You are here

public function YamlFormCompositeBase::getTableColumn in YAML Form 8

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 YamlFormElementBase::getTableColumn

File

src/Plugin/YamlFormElement/YamlFormCompositeBase.php, line 131

Class

YamlFormCompositeBase
Provides a base for composite elements.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function getTableColumn(array $element) {
  $key = $element['#yamlform_key'];
  $title = $element['#title'] ?: $key;
  $is_title_displayed = YamlFormElementHelper::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.
  $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;
}