You are here

public function EntityCollector::validateEndpoints in Relation 8

Same name and namespace in other branches
  1. 8.2 relation_entity_collector/src/Form/EntityCollector.php \Drupal\relation_entity_collector\Form\EntityCollector::validateEndpoints()

Validate relation endpoints.

File

relation_entity_collector/src/Form/EntityCollector.php, line 231
Contains \Drupal\relation_entity_collector\Form\EntityCollector.

Class

EntityCollector
Provides a entity collector form.

Namespace

Drupal\relation_entity_collector\Form

Code

public function validateEndpoints($relation, array &$form, FormStateInterface $form_state) {

  // Perform field_level validation.
  try {
    field_attach_validate('relation', $relation);
  } catch (FieldValidationException $e) {
    $index = 0;

    // We do not look anything like a field widget so just pile the errors on
    // nonexistent form elements.
    foreach ($e->errors as $field_name => $field_errors) {
      foreach ($field_errors as $langcode => $multiple_errors) {
        foreach ($multiple_errors as $delta => $item_errors) {
          foreach ($item_errors as $item_error) {
            form_set_error('error' . $index++, $item_error['message']);
          }
        }
      }
    }
  }
}