You are here

public function Taxonomy::validateConfigurationForm in Workbench Access 8

Form validation handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides AccessControlHierarchyBase::validateConfigurationForm

File

src/Plugin/AccessControlHierarchy/Taxonomy.php, line 422

Class

Taxonomy
Defines a hierarchy based on a Vocabulary.

Namespace

Drupal\workbench_access\Plugin\AccessControlHierarchy

Code

public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  $settings = $form_state
    ->getValues();
  $settings['vocabularies'] = array_values(array_filter($settings['vocabularies']));
  if (!empty($settings['fields'])) {
    $settings['fields'] = array_filter($settings['fields']);
    foreach ($settings['fields'] as $field) {
      if (isset($settings['validate'][$field])) {
        $error = TRUE;
        foreach ($settings['vocabularies'] as $vocabulary) {
          if (in_array($vocabulary, $settings['validate'][$field], TRUE)) {
            $error = FALSE;
          }
        }
        if ($error) {
          $form_field = $form['fields']['#options'][$field];
          list($entity_type, $bundle, $field_name) = explode(':', $field);
          $form_state
            ->setErrorByName('scheme_settings][fields][' . $field, $this
            ->t('The field %field on %type entities of type %bundle is not in the selected vocabularies.', [
            '%field' => $form_field['field'],
            '%type' => $entity_type,
            '%bundle' => $form_field['bundle'],
          ]));
        }
      }
    }
  }
}