With Media Entity module OOTB, there are no configured view modes. The select widgets for entity browser show as empty. This is incorrect, as the core entity system always provides a 'default' view mode.

Comments

joachim created an issue. See original summary.

slashrsm’s picture

Category: Bug report » Task
Issue tags: +D8Media

I am not sure what "select widgets" refers to. Could you elaborate?

joachim’s picture

When I configure an entity reference field to use the Entity Browser widget, there is a section ' Entity display plugin configuration '. This has a dropdown for the view mode.

Looks like it's this code:

  public function settingsForm(array $form, FormStateInterface $form_state) {
    $options = [];
    foreach ($this->entityDisplayRepository->getViewModes($this->configuration['entity_type']) as $id => $view_mode) {
      $options[$id] = $view_mode['label'];
    }

    return [
      'view_mode' => [
        '#type' => 'select',
        '#title' => $this->t('View mode'),
        '#description' => $this->t('Select view mode to be used when rendering entities.'),
        '#default_value' => !empty($this->configuration['view_mode']) ? $this->configuration['view_mode'] : NULL,
        '#options' => $options,
      ],
    ];
  }

I wonder why getViewModes() isn't providing the default view mode?

(Lastly, I really don't understand why you're categorizing this as a task and not a bug. One of the view modes that I can configure in the entity UI is missing in the dropdown. How is that not something that's broken?)

gausarts’s picture

Probably a miss? There is a method ::getViewModeOptions() for the select options, so the options part can just use:
$options = $this->entityDisplayRepository->getViewModeOptions($this->configuration['entity_type']);
It should reveal the mentioned default view mode.

slashrsm’s picture

Issue tags: +Novice

Solution that @gausarts proposed in #4 seems to be the way to go. Thank you for pointing that out.

berdir’s picture

Core is actually inconsistent here.

default is not a view mode, it is a view display that is the fallback if a view mode is used that doesn't exist. \Drupal\Core\Entity\EntityViewBuilder::view() defaults to full, not default.

Being able to select and use default in the UI results in a lot of confusion actually.

joachim’s picture

Category: Task » Bug report
Status: Active » Needs review
StatusFileSize
new874 bytes

Here's a patch.

samuel.mortenson’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

esolitos’s picture

Patch from #7 seems to be the right approach, also I can confirm that it fixes the issue.

  • slashrsm committed dd95fee on 8.x-1.x authored by joachim
    Issue #2806693 by joachim, Berdir, esolitos: File field widget...
slashrsm’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks!

Status: Fixed » Closed (fixed)

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

aminshamim’s picture

#7 ; Its not working for me. Applied the patch but still view mood is not present in the form.