protected function TwitterMediaLibraryAddForm::buildInputElement in Media entity Twitter 8.2
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/ TwitterMediaLibraryAddForm.php, line 26
Class
- TwitterMediaLibraryAddForm
- Creates a form to create Twitter media entities from within Media Library.
Namespace
Drupal\media_entity_twitter\FormCode
protected function buildInputElement(array $form, FormStateInterface $form_state) {
$media_type = $this
->getMediaType($form_state);
$form['container'] = [
'#type' => 'container',
'#title' => $this
->t('Add @type', [
'@type' => $media_type
->label(),
]),
];
$form['container']['url'] = [
'#type' => 'url',
'#title' => $this
->getSourceFieldDefinition($media_type)
->getLabel(),
'#description' => $this
->getSourceFieldDefinition($media_type)
->getDescription(),
'#required' => TRUE,
'#attributes' => [
'placeholder' => 'https://',
],
];
$form['container']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Add'),
'#button_type' => 'primary',
'#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.
// Follow along with changes in \Drupal\media_library\Form\OEmbedForm.
'url' => Url::fromRoute('media_library.ui'),
'options' => [
'query' => $this
->getMediaLibraryState($form_state)
->all() + [
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
],
],
],
];
return $form;
}