You are here

public function EntityReferenceLayoutWidget::validateBehaviors in Entity Reference with Layout 8

Validate paragraph behavior form plugins.

Parameters

array $element: The element to validate.

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

array $form: The complete form array.

File

src/Plugin/Field/FieldWidget/EntityReferenceLayoutWidget.php, line 962

Class

EntityReferenceLayoutWidget
Entity Reference with Layout field widget.

Namespace

Drupal\entity_reference_layout\Plugin\Field\FieldWidget

Code

public function validateBehaviors(array $element, FormStateInterface $form_state, array $form) {
  $element_array_parents = $element['#array_parents'];
  $item_array_parents = array_splice($element_array_parents, 0, -2);
  $item_form = NestedArray::getValue($form, $item_array_parents);

  /** @var \Drupal\paragraphs\ParagraphInterface $paragraphs_entity */
  $entity = $item_form['#entity'];

  // Validate all enabled behavior plugins.
  $paragraphs_type = $entity
    ->getParagraphType();
  if ($this->currentUser
    ->hasPermission('edit behavior plugin settings')) {
    foreach ($paragraphs_type
      ->getEnabledBehaviorPlugins() as $plugin_id => $plugin_values) {
      if (!empty($element[$plugin_id])) {
        $subform_state = SubformState::createForSubform($element[$plugin_id], $form_state
          ->getCompleteForm(), $form_state);
        $plugin_values
          ->validateBehaviorForm($entity, $element[$plugin_id], $subform_state);
      }
    }
  }
}