protected function PhotosMediaLibraryForm::buildInputElement in Album Photos 8.5
Same name and namespace in other branches
- 6.0.x src/Form/PhotosMediaLibraryForm.php \Drupal\photos\Form\PhotosMediaLibraryForm::buildInputElement()
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().
Parameters
array $form: The complete form.
\Drupal\Core\Form\FormStateInterface $form_state: The current form state.
Return value
array The complete form, with the element added.
Overrides AddFormBase::buildInputElement
See also
::processInputValues()
File
- src/
Form/ PhotosMediaLibraryForm.php, line 44
Class
- PhotosMediaLibraryForm
- Creates a form to create media entities from oEmbed URLs.
Namespace
Drupal\photos\FormCode
protected function buildInputElement(array $form, FormStateInterface $form_state) {
$media_type = $this
->getMediaType($form_state);
// Add a container to group the input elements for styling purposes.
$form['container'] = [
'#type' => 'container',
];
// @todo need custom autocomplete results.
// Include albums that user has access to and that have images.
// @todo allow any target bundles.
$form['container']['photos'] = [
'#type' => 'entity_autocomplete',
'#target_type' => 'node',
'#title' => $this
->t('Photo album'),
'#description' => $this
->t('Photo album node.'),
'#required' => TRUE,
'#selection_handler' => 'default',
'#selection_settings' => [
'target_bundles' => [
'photos',
],
],
];
$form['container']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Add'),
'#button_type' => 'primary',
'#validate' => [
'::validateUrl',
],
'#submit' => [
'::addButtonSubmit',
],
'#ajax' => [
'callback' => '::updateFormCallback',
'wrapper' => 'media-library-wrapper',
// Add a fixed URL to post the form since AJAX forms are automatically
// posted to <current> instead of $form['#action'].
// @todo Remove when https://www.drupal.org/project/drupal/issues/2504115
// is fixed.
'url' => Url::fromRoute('media_library.ui'),
'options' => [
'query' => $this
->getMediaLibraryState($form_state)
->all() + [
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
],
],
],
];
return $form;
}