You are here

protected function InstagramMediaLibraryAddForm::buildInputElement in Media entity Instagram 3.x

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/InstagramMediaLibraryAddForm.php, line 26

Class

InstagramMediaLibraryAddForm
Creates a form to create Instagram media entities from within Media Library.

Namespace

Drupal\media_entity_instagram\Form

Code

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',
      'url' => Url::fromRoute('media_library.ui'),
      'options' => [
        'query' => $this
          ->getMediaLibraryState($form_state)
          ->all() + [
          FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
        ],
      ],
    ],
  ];
  return $form;
}