You are here

protected function SoundcloudForm::buildInputElement in Media entity Soundcloud 3.x

Same name and namespace in other branches
  1. 8.2 src/Form/SoundcloudForm.php \Drupal\media_entity_soundcloud\Form\SoundcloudForm::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/SoundcloudForm.php, line 70

Class

SoundcloudForm

Namespace

Drupal\media_entity_soundcloud\Form

Code

protected function buildInputElement(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $container = [
    '#type' => 'container',
  ];
  $container['soundcloud_url'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t("Add Soundcloud Track"),
  ];
  $container['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add'),
    '#button_type' => 'primary',
    '#submit' => [
      '::addButtonSubmit',
    ],
    '#validate' => [
      '::validateSoundcloudUrl',
    ],
    '#ajax' => [
      'callback' => '::updateFormCallback',
      'wrapper' => 'media-library-wrapper',
      // @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,
        ],
      ],
    ],
  ];
  $form['container'] = $container;
  return $form;
}