I have generated a custom content entity via the Drupal Console. It has bundles. I would like to customise the screen which you get to when adding a new such entity - the screen which displays the list of bundles, to click on the type you want to add.

When I generated the entity, a bunch of template files were created, including one called <my_entity>-content-add-list.html.twig. I am certain this is intended to override the core template called entity-add-list-html.twig. However, changes I make to it do not take effect, and by putting twig in debug mode and viewing the source, I can see that it is not being overridden.

Do I need to add a theme suggestion hook? If so, what would the name of the function be? I feel like I must be missing something. Given that the console generated that template I am surprised it is not automatically used. But surely there must be a simple way of telling Drupal to use it.

EDIT: I've found what to name the function: it's mymodule_theme_suggestions_entity_add_list. But the machine name of the entity is nowhere in the $variables array that I can easily get at. I'm looking at parsing the route to get it out, which seems rather hacky

1 Answer 1


So I got there in the end (the machine name of the entity being oc_activity:

function opencase_entities_theme_suggestions_entity_add_list(array $variables) {
  $route_name = \Drupal::routeMatch()->getRouteName();
  $suggestions = []; 
  if ($route_name == "entity.oc_activity.add_page") {
    $suggestions[] = 'oc_activity_content_add_list';
  return $suggestions;

But it feels too hacky & hard-coded; it seems there ought to be a nicer way.

Also, the template file that was generate by the console assumed that the array of bundles was called types when actually it was bundles. So I had to change the generated code from for type in types to for type in bundles. Just putting that here in case it's useful to anyone...

Your Answer

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

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