function EditorMediaDialog::getViewModeDefaultValue

Same name in other branches
  1. 9 core/modules/media/src/Form/EditorMediaDialog.php \Drupal\media\Form\EditorMediaDialog::getViewModeDefaultValue()
  2. 8.9.x core/modules/media/src/Form/EditorMediaDialog.php \Drupal\media\Form\EditorMediaDialog::getViewModeDefaultValue()

Gets the default value for the view mode form element.

Parameters

array $view_mode_options: The array of options for the view mode form element.

\Drupal\filter\Plugin\FilterInterface $media_embed_filter: The media embed filter.

string $media_element_view_mode_attribute: The data-view-mode attribute on the <drupal-media> element.

Return value

string|null The default value for the view mode form element.

1 call to EditorMediaDialog::getViewModeDefaultValue()
EditorMediaDialog::buildForm in core/modules/media/src/Form/EditorMediaDialog.php

File

core/modules/media/src/Form/EditorMediaDialog.php, line 296

Class

EditorMediaDialog
Provides a media embed dialog for text editors.

Namespace

Drupal\media\Form

Code

public static function getViewModeDefaultValue(array $view_mode_options, FilterInterface $media_embed_filter, $media_element_view_mode_attribute) {
    // The select element won't display without at least two options, so if
    // that's the case, just return NULL.
    if (count($view_mode_options) < 2) {
        return NULL;
    }
    $filter_default_view_mode = $media_embed_filter->settings['default_view_mode'];
    // If the current media embed ($media_embed_element) has a set view mode,
    // we want to use that as the default in the select form element,
    // otherwise we'll want to use the default for all embedded media.
    if (!empty($media_element_view_mode_attribute) && array_key_exists($media_element_view_mode_attribute, $view_mode_options)) {
        return $media_element_view_mode_attribute;
    }
    elseif (array_key_exists($filter_default_view_mode, $view_mode_options)) {
        return $filter_default_view_mode;
    }
    return NULL;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.