function MediaHooks::addUrl
Same name and namespace in other branches
- main core/modules/media/src/Hook/MediaHooks.php \Drupal\media\Hook\MediaHooks::addUrl()
Returns the appropriate URL to add media for the current user.
@todo Remove in https://www.drupal.org/project/drupal/issues/2938116
@internal This function is internal and may be removed in a minor release.
Parameters
string[] $allowed_bundles: An array of bundles that should be checked for create access.
Return value
string|false The URL to add media, or FALSE if the user cannot create any media.
1 call to MediaHooks::addUrl()
- MediaHooks::fieldWidgetCompleteFormAlter in core/
modules/ media/ src/ Hook/ MediaHooks.php - Implements hook_field_widget_complete_form_alter().
File
-
core/
modules/ media/ src/ Hook/ MediaHooks.php, line 316
Class
- MediaHooks
- Hook implementations for media.
Namespace
Drupal\media\HookCode
protected function addUrl(array $allowed_bundles) : string|false {
$access_handler = \Drupal::entityTypeManager()->getAccessControlHandler('media');
$create_bundles = array_filter($allowed_bundles, [
$access_handler,
'createAccess',
]);
// Add a section about how to create media if the user has access to do so.
if (count($create_bundles) === 1) {
return Url::fromRoute('entity.media.add_form', [
'media_type' => reset($create_bundles),
])->toString();
}
elseif (count($create_bundles) > 1) {
return Url::fromRoute('entity.media.add_page')->toString();
}
return FALSE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.