How to deny access to a node/add/contenttype page but allow creating of that content type

Filed this issue:

Include option to include content type create page in the rabbit hole? [#3092259] |

A common pairing with never viewing a content type on its own is always creating that content type in-line. Would blocking access to the node/add/[contenttype] page (for content people are nonetheless allowed to create) be considered for inclusion in this module?

William Jieh asks for pretty much exactly what i need:

and didn’t get a good answer but found documentation:

Oh this looks like the closest analog documented:

This shows how to add routes that provide the function of node/add/content-type, but not change existing ones:

See also the one and only commit of my stalled attempt, here:

Note that the simple case of not taking any arguments is easy:

Exact problem, not clearly stated permissions:

Ah no i don’t have the exact problem; i’m trying to do what Neha has already solved. So i can do it like this, in src/Routing/RouteSubscriber.php:

namespace Drupal\drutopia_findit_service_provider\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

 * Listens to the dynamic route events.
class RouteSubscriber extends RouteSubscriberBase {

   * {@inheritdoc}
  protected function alterRoutes(RouteCollection $collection) {
    // Always deny access to '/node/add' listing of available content to create.
    if ($route = $collection->get('node.add_page')) {
      // Note that the second parameter of setRequirement() is a string.
      $route->setRequirement('_permission', 'administer nodes');


This depends on having a file with this:

    class: Drupal\drutopia_findit_service_provider\Routing\RouteSubscriber
      - { name: event_subscriber }