#StackBounty: #8 #nodes #fields #images Is there a way to auto populate the Alternative text using the image file's Alternative text?

Bounty: 50

We have an Article content type that has an image field, field_image. On upload of a new image, the Name and Alternative text is provided.

When we attempt to add the image to the Article node, we have to enter the Alternative text again even though it was provided on uploaded.

Is there a way to auto populate the Alternative text on the Article node using the image file’s Alternative text?

Steps to reproduce:

  1. Add Image field (field_image) to Article content type.
  2. Create a new Article node.
  3. Click on “Select an Image” for field_image and upload a new image (popup shows up allow you to choose from library or upload).
  4. Provide Alternative Text and any other fields to save the image.
  5. After saving, the popup disappears and you will notice the Alternative text is still blank

On upload
on upload

After saving image
after saving


Get this bounty!!!

#StackBounty: #8 #nodes #fields #images Is there a way to auto populate the Alternative text using the image file's Alternative text?

Bounty: 50

We have an Article content type that has an image field, field_image. On upload of a new image, the Name and Alternative text is provided.

When we attempt to add the image to the Article node, we have to enter the Alternative text again even though it was provided on uploaded.

Is there a way to auto populate the Alternative text on the Article node using the image file’s Alternative text?

Steps to reproduce:

  1. Add Image field (field_image) to Article content type.
  2. Create a new Article node.
  3. Click on “Select an Image” for field_image and upload a new image (popup shows up allow you to choose from library or upload).
  4. Provide Alternative Text and any other fields to save the image.
  5. After saving, the popup disappears and you will notice the Alternative text is still blank

On upload
on upload

After saving image
after saving


Get this bounty!!!

#StackBounty: #8 #nodes #fields #images Is there a way to auto populate the Alternative text using the image file's Alternative text?

Bounty: 50

We have an Article content type that has an image field, field_image. On upload of a new image, the Name and Alternative text is provided.

When we attempt to add the image to the Article node, we have to enter the Alternative text again even though it was provided on uploaded.

Is there a way to auto populate the Alternative text on the Article node using the image file’s Alternative text?

Steps to reproduce:

  1. Add Image field (field_image) to Article content type.
  2. Create a new Article node.
  3. Click on “Select an Image” for field_image and upload a new image (popup shows up allow you to choose from library or upload).
  4. Provide Alternative Text and any other fields to save the image.
  5. After saving, the popup disappears and you will notice the Alternative text is still blank

On upload
on upload

After saving image
after saving


Get this bounty!!!

#StackBounty: #8 #nodes #fields #images Is there a way to auto populate the Alternative text using the image file's Alternative text?

Bounty: 50

We have an Article content type that has an image field, field_image. On upload of a new image, the Name and Alternative text is provided.

When we attempt to add the image to the Article node, we have to enter the Alternative text again even though it was provided on uploaded.

Is there a way to auto populate the Alternative text on the Article node using the image file’s Alternative text?

Steps to reproduce:

  1. Add Image field (field_image) to Article content type.
  2. Create a new Article node.
  3. Click on “Select an Image” for field_image and upload a new image (popup shows up allow you to choose from library or upload).
  4. Provide Alternative Text and any other fields to save the image.
  5. After saving, the popup disappears and you will notice the Alternative text is still blank

On upload
on upload

After saving image
after saving


Get this bounty!!!

#StackBounty: #8 #users #emails #workbench How to send an email to select set of users for moderation states?

Bounty: 50

We are using the following modules below for content moderation. Currently have we have 5 people with the Content Approver role and all of them are sent an email when a state transition occurs. There is a need to send email alerts of moderation transitions for certain content types that need approval to just 2 out of the 5 Approvers.

How to send an email to select set of users when changing moderation state?

Expected Results:

When a content editor marks a page ready for Review, they are allowed to manually select one or more users to send an email alert to regardless of Role.

Enabled Modules:

  1. Workbench v8.x-1.0
  2. Workbench Email v8.x-1.0-alpha7


Get this bounty!!!

#StackBounty: #8 #theming #fields #meta-tags How to use default field_image if value is not provided?

Bounty: 50

We are using Schema.org Metatag module to display meta tag attributes to the Article content type. We have a field that we using as an ImageObject using the field_image field. The field_image is setup so that if an image is not selected, then a default image will be displayed in the twig templates.

We had to add a [node:field_image:large:url] into the url field under ImageObject. When an image is selected, the correct url is added to the page. However, when the image is not selected (a default image should be used), the url field is displaying empty.

How to get the token to display the default value is the image is not added through the node edit process?

Current behavior:

"image" : {
  "@type" : "ImageObject",
   "representativeOfPage": "True",
}

Expected behavior (when image is not selected)

"image": {
  "@type": "ImageObject",
  "representativeOfPage": "True",
  "url": "https://path/to/default-image/large/cloud.jpg",
  "width": "400",
  "height": "260"
},


Get this bounty!!!

#StackBounty: #views #8 #views-filters #views-handlers D8 Views – Contextual Filter by Month & Year? (Content date field)

Bounty: 50

We have a dev site finally patched all the way up to 8.5.3. Our old site (8.4.0) was using a Views patch (just for reference) that allowed for a content date field to be contextually filtered by month and year:

https://domain.com/events/042018

returned all events with month 04 and year 2018.

Now on views 8.5.3 this patch is no longer applicable and seems to be integrated for Created Date and Updated Date. But I don’t need these date fields. I am trying to access a content date field that I made.

  1. Does anyone know how to do this?
    or
  2. Can you help me get started on creating a custom views contextual filter handler that can access this custom date field?

Thanks so much!

Example of View: Show all events. Contextually Filter by Date. But instead of an exact date, only grab month and year parts, i.e. show all events for July 2018 /events/201807
views content date month year


Get this bounty!!!

#StackBounty: #8 #forms Form #states only work after change, but not on initial load

Bounty: 50

I’ve got a paragraph with a select field field_colorschema, depending on its value two other fields field_image field_parallax on the same paragraph are shown or hidden. The code I’ve written works for most parts, but only AFTER change of field_colorschema. It does not set the correct state on page load.

function wt_base_field_widget_paragraphs_form_alter(&$element, DrupalCoreFormFormStateInterface $form_state, $context) {
  /** @var DrupalfieldEntityFieldConfig $field_definition */
  $fieldDefinition = $context['items']->getFieldDefinition();
  $parentEntityType = $fieldDefinition->getTargetEntityTypeId();
  $parentEntityBundle = $fieldDefinition->getTargetBundle();
  $parentEntityFieldType = $fieldDefinition->getType();
  $parentEntityFieldName = $fieldDefinition->getName();


  /**
   * Conditionally hide background image and parallax depending on row colorschema
   * http://agaric.com/blogs/conditional-fields-paragraphs-using-javascript-states-api-drupal-8
   */
  if ($parentEntityFieldName == 'field_pagebuilder') {

    /** @see DrupalparagraphsPluginFieldFieldWidgetParagraphsWidget::formElement() */
    $widgetState = DrupalCoreFieldWidgetBase::getWidgetState($element['#field_parents'], $parentEntityFieldName, $form_state);

    /** @var DrupalparagraphsEntityParagraph $paragraph */
    $paragraph = $widgetState['paragraphs'][$element['#delta']]['entity'];
    $paragraphBundle = $paragraph->bundle();

    // Determine which paragraph type is being embedded.
    if ($paragraphBundle == 'row') {
      $dependeeFieldName = 'field_colorschema';
      /* field_colorschema option value is one of ['--color-default', '--color-bglight', '--color-bgdark', '--image-bglight', '--image-bgdark'] */
      $selector = sprintf('select[name="%s[%d][subform][%s]"]', $parentEntityFieldName, $element['#delta'], $dependeeFieldName);

      // Dependent fields.
      $element['subform']['field_image']['#states'] = [
        'visible' => [
          [
            $selector => ['value' => '--image-bglight'],
          ],
          [
            $selector => ['value' => '--image-bgdark'],
          ],
        ],
        'required' => [
          [
            $selector => ['value' => '--image-bglight'],
          ],
          [
            $selector => ['value' => '--image-bgdark'],
          ],
        ],
      ];
      $element['subform']['field_parallax']['#states'] = [
        'visible' => [
          [
            $selector => ['value' => '--image-bglight'],
          ],
          [
            $selector => ['value' => '--image-bgdark'],
          ],
        ],
      ];
    }
  }
}

I’ve also tried inverting everything negative logic (invisible…), because the default value on field_colorschema forces the other 2 fields to be hidden, but again it worked only after change, and not on the initial page load.

What am I missing so that field_image and field_parallax are correctly following field_colorschemas values on the intial page load?

PS: The paragraph subform is inside a Field Group tab, but I think that doesn’t matter, because the given code works after selecting values.


Get this bounty!!!

#StackBounty: #8 #forms Can't get validation errors back from an AJAX form

Bounty: 100

I have a Drupal form that should submit via AJAX. I want to validate the input is correct. A few things are happening:

  • The validateForm method is being hit
  • I’m not able to see the errors in the form with getErrors
  • I want to validate the input, and if an error occurs, flash a message in the form that it is invalid
  • On success, I want to replace the form with a success message (but its not getting that far)

Here is my form code:

<?php

namespace Drupalharlib_newsletter_signupForm;

use DrupalCoreFormFormBase;
use DrupalCoreFormFormStateInterface;

/**
 * Class NewsletterSignup.
 */
class NewsletterSignup extends FormBase {

  public $uniqueIdentifier = 'no_tagline';

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'newsletter_signup_' . $this->uniqueIdentifier;
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    if ($this->uniqueIdentifier == "with_tagline") {
      $show_tagline = TRUE;
    }
    else {
      $show_tagline = FALSE;
    }

    $wrapper = 'ajax-wrapper-' . $this->uniqueIdentifier;

    $form['#prefix'] = '<section class="hl__single-input-form">
'; $form['#suffix'] = '
</section>'; $form['#attributes']['class'][] = 'hl__single-input-form__form'; $form['#attributes']['novalidate'] = 'novalidate'; $form['title'] = [ '#type' => 'label', '#for' => 'edit-email-address', '#title' => 'Stay in the know', '#attributes' => [ 'class' => [ 'hl__label', 'hl__label--inline', ], ], ]; if ($show_tagline) { $form['tagline'] = [ '#markup' => '
Sign up for email updates from MySite
', ]; } $errors = $form_state->getErrors(); if ($errors = $form_state->getErrors()) { $form['errors'] = [ '#markup' => $errors['email_address'], ]; } $form['email_address'] = [ '#type' => 'email', '#size' => NULL, '#required' => TRUE, '#attributes' => [ 'placeholder' => $this->t('Email'), 'class' => [ 'hl__input', 'hl__input--inline', 'js-is-required', ], 'data-twig-suggestion' => 'newsletter_signup_email', ], '#prefix' => '
', ]; $form['submit'] = [ '#type' => 'button', '#value' => $this->t('Sign up'), '#submit' => ['::submitForm'], '#attributes' => [ 'class' => [ 'hl__button', 'hl__button--small', 'hl__button--inline', ], 'data-twig-suggestion' => 'newsletter_signup_submit', ], '#suffix' => '
', '#ajax' => [ 'wrapper' => $wrapper, 'method' => 'replace', 'callback' => '::ajaxRebuildForm', 'progress' => [ '#type' => 'none', ], ], ]; return $form; } /** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { $email_value = $form_state->getValue('email_address'); if (empty($email_value) || !Drupal::service('email.validator')->isValid($email_value)) { $form_state->setError($form['email_address'], $this->t('Please enter a valid email address.')); } if (mailchimp_is_subscribed('XXXXXXX', $email_value, TRUE)) { $form_state->setError($form['email_address'], $this->t('You are already subscribed to our newsletter.')); } } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $result = mailchimp_subscribe('XXXXXXX', $form_state->getValue('email_address')); if (empty($result)) { $form_state->setError($form['email_address'], $this->t('You are already subscribed to our newsletter.')); } else { drupal_set_message($this->t('Thank you for subscribing to our newsletter!')); } } public function ajaxRebuildForm(array $form, FormStateInterface $formState) { return $form; } }

Is ajaxRebuildForm necessary? How can I validate this? Is setError still workable in an ajax submit?

EDIT: I’ve updated the validateForm method to use AjaxResponse. Nothing is happening on my screen.

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    $response = new AjaxResponse();
    $email_value = $form_state->getValue('email_address');

    if (empty($email_value) || !Drupal::service('email.validator')->isValid($email_value)) {
      //$form_state->setError($form['email_address'], $this->t('Please enter a valid email address.'));
      //$form_state->setRebuild();
      $response->addCommand(new CssCommand('.hl__single-input-form__input-group', ['border' => '3px solid red']));
      $response->addCommand(new AlertCommand('Heyoooo'));
      return $response;
    }

    if (mailchimp_is_subscribed('XXXXXXX', $email_value, TRUE)) {
      $form_state->setError($form['email_address'], $this->t('You are already subscribed to our newsletter.'));
    }
  }


Get this bounty!!!