AddMediaForm
extends FormBase
in package
Provides a form to add or edit media entities.
This form facilitates the addition of media to a site's content, allowing users to select from existing media entities, configure titles, and manage publication status.
Table of Contents
Methods
- access() : AccessResult
- Checks if the user can edit their own article.
- buildForm() : array<string|int, mixed>
- Builds the add/edit media form.
- getFormId() : string
- {@inheritdoc}
- getMediaOptions() : array<string|int, mixed>
- Retrieves options for the media select element.
- mediaSelectedCallBack() : array<string|int, mixed>
- AJAX callback for media selection changes.
- submitAjax() : AjaxResponse
- AJAX form submission handler.
- submitForm() : void
- Submits the add/edit media form.
Methods
access()
Checks if the user can edit their own article.
public
access(Request $request, AccountInterface $account) : AccessResult
Parameters
- $request : Request
- $account : AccountInterface
Return values
AccessResultbuildForm()
Builds the add/edit media form.
public
buildForm(array<string|int, mixed> $form, FormStateInterface $form_state) : array<string|int, mixed>
Parameters
- $form : array<string|int, mixed>
-
An associative array containing the structure of the form.
- $form_state : FormStateInterface
-
The current state of the form.
Return values
array<string|int, mixed> —The form structure.
getFormId()
{@inheritdoc}
public
getFormId() : string
Return values
stringgetMediaOptions()
Retrieves options for the media select element.
public
getMediaOptions() : array<string|int, mixed>
Generates an options array for the media select element, grouping media by type for easier selection in the form.
Tags
Return values
array<string|int, mixed> —An associative array of media options, grouped by media type.
mediaSelectedCallBack()
AJAX callback for media selection changes.
public
mediaSelectedCallBack(array<string|int, mixed> &$form, FormStateInterface $form_state) : array<string|int, mixed>
Updates form elements dynamically based on the selected media entity, such as enabling or disabling the publication status checkbox.
Parameters
- $form : array<string|int, mixed>
-
The form array.
- $form_state : FormStateInterface
-
The state of the form.
Return values
array<string|int, mixed> —The updated form elements.
submitAjax()
AJAX form submission handler.
public
submitAjax(array<string|int, mixed> &$form, FormStateInterface $form_state) : AjaxResponse
Processes the form submission via AJAX, improving user experience by providing immediate feedback and avoiding full page reloads.
Parameters
- $form : array<string|int, mixed>
-
The form array.
- $form_state : FormStateInterface
-
The current state of the form.
Tags
Return values
AjaxResponse —An AJAX response to update the UI based on the form submission.
submitForm()
Submits the add/edit media form.
public
submitForm(array<string|int, mixed> &$form, FormStateInterface $form_state) : void
Processes the submitted form values to either create a new media link within the content structure or update an existing one.
Parameters
- $form : array<string|int, mixed>
-
The form array.
- $form_state : FormStateInterface
-
The state of the form.