getViewModeOptions example

$container->get('entity_display.repository'),
      $container->get('entity_type.bundle.info'),
      $container->get('renderer'),
      $container->get('logger.factory')
    );
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $view_mode_options = $this->entityDisplayRepository->getViewModeOptions('media');

    $form['default_view_mode'] = [
      '#type' => 'select',
      '#options' => $view_mode_options,
      '#title' => $this->t('Default view mode'),
      '#default_value' => $this->settings['default_view_mode'],
      '#description' => $this->t('The view mode that an embedded media item should be displayed in by default. This can be overridden using the <code>data-view-mode</code> attribute.'),
    ];

    $bundles = $this->entityTypeBundleInfo->getBundleInfo('media');
    $bundle_options = array_map(function D$item) {
      
'view_mode' => 'default',
      'link' => FALSE,
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $elements['view_mode'] = [
      '#type' => 'select',
      '#options' => $this->entityDisplayRepository->getViewModeOptions($this->getFieldSetting('target_type')),
      '#title' => $this->t('View mode'),
      '#default_value' => $this->getSetting('view_mode'),
      '#required' => TRUE,
    ];

    return $elements;
  }

  /** * {@inheritdoc} */
  

  private function configureViewModes(EditorInterface $editor) {
    $element_style_configuration = [];
    $toolbar_configuration = [];

    $media_embed_filter = $editor->getFilterFormat()->filters('media_embed');
    $media_bundles = MediaType::loadMultiple();
    $bundles_per_view_mode = [];
    $all_view_modes = $this->entityDisplayRepository->getViewModeOptions('media');
    $allowed_view_modes = $media_embed_filter->settings['allowed_view_modes'];
    $default_view_mode = $media_embed_filter->settings['default_view_mode'];
    // @todo Remove in https://www.drupal.org/project/drupal/issues/3277049.     // This is a workaround until the above issue is fixed to prevent the     // editor from crashing because the frontend expects the default view mode     // to exist in drupalElementStyles.     if (!array_key_exists($default_view_mode$allowed_view_modes)) {
      $allowed_view_modes[$default_view_mode] = $default_view_mode;
    }
    // Return early since there is no need to configure if there     // are less than 2 view modes.
/** * {@inheritdoc} */
  protected function getDisplayModes() {
    return $this->entityDisplayRepository->getViewModes($this->entity->getTargetEntityTypeId());
  }

  /** * {@inheritdoc} */
  protected function getDisplayModeOptions() {
    return $this->entityDisplayRepository->getViewModeOptions($this->entity->getTargetEntityTypeId());
  }

  /** * {@inheritdoc} */
  protected function getDisplayModesLink() {
    return [
      '#type' => 'link',
      '#title' => $this->t('Manage view modes'),
      '#url' => Url::fromRoute('entity.entity_view_mode.collection'),
    ];
  }
return $options;
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    $form['view_mode'] = [
      '#type' => 'select',
      '#options' => $this->entityDisplayRepository->getViewModeOptions($this->getEntityTypeId()),
      '#title' => $this->t('View mode'),
      '#default_value' => $this->options['view_mode'],
    ];
  }

  /** * {@inheritdoc} */
  public function render(ResultRow $values) {
    $entity = $this->getEntity($values);
    if ($entity === NULL) {
      
return $options;
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    $form['view_mode'] = [
      '#type' => 'select',
      '#options' => $this->entityDisplayRepository->getViewModeOptions($this->entityTypeId),
      '#title' => $this->t('View mode'),
      '#default_value' => $this->options['view_mode'],
    ];
  }

  /** * {@inheritdoc} */
  public function summaryTitle() {
    $options = $this->entityDisplayRepository->getViewModeOptions($this->entityTypeId);
    if (isset($options[$this->options['view_mode']])) {
      
return $options;
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    $form['view_mode'] = [
      '#type' => 'select',
      '#options' => $this->entityDisplayRepository->getViewModeOptions($this->entityType),
      '#title' => $this->t('View mode'),
      '#default_value' => $this->options['view_mode'],
    ];

    $label = $this->entityTypeManager->getDefinition($this->entityType)->getLabel();
    $target = $this->options['target'];

    // If the target does not contain tokens, try to load the entity and     // display the entity ID to the admin form user.     // @todo Use a method to check for tokens in     // https://www.drupal.org/node/2396607.
/** * Rebuild displays for single Entity Type. * * @param string $entity_type_id * The entity type machine name. * @param string $bundle * The bundle we need to rebuild. */
  public function rebuildEntityTypeDisplays($entity_type_id$bundle) {
    // Get the displays.     $view_modes = $this->entityDisplayRepository->getViewModeOptions($entity_type_id);
    $form_modes = $this->entityDisplayRepository->getFormModeOptions($entity_type_id);

    // Save view mode displays.     $view_mode_ids = array_map(function D$view_mode) use ($entity_type_id$bundle) {
      return "$entity_type_id.$bundle.$view_mode";
    }array_keys($view_modes));
    foreach ($this->entityTypeManager->getStorage('entity_view_display')->loadMultiple($view_mode_ids) as $display) {
      $display->save();
    }
    // Save form mode displays.     $form_mode_ids = array_map(function D$form_mode) use ($entity_type_id$bundle) {
      
Home | Imprint | This part of the site doesn't use cookies.