You are here

public function WebformTestEditorialController::elements in Webform 6.x

Returns webform elements editorial.

Return value

array A renderable array containing webform elements editorial.

1 string reference to 'WebformTestEditorialController::elements'
webform_test_editorial.routing.yml in tests/modules/webform_test_editorial/webform_test_editorial.routing.yml
tests/modules/webform_test_editorial/webform_test_editorial.routing.yml

File

tests/modules/webform_test_editorial/src/Controller/WebformTestEditorialController.php, line 249

Class

WebformTestEditorialController
Provides route responses for webform editorial.

Namespace

Drupal\webform_test_editorial\Controller

Code

public function elements() {
  $definitions = $this->elementManager
    ->getDefinitions();
  $definitions = $this->elementManager
    ->getSortedDefinitions($definitions, 'category');
  $grouped_definitions = $this->elementManager
    ->getGroupedDefinitions($definitions);
  unset($grouped_definitions['Other elements']);
  $build = [];
  $build['title'] = [
    '#prefix' => '<h1>',
    '#suffix' => '</h1>',
    '#markup' => $this
      ->t('Webform: Elements editorial'),
  ];
  foreach ($grouped_definitions as $category_name => $elements) {

    // Header.
    $header = [
      [
        'data' => $this
          ->t('Name'),
        'width' => '25%',
      ],
      [
        'data' => $this
          ->t('Label'),
        'width' => '25%',
      ],
      [
        'data' => $this
          ->t('Description'),
        'width' => '50%',
      ],
    ];

    // Rows.
    $rows = [];
    foreach ($elements as $name => $element) {
      $rows[] = [
        'data' => [
          [
            'data' => '<b>' . $name . '</b>',
          ],
          [
            'data' => $element['label'],
          ],
          [
            'data' => $element['description'],
          ],
        ],
      ];
    }
    $build[$category_name] = $this
      ->buildTable($category_name, $header, $rows, 'h2');
  }
  return $this
    ->response($build);
}