You are here

public function ImportController::index in farmOS 2.x

The index of importers.

Return value

array Returns a render array.

1 string reference to 'ImportController::index'
farm_import.routing.yml in modules/core/import/farm_import.routing.yml
modules/core/import/farm_import.routing.yml

File

modules/core/import/src/Controller/ImportController.php, line 51

Class

ImportController
Import controller.

Namespace

Drupal\farm_import\Controller

Code

public function index() : array {

  // Load all menu links below it.
  $parameters = new MenuTreeParameters();
  $parameters
    ->setRoot('farm.import')
    ->excludeRoot()
    ->setTopLevelOnly()
    ->onlyEnabledLinks();
  $tree = $this->menuLinkTree
    ->load(NULL, $parameters);
  $manipulators = [
    [
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ],
    [
      'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
    ],
  ];
  $tree = $this->menuLinkTree
    ->transform($tree, $manipulators);
  $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)) {
    $items = [];
    foreach ($links as $link) {
      $items[] = [
        'title' => $link
          ->getTitle(),
        'description' => $link
          ->getDescription(),
        'url' => $link
          ->getUrlObject(),
      ];
    }
    $output = [
      '#theme' => 'admin_block_content',
      '#content' => $items,
    ];
  }
  else {
    $output = [
      '#markup' => $this
        ->t('You do not have any importers.'),
    ];
  }
  return $output;
}