-1

I would like to style one of my custom post type edit screens in the admin section differently from others. It is actually a slider and I would like the content editor to have drag/drop alignment control for some images in the slides.

The usual Drupal way would be to create/override the template for my specific content type using theme suggestions and modify it to my liking, but there is very minimal amount of suggestions for backend. I have enabled twig debug to add suggestions to the markup as comments.

I'm thinking this could be accomplished by hook_theme_suggestions_HOOK_alter? but I'm unable to pick a start.

I'm using default classy theme.

Take the following content structure for example, A paragraph of type Slide 1 which contains a field named field_title. This paragraph is added to a content type, Slider, using "paragraph" field type.

I want to modify how this field appears for this particular content type while editing in the backend. Not just CSS, but I want to add additional HTML elements around this text field for my design needs. But how do I override a template specific to this field when twig debug only shows me following template suggestions

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'input__textfield' -->
<!-- 
    FILE NAME SUGGESTIONS:
    * input--textfield.html.twig
    x input.html.twig
-->
<!-- BEGIN OUTPUT from 'core/themes/classy/templates/form/input.html.twig' -->
  • 1
    Theme suggestions are for any/all installed themes, not theme-specific. Any theme can implement any template. so it's hard to tell exactly what you mean. – Jaypan May 16 at 4:46
  • 1
    Well your thinking was correct in that you want hook_theme_suggestions_alter() or hook_theme_suggestions_HOOK_alter(). This will allow templates to be created in any theme, including the admin theme. – Jaypan May 16 at 6:02
  • 1
    Yes, theme suggestions are for all the themes, but the first example given in hook_theme_suggestions_alter() is verifying the user is logged-in. It makes me think it's acceptable for the hook to check if the currently used theme is the administrative theme. – kiamlaluno May 16 at 12:11
  • 2
    The question needs to be more clear where the hook is placed. If it is in a module then the suggestions will apply to any theme which wins the theme negotiation. If it is placed in a theme then it will only apply to this theme, because otherwise the hook will not be executed. In case of the core admin theme you need to place the hook in a module or in a subtheme of the admin theme. – 4k4 May 16 at 16:01
  • 1
    Nonetheless you have to clarify the question which theme you want to use for editing content (depends on user roles or the checkbox at the end of the theme settings). Then create a subtheme and place the customized templates (and the hooks to select and prepare the templates) in this custom theme. – 4k4 May 17 at 7:51

Your Answer

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

Browse other questions tagged or ask your own question.