You are here

public function AllowedProvidersForm::buildForm in oEmbed Providers 1.0.x

Same name and namespace in other branches
  1. 1.1.x src/Form/AllowedProvidersForm.php \Drupal\oembed_providers\Form\AllowedProvidersForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/AllowedProvidersForm.php, line 73

Class

AllowedProvidersForm
Configure allowed providers settings form.

Namespace

Drupal\oembed_providers\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config(static::SETTINGS);
  $form['security_warning'] = [
    '#markup' => HelperTrait::disabledProviderSecurityWarning(),
    // Simulate warning message.
    '#prefix' => '<div role="contentinfo" aria-label="Warning message" class="messages messages--warning">',
    '#suffix' => '</div>',
  ];
  if (empty($config
    ->get('allowed_providers'))) {
    $form['install_markup'] = [
      '#markup' => $this
        ->t('The <em>oEmbed Providers</em> module now manages oEmbed providers. Allowed oEmbed providers must be configured below.'),
      // Simulate warning message.
      '#prefix' => '<div role="contentinfo" aria-label="Warning message" class="messages messages--warning">',
      '#suffix' => '</div>',
    ];
  }
  $form['markup'] = [
    '#markup' => $this
      ->t('<p>Providers enabled below will be made available as media sources.</p>'),
  ];
  $providers = $this->providerRepository
    ->getAll();
  $provider_keys = [];
  foreach ($providers as $provider) {
    $provider_keys[$provider
      ->getName()] = $provider
      ->getName();
  }
  $form['allowed_providers'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Allowed Providers'),
    '#default_value' => $config
      ->get('allowed_providers') ? $config
      ->get('allowed_providers') : [],
    '#options' => $provider_keys,
  ];
  $form['#attached']['library'][] = 'oembed_providers/settings_form';
  return parent::buildForm($form, $form_state);
}