You are here

protected function WebformLocationBase::buildCompositeElementsTable in Webform 6.x

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

Build the composite elements settings table.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array A renderable array container the composite elements settings table.

Overrides WebformCompositeBase::buildCompositeElementsTable

File

src/Plugin/WebformElement/WebformLocationBase.php, line 110

Class

WebformLocationBase
Provides a base 'location' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function buildCompositeElementsTable(array $form, FormStateInterface $form_state) {
  $header = [
    $this
      ->t('Key'),
    $this
      ->t('Title/Placeholder'),
    $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,
          ],
          $composite_key . '__placeholder' => [
            '#type' => 'textfield',
            '#title' => $this
              ->t('@title placeholder', $t_args),
            '#title_display' => 'invisible',
            '#placeholder' => $this
              ->t('Enter placeholder…'),
            '#attributes' => $attributes,
          ],
        ],
      ];
    }
    else {
      $row['title_and_description'] = [
        'data' => [
          '',
        ],
      ];
    }

    // Access.
    if ($composite_key === 'value') {
      $row[$composite_key . '__access'] = [
        '#type' => 'checkbox',
        '#default_value' => TRUE,
        '#disabled' => TRUE,
        '#access' => TRUE,
      ];
    }
    else {
      $row[$composite_key . '__access'] = [
        '#type' => 'checkbox',
        '#return_value' => TRUE,
      ];
    }
    $rows[$composite_key] = $row;
  }
  return [
    '#type' => 'table',
    '#header' => $header,
  ] + $rows;
}