4

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.

5

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;
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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