Problem/Motivation
The template suggestions have a "custom" view mode. It would be nice to have the correct view mode in the template suggestions.
Steps to reproduce
<?php
namespace Drupal\example\Plugin\ExtraField\Display;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\extra_field\Plugin\ExtraFieldDisplayFormattedBase;
/**
* Extrafield formatter.
*
* @ExtraFieldDisplay(
* id = "node_type",
* label = @Translation("Node type"),
* bundles = {
* "node.*"
* }
* )
*/
class NodeType extends ExtraFieldDisplayFormattedBase {
/**
* {@inheritdoc}
*/
public function viewElements(ContentEntityInterface $entity) {
return [
'#markup' => $entity->type->entity->label(),
];
}
}
Suggestions:
<!-- FILE NAME SUGGESTIONS:
* field--node--extra-field-node-type--article---custom.html.twig
* field--node--extra-field-node-type---custom.html.twig
* field--node--extra-field-node-type--article.html.twig
* field--node--extra-field-node-type.html.twig
* field--node--article.html.twig
* field--extra-field-node-type.html.twig
* field--extra-field.html.twig
x field.html.twig
-->
Suggestions should be, with a "alert" view mode:
<!-- FILE NAME SUGGESTIONS:
* field--node--extra-field-node-type--article---alert.html.twig
* field--node--extra-field-node-type---alert.html.twig
* field--node--extra-field-node-type--article.html.twig
* field--node--extra-field-node-type.html.twig
* field--node--article.html.twig
* field--extra-field-node-type.html.twig
* field--extra-field.html.twig
x field.html.twig
-->
Comments
Comment #2
jnettikThis seems to be done deliberately to get around the Quickedit module. In
ExtraFieldDisplayFormattedBase::view()there's this array:I got around this issue (I'm not using Quickedit) by adding a
::view()method to my class and overrode the view mode:Comment #5
prudloff commentedThe MR keeps the quickedit workaround but also adds template suggestions back.
It also keeps the
-customsuggestion for retro-compatibility.Comment #6
timohuismanI'm not sure why, but I get a 404 when I try to create a new branch for this issue.
Anyhow, Quickedit is no longer in core, see #3259831: Quick Edit is deprecated. So we could just use the existing view mode instead of overwriting it.
Comment #8
prudloff commentedI agree that dropping the quickedit workaround would be the easiest way to fix this.
Comment #9
pcambraComment #10
arousseau commentedMR 13 applies cleanly to 3.0 and I get the following template suggestions, with the correct view mode.
It looks safe to merge.
Comment #12
pcambraThanks all!
Comment #14
prudloff commentedIs there a plan to publish a release containing this fix?