You are here

public function OembedProviderBucketForm::form in oEmbed Providers 2.x

Overrides Drupal\Core\Entity\EntityForm::form().

Parameters

array $form: A nested array form elements comprising the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The array containing the complete form.

Overrides EntityForm::form

File

src/OembedProviderBucketForm.php, line 78

Class

OembedProviderBucketForm
Form controller for the oEmbed provider bucket edit/add forms.

Namespace

Drupal\oembed_providers

Code

public function form(array $form, FormStateInterface $form_state) {
  if ($this->operation == 'edit') {
    $form['#title'] = $this
      ->t('<em>Edit oEmbed provider bucket</em> @label', [
      '@label' => $this->entity
        ->label(),
    ]);
  }
  $entity = $this->entity;
  $form['security_warning'] = [
    '#markup' => HelperTrait::disabledProviderSecurityWarning(),
    // Simulate warning message.
    '#prefix' => '<div role="contentinfo" aria-label="Warning message" class="messages messages--warning">',
    '#suffix' => '</div>',
  ];
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Bucket name'),
    '#default_value' => $entity
      ->label(),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $entity
      ->id(),
    '#machine_name' => [
      'exists' => [
        $this,
        'exist',
      ],
    ],
    '#disabled' => !$entity
      ->isNew(),
  ];
  $form['description'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Description'),
    '#default_value' => $entity
      ->get('description'),
  ];
  $providers = $this->providerRepository
    ->getAll();
  $provider_keys = [];
  foreach ($providers as $provider) {
    $provider_keys[$provider
      ->getName()] = $provider
      ->getName();
  }
  $form['markup'] = [
    '#markup' => $this
      ->t('<p>Providers enabled below will be made available to this media source.</p>'),
  ];
  $form['providers'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Allowed Providers'),
    '#default_value' => $entity
      ->get('providers') ? $entity
      ->get('providers') : [],
    '#options' => $provider_keys,
  ];
  $form['#attached']['library'][] = 'oembed_providers/provider_bucket_form';
  return parent::form($form, $form_state);
}