You are here

public function MultiNodeAddController::overview in Multi Node Add 8

Provides links to specific bundle multi node add forms.

1 string reference to 'MultiNodeAddController::overview'
multi_node_add.routing.yml in ./multi_node_add.routing.yml
multi_node_add.routing.yml

File

src/Controller/MultiNodeAddController.php, line 16

Class

MultiNodeAddController
Controller for Multi Node Add.

Namespace

Drupal\multi_node_add\Controller

Code

public function overview() {
  $content = [];

  // Only use node types the user has access to.
  foreach (\Drupal::entityTypeManager()
    ->getStorage('node_type')
    ->loadMultiple() as $type) {
    if (\Drupal::entityTypeManager()
      ->getAccessControlHandler('node')
      ->createAccess($type
      ->getOriginalId())) {
      $content[$type
        ->getOriginalId()] = $type;
    }
  }

  // Bypass the node/add listing if only one content type is available.
  if (count($content) == 1) {
    $type = array_shift($content);
    return $this
      ->redirect('multi_node_add.add', [
      'node_type' => $type->type,
    ]);
  }
  return [
    '#theme' => 'multi_node_add_list',
    '#content' => $content,
  ];
}