0

Sorry if this has been asked already, I haven't seen anything yet exactly what I'm looking for.

I'm using the Views UI in Drupal 8 to output a list of a custom content entity type that I created via a custom module. I'd like to know what's the best way to programatically alter the markup of the entire entity.

I know that to do this with a field belonging to the entity you would use {module}\src\Plugin\Field\FieldFormatter\{formattername}.php and this would appear as an option for displaying a field, but is there a way to do this for the whole entity rather than just a field?

If there are any articles on this topic anyone could recommend I would greatly appreciate it, thank you.

  • 1
    Yes. Output the view result as a view Mode and not as fields, then supply the markup for the view Mode twig template + fields as normal. Views will respect that and use it instead of of the view rendering fields by itself. – Kevin Aug 9 '17 at 4:10
  • Thank you for the reply @Kevin, I'm not exactly sure what you mean by "Output the view result as a view Mode". Does this refer to the "Format" section of the display settings? Under the "Show" setting there the only options I see are Fields, [entity class name], and Search. – saramm1 Aug 9 '17 at 13:39
  • Nodes have a "Content" format that lets you select the view mode to render as. I assume by "custom content type" you don't mean you created a new node type, because this option is available on a Node based view. – Kevin Aug 9 '17 at 13:47
  • Correct, it is a custom entity that doesn't extend the node type. – saramm1 Aug 9 '17 at 13:49

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.