3

I use Drupal 8.2.3 and can't view content in my admin theme (seven), when logged in as admin (I can only view management pages with Seven, but not content pages as in general).

I thought that this would help but it doesn't:

enter image description here

  • 2
    Please provide more details on what exactly you mean by "I can only see management pages but not content pages as well". – Yogesh Dec 2 '16 at 8:54
  • I meant to say that only management pages are presented in Seven, but not content pages in general. For example --- If I edit a node, I see the edit page as in Seven, but if I view it, I see it in my regular theme. My aim is to view content also in Seven, when logged in as Admin. – JohnDoea Dec 2 '16 at 9:41
  • 1
    Please add screenshot of homepage as admin user – Akki Dec 2 '16 at 9:50
  • Note that label of that check box says "Use an administrative theme for editing or creating content" (not viewing content). That's still not clear what are "content pages" in your understanding. If you need to show all site content in Seven theme why not set it as default theme? – ya.teck Dec 2 '16 at 10:26
  • @Benia I've updated answer for D8 version. Please check. – Yogesh Dec 2 '16 at 11:22
5
+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).

  • Deep thanks for this magnificent answer Yogesh! Can you please elaborate on the sentence "page by itself." on the first passage? – JohnDoea Dec 2 '16 at 17:29
  • @Benia, it means Node module alters URL by it-self. I've updated the Ans please check and let me know if you've any doubts. – Yogesh Dec 3 '16 at 9:34
-4

You need install https://www.drupal.org/project/admin_toolbar

Once you install you will be able to do all the content related editing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.