You are here

public static function FieldGroupFormatterBase::validateCssClass in Field Group 8.3

Validate the entered css class from the submitted format settings.

Parameters

array $element: The validated element.

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

File

src/FieldGroupFormatterBase.php, line 218

Class

FieldGroupFormatterBase
Base class for 'Fieldgroup formatter' plugin implementations.

Namespace

Drupal\field_group

Code

public static function validateCssClass(array $element, FormStateInterface $form_state) {
  $form_state_values = $form_state
    ->getValues();
  $plugin_name = $form_state
    ->get('plugin_settings_edit');
  if (!empty($form_state_values['fields'][$plugin_name]['settings_edit_form']['settings']['classes']) && !preg_match('!^[A-Za-z0-9-_ ]+$!', $form_state_values['fields'][$plugin_name]['settings_edit_form']['settings']['classes'])) {
    $form_state
      ->setError($element, t('The css class must include only letters, numbers, underscores and dashes.'));
  }
}