diff --git a/modules/core/import/modules/csv/src/Controller/CsvImportController.php b/modules/core/import/modules/csv/src/Controller/CsvImportController.php index 5563526d3..322ef1512 100644 --- a/modules/core/import/modules/csv/src/Controller/CsvImportController.php +++ b/modules/core/import/modules/csv/src/Controller/CsvImportController.php @@ -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, diff --git a/modules/core/import/src/Controller/ImportController.php b/modules/core/import/src/Controller/ImportController.php index 83f6c3ac7..dfbf9297c 100644 --- a/modules/core/import/src/Controller/ImportController.php +++ b/modules/core/import/src/Controller/ImportController.php @@ -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, diff --git a/modules/core/quick/src/Controller/QuickFormController.php b/modules/core/quick/src/Controller/QuickFormController.php index 753821b77..3a2c30e18 100644 --- a/modules/core/quick/src/Controller/QuickFormController.php +++ b/modules/core/quick/src/Controller/QuickFormController.php @@ -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', diff --git a/modules/core/report/src/Controller/ReportController.php b/modules/core/report/src/Controller/ReportController.php index 33d111ee5..2d4e33922 100644 --- a/modules/core/report/src/Controller/ReportController.php +++ b/modules/core/report/src/Controller/ReportController.php @@ -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 = []; + + // Build list item for each report. + $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. - $links[] = $element->link; - } - if (!empty($links)) { - $items = []; - foreach ($links as $link) { + $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; } diff --git a/modules/core/setup/src/Controller/SetupController.php b/modules/core/setup/src/Controller/SetupController.php index 80c9b8349..d33e5e315 100644 --- a/modules/core/setup/src/Controller/SetupController.php +++ b/modules/core/setup/src/Controller/SetupController.php @@ -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; + $tree_access_cacheability->addCacheableDependency($element->access); + if ($element->access->isAllowed()) { + $items[] = [ + 'title' => $element->link->getTitle(), + 'description' => $element->link->getDescription(), + 'url' => $element->link->getUrlObject(), + ]; } + } - // Include the link. - $items[] = [ - 'title' => $element->link->getTitle(), - 'description' => $element->link->getDescription(), - 'url' => $element->link->getUrlObject(), + // Render items. + if (!empty($items)) { + $output = [ + '#theme' => 'admin_block_content', + '#content' => $items, ]; } - - // 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.'); - } 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; } }