protected function MediaLibraryUiBuilder::buildMediaTypeAddForm in Drupal 9
Same name and namespace in other branches
- 8 core/modules/media_library/src/MediaLibraryUiBuilder.php \Drupal\media_library\MediaLibraryUiBuilder::buildMediaTypeAddForm()
Get the add form for the selected media type.
Parameters
\Drupal\media_library\MediaLibraryState $state: The current state of the media library, derived from the current request.
Return value
array The render array for the media type add form.
1 call to MediaLibraryUiBuilder::buildMediaTypeAddForm()
- MediaLibraryUiBuilder::buildLibraryContent in core/
modules/ media_library/ src/ MediaLibraryUiBuilder.php - Build the media library content area.
File
- core/
modules/ media_library/ src/ MediaLibraryUiBuilder.php, line 285
Class
- MediaLibraryUiBuilder
- Service which builds the media library.
Namespace
Drupal\media_libraryCode
protected function buildMediaTypeAddForm(MediaLibraryState $state) {
$selected_type_id = $state
->getSelectedTypeId();
$access_handler = $this->entityTypeManager
->getAccessControlHandler('media');
$context = [
'media_library_state' => $state,
];
if (!$access_handler
->createAccess($selected_type_id, NULL, $context)) {
return [];
}
$selected_type = $this->entityTypeManager
->getStorage('media_type')
->load($selected_type_id);
$plugin_definition = $selected_type
->getSource()
->getPluginDefinition();
if (empty($plugin_definition['forms']['media_library_add'])) {
return [];
}
// After the form to add new media is submitted, we need to rebuild the
// media library with a new instance of the media add form. The form API
// allows us to do that by forcing empty user input.
// @see \Drupal\Core\Form\FormBuilder::doBuildForm()
$form_state = new FormState();
if ($state
->get('_media_library_form_rebuild')) {
$form_state
->setUserInput([]);
$state
->remove('_media_library_form_rebuild');
}
$form_state
->set('media_library_state', $state);
return $this->formBuilder
->buildForm($plugin_definition['forms']['media_library_add'], $form_state);
}