You are here

protected function YamlFormLocation::buildCompositeElementsTable in YAML Form 8

Build the composite elements settings table.

Return value

array A renderable array container the composite elements settings table.

Overrides YamlFormCompositeBase::buildCompositeElementsTable

File

src/Plugin/YamlFormElement/YamlFormLocation.php, line 135

Class

YamlFormLocation
Provides an 'location' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

protected function buildCompositeElementsTable() {
  $header = [
    $this
      ->t('Key'),
    $this
      ->t('Title'),
    $this
      ->t('Visible'),
  ];
  $rows = [];
  $composite_elements = $this
    ->getCompositeElements();
  foreach ($composite_elements as $composite_key => $composite_element) {
    $title = isset($composite_element['#title']) ? $composite_element['#title'] : $composite_key;
    $type = isset($composite_element['#type']) ? $composite_element['#type'] : NULL;
    $t_args = [
      '@title' => $title,
    ];
    $attributes = [
      'style' => 'width: 100%; margin-bottom: 5px',
    ];
    $row = [];

    // Key.
    $row[$composite_key . '__key'] = [
      '#markup' => $composite_key,
      '#access' => TRUE,
    ];

    // Title, placeholder, and description.
    if ($type) {
      $row['title_and_description'] = [
        'data' => [
          $composite_key . '__title' => [
            '#type' => 'textfield',
            '#title' => $this
              ->t('@title title', $t_args),
            '#title_display' => 'invisible',
            '#placeholder' => $this
              ->t('Enter title...'),
            '#attributes' => $attributes,
          ],
        ],
      ];
    }
    else {
      $row['title_and_description'] = [
        'data' => [
          '',
        ],
      ];
    }

    // Access.
    $row[$composite_key . '__access'] = [
      '#type' => 'checkbox',
      '#return_value' => TRUE,
    ];
    $rows[$composite_key] = $row;
  }
  return [
    '#type' => 'table',
    '#header' => $header,
  ] + $rows;
}