diff --git a/core/modules/node/lib/Drupal/node/Access/NodeAddAccess.php b/core/modules/node/lib/Drupal/node/Access/NodeAddAccess.php new file mode 100644 index 0000000..55218d9 --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Access/NodeAddAccess.php @@ -0,0 +1,38 @@ +getRequirements()); + } + + /** + * Implements AccessCheckInterface::access(). + */ + public function access(Route $route, Request $request) { + $types = node_type_get_types(); + foreach ($types as $type) { + if (node_hook($type->type, 'form') && node_access('create', $type->type)) { + return TRUE; + } + } + return NULL; + } +} diff --git a/core/modules/node/lib/Drupal/node/Controller/NodeAddController.php b/core/modules/node/lib/Drupal/node/Controller/NodeAddController.php new file mode 100644 index 0000000..0891638b --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Controller/NodeAddController.php @@ -0,0 +1,47 @@ +type, 'form') && node_access('create', $type->type)) { + $content[$type->type] = $type; + } + } + + // Bypass the node/add listing if only one content type is available. + if (count($content) == 1) { + $type = array_shift($content); + return new RedirectResponse('/node/add/' . $type->type); + } + return array( + '#theme' => 'node_add_list', + '#content' => $content, + ); + } +} diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/area/ListingEmpty.php b/core/modules/node/lib/Drupal/node/Plugin/views/area/ListingEmpty.php index 666cf26..16b3ce0 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/area/ListingEmpty.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/area/ListingEmpty.php @@ -7,8 +7,10 @@ namespace Drupal\node\Plugin\views\area; +use Symfony\Component\Routing\Route; use Drupal\Component\Annotation\PluginID; use Drupal\views\Plugin\views\area\AreaPluginBase; +use Drupal\node\Access\NodeAddAccess; /** * Defines an area plugin to display a node/add link. @@ -24,19 +26,19 @@ class ListingEmpty extends AreaPluginBase { */ public function render($empty = FALSE) { if (!$empty || !empty($this->options['empty'])) { + $access = new NodeAddAccess(); $element = array( '#theme' => 'links', '#links' => array( array( 'href' => 'node/add', - 'title' => t('Add new content') - ) - ) , - '#access' => _node_add_access() + 'title' => t('Add new content'), + ), + ), + '#access' => $access->access(new Route('/node'), \Drupal::request()), ); return $element; } return array(); } - } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index d41d960..0f9d66c 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1588,30 +1588,6 @@ function _node_revision_access(EntityInterface $node, $op = 'view', $account = N } /** - * Access callback: Checks whether the user has permission to add a node. - * - * @return - * TRUE if the user has add permission, otherwise FALSE. - * - * @see node_menu() - */ -function _node_add_access() { - $types = node_type_get_types(); - foreach ($types as $type) { - if (node_hook($type->type, 'form') && node_access('create', $type->type)) { - return TRUE; - } - } - if (user_access('administer content types')) { - // There are no content types defined that the user has permission to create, - // but the user does have the permission to administer the content types, so - // grant them access to the page anyway. - return TRUE; - } - return FALSE; -} - -/** * Implements hook_menu(). */ function node_menu() { @@ -1680,9 +1656,7 @@ function node_menu() { ); $items['node/add'] = array( 'title' => 'Add content', - 'page callback' => 'node_add_page', - 'access callback' => '_node_add_access', - 'file' => 'node.pages.inc', + 'route_name' => 'node.add_page', ); $items['node/add/%node_type'] = array( 'title callback' => 'node_type_get_clean_name', diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 9aa4982..d2eaf3a 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -28,34 +28,6 @@ function node_page_edit($node) { } /** - * Page callback: Displays add content links for available content types. - * - * Redirects to node/add/[type] if only one content type is available. - * - * @return array - * 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 redirects - * to the node add page for that one node type and does not return at all. - * - * @see node_menu() - */ -function node_add_page() { - $content = array(); - // Only use node types the user has access to. - foreach (node_type_get_types() as $type) { - if (node_hook($type->type, 'form') && node_access('create', $type->type)) { - $content[$type->type] = $type; - } - } - // Bypass the node/add listing if only one content type is available. - if (count($content) == 1) { - $type = array_shift($content); - drupal_goto('node/add/' . $type->type); - } - return array('#theme' => 'node_add_list', '#content' => $content); -} - -/** * Returns HTML for a list of available node types for node creation. * * @param $variables diff --git a/core/modules/node/node.routing.yml b/core/modules/node/node.routing.yml new file mode 100644 index 0000000..0e5b6c7 --- /dev/null +++ b/core/modules/node/node.routing.yml @@ -0,0 +1,8 @@ +node.add_page: + pattern: '/node/add' + defaults: + _controller: '\Drupal\node\Controller\NodeAddController::addNode' + requirements: + _permissions: 'administer content types' + _node_add_access: 'node' + \ No newline at end of file diff --git a/core/modules/node/node.services.yml b/core/modules/node/node.services.yml new file mode 100644 index 0000000..99e9936 --- /dev/null +++ b/core/modules/node/node.services.yml @@ -0,0 +1,6 @@ +services: + node.add_access: + class: Drupal\node\Access\NodeAddAccess + arguments: ['@plugin.manager.entity'] + tags: + - { name: access_check } \ No newline at end of file diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php old mode 100644 new mode 100755