public static function TaxonomyTooltip::validateTaxonomyVocabs in Glossify 8
Validation callback for glossify_taxonomy_vocabs.
Make the field required if the filter is enabled.
Parameters
array $element: The element being processed.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $complete_form: The complete form structure.
File
- modules/glossify_taxonomy/ src/ Plugin/ Filter/ TaxonomyTooltip.php, line 99 
Class
- TaxonomyTooltip
- Filter to find and process found taxonomy terms in the fields value.
Namespace
Drupal\glossify_taxonomy\Plugin\FilterCode
public static function validateTaxonomyVocabs(&$element, FormStateInterface $form_state, &$complete_form) {
  $values = $form_state
    ->getValues();
  // Make taxonomy_vocabs required if the filter is enabled.
  if (!empty($values['filters']['glossify_taxonomy']['status'])) {
    $field_values = array_filter($values['filters']['glossify_taxonomy']['settings']['glossify_taxonomy_vocabs']);
    if (empty($field_values)) {
      $element['#required'] = TRUE;
      $form_state
        ->setError($element, t('%field is required.', [
        '%field' => $element['#title'],
      ]));
    }
  }
}