You are here

public function WebformCompositeBase::getTableColumn in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/WebformCompositeBase.php \Drupal\webform\Plugin\WebformElement\WebformCompositeBase::getTableColumn()

Get element's table column(s) settings.

Parameters

array $element: An element.

Return value

array An associative array containing an element's table column(s).

Overrides WebformElementBase::getTableColumn

File

src/Plugin/WebformElement/WebformCompositeBase.php, line 230

Class

WebformCompositeBase
Provides a base for composite elements.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function getTableColumn(array $element) {
  $key = $element['#webform_key'];
  $title = $element['#title'] ?: $key;
  $is_title_displayed = WebformElementHelper::isTitleDisplayed($element);

  // Get the main composite element, which can't be sorted.
  $columns = parent::getTableColumn($element);
  $columns['element__' . $key]['sort'] = FALSE;

  // Get individual composite elements.
  if (!$this
    ->hasMultipleValues($element)) {
    $composite_elements = $this
      ->getInitializedCompositeElement($element);
    foreach (RenderElement::children($composite_elements) as $composite_key) {
      $composite_element = $composite_elements[$composite_key];

      // Make sure the composite element is visible.
      $access_key = '#' . $composite_key . '__access';
      if (isset($element[$access_key]) && $element[$access_key] === FALSE) {
        continue;
      }

      // Add reference to initialized composite element so that it can be
      // used by ::formatTableColumn().
      $columns['element__' . $key . '__' . $composite_key] = [
        'title' => ($is_title_displayed ? $title . ': ' : '') . (!empty($composite_element['#title']) ? $composite_element['#title'] : $composite_key),
        'sort' => TRUE,
        'default' => FALSE,
        'key' => $key,
        'element' => $element,
        'property_name' => $composite_key,
        'composite_key' => $composite_key,
        'composite_element' => $composite_element,
        'plugin' => $this,
      ];
    }
  }
  return $columns;
}