I have created a super-simple drupal 8 custom entity. We now need a custom view mode for this entity. What do I need to add to my definition to make my entity appear as an option on the 'Add View Mode' page: /admin/structure/display-modes/view/add ?

My super-simple entity definition is

 * @ContentEntityType(
 *   id = "schedulecal",
 *   label = @Translation("ScheduleCalendar"),
 *   base_table = "scheduler_entity_calendars",
 *   entity_keys = {
 *     "id" = "id",
 *     "uuid" = "uuid",
 *   },
 * )

I can't find this info anywhere in doc.


1 Answer 1


You need a view builder class in the handler section:

 *   handlers = {
 *     "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",

and a field UI route:

 *   field_ui_base_route = "my_entity.settings",

pointing at the config form for the settings of your entity type. If you don't have settings return at least a #markup element:

  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['my_entity_settings']['#markup'] = 'Settings form for My Entity entities. Manage field settings here.';
    return $form;
  • I also had to add a route to my_entity.settings passing it the form like so - form: '\Drupal\my_module\Form\MySettingsForm'
    – Cameron
    Sep 23, 2022 at 11:06
  • Oh and to actually theme the view mode via a template you will need to implement a theme hook, as outlined here jimconte.com/blog/web/themeing-a-custom-content-entity
    – Cameron
    Sep 23, 2022 at 11:26

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.