public NodeController::addPage()
Displays add content links for available content types.
Redirects to node/add/[type] if only one content type is available.
Return value
array|\Symfony\Component\HttpFoundation\RedirectResponse A render array for a list of the node types that can be added; however, if there is only one node type defined for the site, the function will return a RedirectResponse to the node add page for that one node type.
File
- core/modules/node/src/Controller/NodeController.php, line 69
Class
- NodeController
- Returns responses for Node routes.
Namespace
Drupal\node\Controller
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | public function addPage() { $build = [ '#theme' => 'node_add_list' , '#cache' => [ 'tags' => $this ->entityManager()->getDefinition( 'node_type' )->getListCacheTags(), ], ]; $content = array (); // Only use node types the user has access to. foreach ( $this ->entityManager()->getStorage( 'node_type' )->loadMultiple() as $type ) { $access = $this ->entityManager()->getAccessControlHandler( 'node' )->createAccess( $type ->id(), NULL, [], TRUE); if ( $access ->isAllowed()) { $content [ $type ->id()] = $type ; } $this ->renderer->addCacheableDependency( $build , $access ); } // Bypass the node/add listing if only one content type is available. if ( count ( $content ) == 1) { $type = array_shift ( $content ); return $this ->redirect( 'node.add' , array ( 'node_type' => $type ->id())); } $build [ '#content' ] = $content ; return $build ; } |
Please login to continue.