OK maybe someone can help me with this.
I have the node edit template working (one node edit template for all node types) by looking at the seven theme. What I am looking to do though is have a separate node edit template per content type, Luke what you can do with the node view template system. Is this possible and if so can someone help me out a bit?

Comments

onejam’s picture

You can turn on debug to look at theme suggestions output.

Open /sites/default/services.yml

and change:

debug: true

Clear the cache and when you view a node page, you should see some theme suggestions.

When you add a new template, don't forget to clear the cache each time so it will appear.

Also, take a look at Drupal 8 template naming conventions: https://www.drupal.org/node/2354645

-----------------------------------------------------------------
We build engaging websites and intuitive designs that will benefit your business.
Duvien

Draven_Caine’s picture

Its for the node edit, not the node view.

Draven_Caine’s picture

There isn't a services file, only default.services. where should the debug info print? I don't see it on the view or edit page.

onejam’s picture

Sorry yes, default.services.yml on line 58 (see: https://www.drupal.org/node/1906392)

You create a template file and place it in your theme folder to override the default template. Perhaps, i misunderstood what you are trying to do? are trying to create a new content type so you can have a different edit node?

-----------------------------------------------------------------
We build engaging websites and intuitive designs that will benefit your business.
Duvien

Draven_Caine’s picture

No the template used for the node edit form (content/3/edit for example) right now I had to add a function to my .theme file for it to use node-edit-form.HTML.twig. that file controls all node edit forms, I want a separate template file per content type on the edit form. So "plants page" content type would use a different template file for it's edit form than "campgrounds" content type.

Draven_Caine’s picture

I have the template working, (look at the theme suggestion in bartik). Now I am trying to get individual form fields to print. {{ children }} prints all form fields. Any help?

chrisshattuck’s picture

This feels hacky, but it's the best I can come up with. First add this code to your admin .theme file (likely a sub-theme of Seven):

function NAMEOFTHEME_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
  if ($hook == 'node_edit_form') {
    if ($node = \Drupal::routeMatch()->getParameter('node')) {
      $content_type = $node->bundle();
    } else {
      $current_path = \Drupal::service('path.current')->getPath();
      $path_args = explode('/', $current_path);
      $content_type = $path_args[3];
    }
    $suggestions[] = 'node_edit_form__' . $content_type;
  }
}

Next, create twig templates in your theme's template directory in the form of node-edit-form--NODE-TYPE-SEPARATED-WITH-DASHES.html.twig.

Learn virtually any aspect of Drupal on BuildAModule, where I've recorded over 2200 video tutorials.

mmlmitchell’s picture

The hook_theme_suggestions_alter works great. Thanks for that. Could it be used to target a form mode?

scott.whittaker’s picture

hook_theme_suggestions_alter gets called a lot on a node edit page, but 'node_edit_form' is not one of the $hook values. HTML, Page, Regions, Blocks and Fields are all listed, but not the node form itself. I can't find anything else there to hook on to add the node edit template suggestion to.

Edit: turns out my problem is that I want to display node edit forms using the front-end theme. I'm doing this by setting _admin_route to false using an alterRoutes function in a custom RouteSubscriber class in my module. This works a treat, but it seems to prevent hook_theme_suggestions_alter from being called.

To fix this issue, I had to use a hook_form_alter in my module to catch all the node forms and set:

$form['#theme'] = ['node_edit_form'];

robpowell’s picture

I created a step by step guide here https://drupal.stackexchange.com/a/308548/69482