function EntityReference::cleanUpSubformChildren

Same name and namespace in other branches
  1. main core/modules/views/src/Plugin/views/filter/EntityReference.php \Drupal\views\Plugin\views\filter\EntityReference::cleanUpSubformChildren()

Clean up subform children for properties that could cause problems.

Views modal forms do not work with required or ajax elements.

Parameters

array $element: The form element.

1 call to EntityReference::cleanUpSubformChildren()
EntityReference::buildExtraOptionsForm in core/modules/views/src/Plugin/views/filter/EntityReference.php
Provide a form for setting options.

File

core/modules/views/src/Plugin/views/filter/EntityReference.php, line 273

Class

EntityReference
Filters a view by entity references.

Namespace

Drupal\views\Plugin\views\filter

Code

protected function cleanUpSubformChildren(array &$element) : void {
  // Remove the required property to prevent focus errors.
  if (isset($element['#required']) && $element['#required']) {
    $element['#required'] = FALSE;
    $element['#element_validate'][] = [
      static::class,
      'validateRequired',
    ];
  }
  // Remove the ajax property as it does not work.
  if (!empty($element['#ajax'])) {
    unset($element['#ajax']);
  }
  // Recursively apply to nested fields within the handler sub form.
  foreach (Element::children($element) as $delta) {
    $this->cleanUpSubformChildren($element[$delta]);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.