You are here

public static function PluginBase::preRenderFlattenData in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase::preRenderFlattenData()

Flattens the structure of form elements.

If a form element has #flatten = TRUE, then all of its children get moved to the same level as the element itself. So $form['to_be_flattened'][$key] becomes $form[$key], and $form['to_be_flattened'] gets unset.

Parameters

array $form: The form build array to alter.

Return value

array The form build array.

Overrides ViewsPluginInterface::preRenderFlattenData

File

core/modules/views/src/Plugin/views/PluginBase.php, line 502

Class

PluginBase
Base class for any views plugin types.

Namespace

Drupal\views\Plugin\views

Code

public static function preRenderFlattenData($form) {
  foreach (Element::children($form) as $key) {
    $element = $form[$key];
    if (!empty($element['#flatten'])) {
      foreach (Element::children($element) as $child_key) {
        $form[$child_key] = $form[$key][$child_key];
      }

      // All done, remove the now-empty parent.
      unset($form[$key]);
    }
  }
  return $form;
}