Standardize index building across all index controllers
This commit is contained in:
parent
b815dacb4f
commit
e5c3bda5bf
|
@ -118,27 +118,21 @@ class CsvImportController extends ControllerBase {
|
|||
$tree_access_cacheability = new CacheableMetadata();
|
||||
$tree_access_cacheability->addCacheTags($this->entityTypeManager()->getStorage('migration')->getEntityType()->getListCacheTags());
|
||||
|
||||
$links = [];
|
||||
// Build items for each csv importer.
|
||||
$items = [];
|
||||
foreach ($tree as $element) {
|
||||
$tree_access_cacheability->addCacheableDependency($element->access);
|
||||
|
||||
// Only render accessible links.
|
||||
if (!$element->access->isAllowed()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Include the link.
|
||||
$links[] = $element->link;
|
||||
}
|
||||
if (!empty($links)) {
|
||||
$items = [];
|
||||
foreach ($links as $link) {
|
||||
if ($element->access->isAllowed()) {
|
||||
$items[] = [
|
||||
'title' => $link->getTitle(),
|
||||
'description' => $link->getDescription(),
|
||||
'url' => $link->getUrlObject(),
|
||||
'title' => $element->link->getTitle(),
|
||||
'description' => $element->link->getDescription(),
|
||||
'url' => $element->link->getUrlObject(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Render items.
|
||||
if (!empty($items)) {
|
||||
$output = [
|
||||
'#theme' => 'admin_block_content',
|
||||
'#content' => $items,
|
||||
|
|
|
@ -63,27 +63,21 @@ class ImportController extends ControllerBase {
|
|||
// Start cacheability for indexer list.
|
||||
$tree_access_cacheability = new CacheableMetadata();
|
||||
|
||||
$links = [];
|
||||
// Build list item for each importer.
|
||||
$items = [];
|
||||
foreach ($tree as $element) {
|
||||
$tree_access_cacheability->addCacheableDependency($element->access);
|
||||
|
||||
// Only render accessible links.
|
||||
if (!$element->access->isAllowed()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Include the link.
|
||||
$links[] = $element->link;
|
||||
}
|
||||
if (!empty($links)) {
|
||||
$items = [];
|
||||
foreach ($links as $link) {
|
||||
if ($element->access->isAllowed()) {
|
||||
$items[] = [
|
||||
'title' => $link->getTitle(),
|
||||
'description' => $link->getDescription(),
|
||||
'url' => $link->getUrlObject(),
|
||||
'title' => $element->link->getTitle(),
|
||||
'description' => $element->link->getDescription(),
|
||||
'url' => $element->link->getUrlObject(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Render items.
|
||||
if (!empty($items)) {
|
||||
$output = [
|
||||
'#theme' => 'admin_block_content',
|
||||
'#content' => $items,
|
||||
|
|
|
@ -59,9 +59,9 @@ class QuickFormController extends ControllerBase {
|
|||
$quick_forms = $this->quickFormInstanceManager->getInstances();
|
||||
$items = [];
|
||||
foreach ($quick_forms as $id => $quick_form) {
|
||||
$cacheability->addCacheableDependency($quick_form);
|
||||
$url = Url::fromRoute('farm.quick.' . $id);
|
||||
if ($url->access()) {
|
||||
$cacheability->addCacheableDependency($quick_form);
|
||||
$items[] = [
|
||||
'title' => $quick_form->getLabel(),
|
||||
'description' => $quick_form->getDescription(),
|
||||
|
@ -69,6 +69,8 @@ class QuickFormController extends ControllerBase {
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Render items.
|
||||
if (!empty($items)) {
|
||||
$output = [
|
||||
'#theme' => 'admin_block_content',
|
||||
|
|
|
@ -59,28 +59,25 @@ class ReportController extends ControllerBase {
|
|||
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
|
||||
];
|
||||
$tree = $this->menuLinkTree->transform($tree, $manipulators);
|
||||
|
||||
// Start cacheability for report list.
|
||||
$tree_access_cacheability = new CacheableMetadata();
|
||||
$links = [];
|
||||
foreach ($tree as $element) {
|
||||
$tree_access_cacheability = $tree_access_cacheability->merge(CacheableMetadata::createFromObject($element->access));
|
||||
|
||||
// Only render accessible links.
|
||||
if (!$element->access->isAllowed()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Include the link.
|
||||
$links[] = $element->link;
|
||||
}
|
||||
if (!empty($links)) {
|
||||
// Build list item for each report.
|
||||
$items = [];
|
||||
foreach ($links as $link) {
|
||||
foreach ($tree as $element) {
|
||||
$tree_access_cacheability->addCacheableDependency($element->access);
|
||||
if ($element->access->isAllowed()) {
|
||||
$items[] = [
|
||||
'title' => $link->getTitle(),
|
||||
'description' => $link->getDescription(),
|
||||
'url' => $link->getUrlObject(),
|
||||
'title' => $element->link->getTitle(),
|
||||
'description' => $element->link->getDescription(),
|
||||
'url' => $element->link->getUrlObject(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Render items.
|
||||
if (!empty($items)) {
|
||||
$output = [
|
||||
'#theme' => 'admin_block_content',
|
||||
'#content' => $items,
|
||||
|
@ -91,6 +88,7 @@ class ReportController extends ControllerBase {
|
|||
'#markup' => $this->t('You do not have any reports.'),
|
||||
];
|
||||
}
|
||||
$tree_access_cacheability->applyTo($output);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,38 +59,37 @@ class SetupController extends ControllerBase {
|
|||
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
|
||||
];
|
||||
$tree = $this->menuLinkTree->transform($tree, $manipulators);
|
||||
|
||||
// Start cacheability for setup list.
|
||||
$tree_access_cacheability = new CacheableMetadata();
|
||||
|
||||
// Build list item for each setup item.
|
||||
$items = [];
|
||||
foreach ($tree as $element) {
|
||||
$tree_access_cacheability = $tree_access_cacheability->merge(CacheableMetadata::createFromObject($element->access));
|
||||
|
||||
// Only render accessible links.
|
||||
if (!$element->access->isAllowed()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Include the link.
|
||||
$tree_access_cacheability->addCacheableDependency($element->access);
|
||||
if ($element->access->isAllowed()) {
|
||||
$items[] = [
|
||||
'title' => $element->link->getTitle(),
|
||||
'description' => $element->link->getDescription(),
|
||||
'url' => $element->link->getUrlObject(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Create render array with cacheability.
|
||||
$render = [];
|
||||
$tree_access_cacheability->applyTo($render);
|
||||
|
||||
// Add message if there are no setup items.
|
||||
if (empty($items)) {
|
||||
$render['#markup'] = $this->t('You do not have any setup items.');
|
||||
// Render items.
|
||||
if (!empty($items)) {
|
||||
$output = [
|
||||
'#theme' => 'admin_block_content',
|
||||
'#content' => $items,
|
||||
];
|
||||
}
|
||||
else {
|
||||
$render['#theme'] = 'admin_block_content';
|
||||
$render['#content'] = $items;
|
||||
$output = [
|
||||
'#markup' => $this->t('You do not have any setup items.'),
|
||||
];
|
||||
}
|
||||
|
||||
return $render;
|
||||
$tree_access_cacheability->applyTo($output);
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue