4

I can't view nodes using the Seven theme as administrative theme. When I am logged in as administrator, I can only view management pages with Seven, but no content pages.

I thought that the settings on this page should be sufficient.

screenshot

How do I set an administrative theme like Seven to view nodes when I am logged in as administrator?

0

1 Answer 1

7
+50

Drupal doesn't treat Content/Node view page as admin pages even after enabling "Use the administration theme when editing or creating content" setting on "Admin => Appearance" Page. This is just a setting allowed by Drupal Core. Node module uses this setting and alter Content/Note edit, delete, revision, etc. page URLs so Drupal can treat these path as Admin path.

You'll have to alter route defined by Core's Node module. You can do this by implementing alterRoutes() and tell Drupal to treat Content View page as admin URLs. Check example below:

namespace Drupal\example\Routing;

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

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

  /**
   * {@inheritdoc}
   */
  public function alterRoutes(RouteCollection $collection) {
    if ($route = $collection->get('entity.node.canonical')) {
      // Node module has option to define all path as admin path,
      // where path has "_node_operation_route" option set to TRUE.
      $route->setOption('_node_operation_route', TRUE);
      // Below line define path as admin path.
      // $route->setOption('_admin_route', TRUE);
    }
  }

}

If Use the administration theme when editing or creating content setting is enabled then, the Node module checks if any path has _node_operation_route option set to TRUE. If yes, it alters the path and set _admin_route option to TRUE so the path will be treated as an admin path (and then you will see it as in an admin theme, which is in this case, Seven).

If this doesn't work you can specifically set _admin_route option to TRUE for Content/Node View (entity.node.canonical) page programatically (check commented code).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.