You are here

private static function FieldCollectionEmbedWidget::collectRequiredElements in Field collection 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php \Drupal\field_collection\Plugin\Field\FieldWidget\FieldCollectionEmbedWidget::collectRequiredElements()

Prevent the default 'required' validation from running on subfields.

1 call to FieldCollectionEmbedWidget::collectRequiredElements()
FieldCollectionEmbedWidget::delayRequiredValidation in src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php
#after_build of a field collection element.

File

src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php, line 148

Class

FieldCollectionEmbedWidget
Plugin implementation of the 'field_collection_embed' widget.

Namespace

Drupal\field_collection\Plugin\Field\FieldWidget

Code

private static function collectRequiredElements(&$element, &$required_elements) {

  // Recurse through all children.
  foreach (Element::children($element) as $key) {
    if (isset($element[$key]) && $element[$key]) {
      static::collectRequiredElements($element[$key], $required_elements);
    }
  }
  if (!empty($element['#required'])) {
    $element['#required'] = FALSE;
    $required_elements[] =& $element;
    $element += [
      '#pre_render' => [],
    ];
    array_unshift($element['#pre_render'], [
      static::class,
      'renderRequired',
    ]);
  }
}