protected function MediaLibraryWidget::getNoMediaTypesAvailableMessage in Drupal 10
Same name and namespace in other branches
- 8 core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php \Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget::getNoMediaTypesAvailableMessage()
- 9 core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php \Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget::getNoMediaTypesAvailableMessage()
Gets the message to display when there are no allowed media types.
Return value
\Drupal\Component\Render\MarkupInterface The message to display when there are no allowed media types.
1 call to MediaLibraryWidget::getNoMediaTypesAvailableMessage()
- MediaLibraryWidget::formElement in core/
modules/ media_library/ src/ Plugin/ Field/ FieldWidget/ MediaLibraryWidget.php - Returns the form for a single field widget.
File
- core/
modules/ media_library/ src/ Plugin/ Field/ FieldWidget/ MediaLibraryWidget.php, line 619
Class
- MediaLibraryWidget
- Plugin implementation of the 'media_library_widget' widget.
Namespace
Drupal\media_library\Plugin\Field\FieldWidgetCode
protected function getNoMediaTypesAvailableMessage() {
$entity_type_id = $this->fieldDefinition
->getTargetEntityTypeId();
$default_message = $this
->t('There are no allowed media types configured for this field. Please contact the site administrator.');
// Show the default message if the user does not have the permissions to
// configure the fields for the entity type.
if (!$this->currentUser
->hasPermission("administer {$entity_type_id} fields")) {
return $default_message;
}
// Show a message for privileged users to configure the field if the Field
// UI module is not enabled.
if (!$this->moduleHandler
->moduleExists('field_ui')) {
return $this
->t('There are no allowed media types configured for this field. Edit the field settings to select the allowed media types.');
}
// Add a link to the message to configure the field if the Field UI module
// is enabled.
$route_parameters = FieldUI::getRouteBundleParameter($this->entityTypeManager
->getDefinition($entity_type_id), $this->fieldDefinition
->getTargetBundle());
$route_parameters['field_config'] = $this->fieldDefinition
->id();
$url = Url::fromRoute('entity.field_config.' . $entity_type_id . '_field_edit_form', $route_parameters);
if ($url
->access($this->currentUser)) {
return $this
->t('There are no allowed media types configured for this field. <a href=":url">Edit the field settings</a> to select the allowed media types.', [
':url' => $url
->toString(),
]);
}
// If the user for some reason doesn't have access to the Field UI, fall
// back to the default message.
return $default_message;
}