You are here

public static function CategorizedOptionsbuttonsWidget::validateElement in Open Social 10.2.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::validateElement()
  2. 8.3 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::validateElement()
  3. 8.4 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::validateElement()
  4. 8.5 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::validateElement()
  5. 8.6 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::validateElement()
  6. 8.7 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::validateElement()
  7. 8.8 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::validateElement()
  8. 10.3.x modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::validateElement()
  9. 10.0.x modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::validateElement()
  10. 10.1.x modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::validateElement()

Form validation handler for widget elements.

Parameters

array $element: The form element.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

Overrides OptionsWidgetBase::validateElement

File

modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php, line 101

Class

CategorizedOptionsbuttonsWidget
Plugin implementation of the 'categorized_options_buttons' widget.

Namespace

Drupal\social_profile\Plugin\Field\FieldWidget

Code

public static function validateElement(array $element, FormStateInterface $form_state) {

  // Only pre-process the validation if this is a categorized checkbox
  // element.
  if (isset($element['#checkbox_categories'])) {

    // This turns the tree back into a single checkbox element that our parent
    // widget can handle. We didn't disable value tree submission because it
    // gives us issues in FormValidator::performRequiredValidation.
    $element['#value'] = [];
    $element['#options'] = [];
    if (isset($element['checkboxes'])) {
      $element['#value'] += $element['checkboxes']['#value'];
      $element['#options'] += $element['checkboxes']['#options'];
    }
    foreach ($element['#checkbox_categories'] as $tid) {

      // If a value in a category was checked then those selections are added
      // but we also select the category itself.
      if (!empty($element[$tid]['checkboxes']['#value'])) {
        $element['#value'] += [
          $tid => $tid,
        ];
        $element['#options'] += [
          $tid => $tid,
        ];
        $element['#value'] += $element[$tid]['checkboxes']['#value'];
        $element['#options'] += $element[$tid]['checkboxes']['#options'];
      }
    }
  }
  parent::validateElement($element, $form_state);
}