Use admin theme for add and edit forms of some content types, but not all

Created on 21 March 2025, 15 days ago

Problem/Motivation

I think this is a feature request, but of course i would be thrilled if it turns out to be a support request, and i'm just not seeing how to do it.

We have some node bundles where the content creation and updating forms should use the front-end theme, and others where they should use the administration theme. Both staff and visitor roles should be able to use either theme for content editing, but based on which type of content they are creating or editing not their own choice or their role.

Proposed resolution

Add settings or a submodule to choose to use the administrative theme per content type, rather than strictly by "route", which as far as i can tell does not have the context of content type. Drupal core's node module does this in NodeAdminRouteSubscriber::alterRoutes() but i cannot see content type / bundle (on create forms) nor node object (on edit forms) in that method in the debugger.

This module seems to take a very different approach, not setting the _admin_route option on routes, so i hope it is more flexible/amenable to this need.

Remaining tasks

Decide if this module can already do this, or if this feature should be added in the main module, or added as a submodule.

Thank you for contributing this module! If this feature seems a good fit for it i can try to help contribute it.

User interface changes

Somewhere, settings that ask which content types should use the administration theme. Maybe even add that to /admin/appearance, or put a link there to a settings page provided by this module, so people know how to "Use the administration theme when editing or creating content" for only specific types of nodes.

API changes

Data model changes

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇺🇸United States mlncn Minneapolis, MN, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mlncn
  • 🇪🇸Spain psf_ Huelva

    Hi @mlncn,

    Thank you for your suggestion and for contributing to the module discussion!

    After reviewing your request, I believe that the functionality you're looking for—applying the admin theme based on content type rather than strictly by route—is not directly related to this module. The reason is that Drupal’s routing system does not differentiate between bundles when determining which theme to apply, especially for creation forms (/node/add/{content_type}).

    A more effective approach would be to handle this via a separate module that implements a Theme Negotiator, which can check the content type dynamically and apply the appropriate theme accordingly.

    If the Admin Theme module does not fully cover your needs, I’d be happy to help guide or assist in developing a new module specifically for this feature. Let me know if you're interested in collaborating on this!

    Thanks again for your input!

    Best

  • 🇺🇸United States mlncn Minneapolis, MN, USA

    Thank you so much for your quick and kind response!

    Admin Theme has the same

    I am curious why Simple Admin Theme by Route uses event subscriber when alterRoutes should be enough to add _admin_route

    And do you know for certain that your EventSubscriberInterface onKernelRequest() cannot set the theme for non-route things like path for the creation forms and what type of object (or rather bundle of entity) for edit forms? Since i'll have to grab the request anyway your approach seems a little more straightforward than the ThemeNegotiator approaches i'm finding.

    Thank you very much for everything!

    (New module coming shortly…)

  • 🇺🇸United States mlncn Minneapolis, MN, USA

    And the module is done!

    Administration Theme by Content Type - https://www.drupal.org/project/admin_theme_by_content_type

    I think you are right it is more straightforward for the end-user as a standalone. Thanks!

  • 🇺🇸United States mlncn Minneapolis, MN, USA
  • 🇪🇸Spain psf_ Huelva

    Hi,

    Nice project :D I added the "similar projects" section with your module too : )))

  • 🇪🇸Spain psf_ Huelva
  • 🇪🇸Spain psf_ Huelva
Production build 0.71.5 2024