public static function EditorMediaDialog::getViewModeDefaultValue in Drupal 8
Same name and namespace in other branches
- 9 core/modules/media/src/Form/EditorMediaDialog.php \Drupal\media\Form\EditorMediaDialog::getViewModeDefaultValue()
- 10 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 287
Class
- EditorMediaDialog
- Provides a media embed dialog for text editors.
Namespace
Drupal\media\FormCode
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;
}