There is no way to select the 'default' view mode of an entity when using the entity_reference field. There should *always* be a 'default' option by default.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Status: Active » Needs review
FileSize
1.62 KB
Dave Reid’s picture

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Agreed :)

olli’s picture

Do you think we should make 'Default' view mode available also in custom blocks, views entity area and row plugins (in follow-ups)?

+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php
@@ -67,6 +67,9 @@ public function settingsSummary() {
+    if ($view_mode == 'default') {
+      $view_mode = t('Default');
+    }
     $summary[] = t('Rendered as @mode', array('@mode' => isset($view_modes[$view_mode]['label']) ? $view_modes[$view_mode]['label'] : $view_mode));

I'm not sure if this would be more readable as:

    if ($view_mode == 'default') {
      $view_mode = t('Default');
    }
    elseif (isset($view_modes[$view_mode]['label'])) {
      $view_mode = $view_modes[$view_mode]['label'];
    }
    $summary[] = t('Rendered as @mode', array('@mode' => $view_mode));
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 6023052 and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Dave Reid’s picture

I'm starting to wonder if entity_get_view_modes() should always include a 'default' => array('label' => t('Default')) in it's return value...

olli’s picture

Hmm. Found this saying:

An additional 'default' view mode is available for all entity types. This view mode is not intended for actual entity display, but holds default display settings.

Also: the default value for view mode is "full" here, but not all entity types have it.

So instead of providing the 'Default', what about providing the 'Full'? Or should we just change the docs by removing "is not intended for actual entity display, but" and maybe change the default value from "full" to "default"?

Dave Reid’s picture

That documentation is in my opinion, wrong. Default view mode is perfectly valid for display.