FileUploadForm
class FileUploadForm extends AddFormBase (View source)
| internal | Form classes are internal. |
Creates a form to create media entities from uploaded files.
Traits
Provides dependency injection friendly methods for serialization.
Wrapper methods for the logger factory service.
Provides a trait for the messenger service.
Wrapper methods for the Redirect Destination.
Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.
Properties
| protected array | $_serviceIds | An array of service IDs keyed by property name used for serialization. |
from DependencySerializationTrait |
| protected array | $_entityStorages | An array of entity type IDs keyed by the property name of their storages. |
from DependencySerializationTrait |
| protected LoggerChannelFactoryInterface | $loggerFactory | The logger channel factory service. |
from LoggerChannelTrait |
| protected MessengerInterface | $messenger | The messenger. |
from MessengerTrait |
| protected RedirectDestinationInterface | $redirectDestination | The redirect destination service. |
from RedirectDestinationTrait |
| protected TranslationInterface | $stringTranslation | The string translation service. |
from StringTranslationTrait |
| protected RequestStack | $requestStack | The request stack. |
from FormBase |
| protected ConfigFactoryInterface | $configFactory | The config factory. |
from FormBase |
| protected RouteMatchInterface | $routeMatch | The route match. |
from FormBase |
| protected EntityTypeManagerInterface | $entityTypeManager | The entity type manager. |
from AddFormBase |
| protected MediaLibraryUiBuilder | $libraryUiBuilder | The media library UI builder. |
from AddFormBase |
| protected MediaTypeInterface | $mediaType | The type of media items being created by this form. |
from AddFormBase |
| protected EntityViewBuilderInterface | $viewBuilder | The media view builder. |
from AddFormBase |
| protected OpenerResolverInterface | $openerResolver | The opener resolver. |
from AddFormBase |
| protected ElementInfoManagerInterface | $elementInfo | The element info manager. |
|
| protected ElementInfoManagerInterface | $renderer | The renderer service. |
|
| protected FileSystemInterface | $fileSystem | The file system service. |
|
| protected FileUsageInterface | $fileUsage | The file usage service. |
Methods
Gets the logger for a specific channel.
Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
Returns the redirect destination service.
Sets the redirect destination service.
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
Instantiates a new instance of this class.
Sets the request stack object to use.
Returns a redirect response object for the specified route.
Constructs a new FileUploadForm.
Builds the element for submitting source field value(s).
Builds the sub-form for setting required fields on a new media item.
Lists the trusted callbacks provided by the implementing class.
Converts the set of newly added media into an item list for rendering.
Returns a render array containing the current selection.
Returns a render array for a single pre-selected media item.
Returns an array of supported actions for the form.
Creates media items from source field input values.
Creates a new, unsaved media item from a source field value.
Prepares a created media item to be permanently saved.
Submit handler for the remove button.
AJAX callback to update the entire form based on source field input.
Validate a created media item.
AJAX callback to send the new media item(s) to the media library.
AJAX callback to send the new media item(s) to the calling code.
Get the media library state from the form state.
Returns the name of the source field for a media type.
Get all pre-selected media items from the form state.
Get all pre-selected and added media items from the form state.
Determines if the "advanced UI" of the Media Library is enabled.
Returns a unique string identifying the form.
Processes an upload (managed_file) element.
Processes an image or file source field element.
Submit handler for the upload button, inside the managed_file element.
Details
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
protected LoggerInterface
getLogger(string $channel)
Gets the logger for a specific channel.
$this
setLoggerFactory(LoggerChannelFactoryInterface $logger_factory)
Injects the logger channel factory.
setMessenger(MessengerInterface $messenger)
Sets the messenger.
MessengerInterface
messenger()
Gets the messenger.
protected array
getDestinationArray()
Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
protected RedirectDestinationInterface
getRedirectDestination()
Returns the redirect destination service.
$this
setRedirectDestination(RedirectDestinationInterface $redirect_destination)
Sets the redirect destination service.
protected TranslatableMarkup
t(string $string, array $args = [], array $options = [])
Translates a string to the current language or to a given language.
See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.
In order for strings to be localized, make them available in one of the ways supported by the
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
getStringTranslation()
Gets the string translation service.
$this
setStringTranslation(TranslationInterface $translation)
Sets the string translation service to use.
static
create(ContainerInterface $container)
Instantiates a new instance of this class.
This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.
validateForm(array $form, FormStateInterface $form_state)
Form validation handler.
protected ImmutableConfig
config(string $name)
Retrieves a configuration object.
This is the main entry point to the configuration API. Calling
protected ConfigFactoryInterface
configFactory()
Gets the config factory for this form.
When accessing configuration values, use $this->config(). Only use this when the config factory needs to be manipulated directly.
$this
setConfigFactory(ConfigFactoryInterface $config_factory)
Sets the config factory for this form.
resetConfigFactory()
Resets the configuration factory.
protected Request
getRequest()
Gets the request object.
protected RouteMatchInterface
getRouteMatch()
Gets the route match.
$this
setRequestStack(RequestStack $request_stack)
Sets the request stack object to use.
protected AccountInterface
currentUser()
Gets the current user.
protected RedirectResponse
redirect(string $route_name, array $route_parameters = [], array $options = [], int $status = 302)
Returns a redirect response object for the specified route.
protected LoggerInterface
logger(string $channel)
Gets the logger for a specific channel.
This method exists for backward-compatibility between FormBase and LoggerChannelTrait. Use LoggerChannelTrait::getLogger() instead.
__construct(EntityTypeManagerInterface $entity_type_manager, MediaLibraryUiBuilder $library_ui_builder, ElementInfoManagerInterface $element_info, RendererInterface $renderer, FileSystemInterface $file_system, OpenerResolverInterface $opener_resolver, FileUsageInterface $file_usage)
Constructs a new FileUploadForm.
string|null
getBaseFormId()
Returns a string identifying the base form.
protected MediaTypeInterface
getMediaType(FormStateInterface $form_state)
Get the media type from the form state.
array
buildForm(array $form, FormStateInterface $form_state)
Form constructor.
protected array
buildInputElement(array $form, FormStateInterface $form_state)
Builds the element for submitting source field value(s).
The input element needs to have a submit handler to create media items from the user input and store them in the form state using ::processInputValues().
protected array
buildEntityFormElement(MediaInterface $media, array $form, FormStateInterface $form_state, int $delta)
Builds the sub-form for setting required fields on a new media item.
static string[]
trustedCallbacks()
Lists the trusted callbacks provided by the implementing class.
Trusted callbacks are public methods on the implementing class and can be invoked via \Drupal\Core\Security\DoTrustedCallbackTrait::doTrustedCallback().
array
preRenderAddedMedia(array $element)
Converts the set of newly added media into an item list for rendering.
protected array
buildCurrentSelectionArea(array $form, FormStateInterface $form_state)
Returns a render array containing the current selection.
protected array
buildSelectedItemElement(MediaInterface $media, array $form, FormStateInterface $form_state)
Returns a render array for a single pre-selected media item.
protected array
buildActions(array $form, FormStateInterface $form_state)
Returns an array of supported actions for the form.
protected
processInputValues(array $source_field_values, array $form, FormStateInterface $form_state)
Creates media items from source field input values.
protected MediaInterface
createMediaFromValue(MediaTypeInterface $media_type, EntityStorageInterface $media_storage, string $source_field_name, $file)
Creates a new, unsaved media item from a source field value.
protected
prepareMediaEntityForSave(MediaInterface $media)
Prepares a created media item to be permanently saved.
removeButtonSubmit(array $form, FormStateInterface $form_state)
Submit handler for the remove button.
AjaxResponse|array
updateFormCallback(array $form, FormStateInterface $form_state)
AJAX callback to update the entire form based on source field input.
protected
validateMediaEntity(MediaInterface $media, array $form, FormStateInterface $form_state, int $delta)
Validate a created media item.
submitForm(array $form, FormStateInterface $form_state)
Form submission handler.
array|AjaxResponse
updateLibrary(array $form, FormStateInterface $form_state)
AJAX callback to send the new media item(s) to the media library.
protected array
buildMediaLibraryUi(FormStateInterface $form_state)
Build the render array of the media library UI.
array|AjaxResponse
updateWidget(array $form, FormStateInterface $form_state)
AJAX callback to send the new media item(s) to the calling code.
protected MediaLibraryState
getMediaLibraryState(FormStateInterface $form_state)
Get the media library state from the form state.
protected string
getSourceFieldName(MediaTypeInterface $media_type)
Returns the name of the source field for a media type.
protected MediaInterface[]
getPreSelectedMediaItems(FormStateInterface $form_state)
Get all pre-selected media items from the form state.
protected MediaInterface[]
getAddedMediaItems(FormStateInterface $form_state)
Get all added media items from the form state.
protected MediaInterface[]
getCurrentMediaItems(FormStateInterface $form_state)
Get all pre-selected and added media items from the form state.
protected bool
isAdvancedUi()
Determines if the "advanced UI" of the Media Library is enabled.
This exposes additional features that are useful to power users.
string
getFormId()
Returns a unique string identifying the form.
The returned ID should be a unique string that can be a valid PHP function name, since it's used in hook implementation names such as hook_form_FORM_ID_alter().
array
validateUploadElement(array $element, FormStateInterface $form_state)
Validates the upload element.
array
processUploadElement(array $element, FormStateInterface $form_state)
Processes an upload (managed_file) element.
static array
hideExtraSourceFieldComponents(array $element, FormStateInterface $form_state, $form)
Processes an image or file source field element.
uploadButtonSubmit(array $form, FormStateInterface $form_state)
Submit handler for the upload button, inside the managed_file element.
protected FileItem
createFileItem(MediaTypeInterface $media_type)
Create a file field item.