Generates an overview page of available layouts for the grid layout plugin.
array The output render array.
public function layouts() {
$filters = [
'#type' => 'fieldset',
'#attributes' => [
'class' => [
'table-filter',
'js-show',
'form--inline',
],
'data-table' => '.paragraphs-collection-overview-table',
],
'#title' => $this
->t('Filter'),
];
$filters['text'] = [
'#type' => 'search',
'#title' => $this
->t('Grid layout label or ID'),
'#size' => 40,
'#attributes' => [
'class' => [
'table-filter-text',
],
'autocomplete' => 'off',
'title' => $this
->t('Enter a part of the style label or ID to filter by.'),
],
];
$header = [
'label' => $this
->t('Grid layout'),
'details' => $this
->t('Details'),
'use' => $this
->t('Used in'),
];
$layouts = $this->gridLayoutDiscovery
->getGridLayouts();
$rows = [];
foreach ($this
->getParagraphsTypesGroupedByGridLayouts() as $layout_id => $value) {
$layout = $layouts[$layout_id];
$paragraphs_type_link_list = [];
foreach ($value as $paragraphs_type_id => $paragraphs_type) {
/** @var ParagraphsType $paragraphs_type */
if ($paragraphs_type_link_list != []) {
$paragraphs_type_link_list[] = [
'#plain_text' => ', ',
];
}
$paragraphs_type_link_list[] = [
'#type' => 'link',
'#title' => $paragraphs_type
->label(),
'#url' => $paragraphs_type
->toUrl(),
'#attributes' => [
'class' => [
'table-filter-paragraphs-type-source',
],
],
];
}
$row['label'] = [
'#type' => 'container',
'#plain_text' => $layout['title'],
'#attributes' => [
'class' => [
'table-filter-text-source',
],
],
];
$row['details'] = [
'#type' => 'details',
'#title' => !empty($layout['description']) ? $layout['description'] : $this
->t('Description not available.'),
'#open' => FALSE,
'#attributes' => [
'class' => [
'overview-details',
],
],
];
$row['details']['id'] = [
'#type' => 'item',
'#title' => $this
->t('ID'),
'#prefix' => '<span class="container-inline">',
'#suffix' => '</span>',
'item' => [
'#type' => 'container',
'#plain_text' => $layout_id,
'#attributes' => [
'class' => [
'table-filter-text-source',
],
],
],
];
$row['use'] = $paragraphs_type_link_list;
$rows[] = $row;
}
$table = [
'#type' => 'table',
'#header' => $header,
'#sticky' => TRUE,
'#attributes' => [
'class' => [
'paragraphs-collection-overview-table',
],
],
];
$table += $rows;
$build['filters'] = $filters;
$build['table'] = $table;
$build['#attached']['library'] = [
'paragraphs_collection/overview',
];
return $build;
}