You are here

public function SettingsForm::buildForm in oEmbed 8

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/SettingsForm.php, line 37
Contains \Drupal\oembed\Form\SettingsForm.

Class

SettingsForm

Namespace

Drupal\oembed\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('oembed.settings');
  $periods = array(
    3600,
    10800,
    21600,
    32400,
    43200,
    86400,
    172800,
    259200,
    604800,
    1209600,
    2419200,
    4838400,
    9676800,
  );
  $period = array_map(array(
    \Drupal::service('date.formatter'),
    'formatInterval',
  ), array_combine($periods, $periods));
  $period[CacheBackendInterface::CACHE_PERMANENT] = t('Indefinite');
  $form['cache'] = array(
    '#type' => 'details',
    '#title' => $this
      ->t('Cache'),
    '#open' => TRUE,
    '#tree' => TRUE,
  );
  $form['cache']['lifetime'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Minimum oEmbed cache lifetime'),
    '#options' => $period,
    '#default_value' => $config
      ->get('cache.lifetime'),
    '#description' => $this
      ->t('Cached oEmbed output will not be re-requested until at least this much time has elapsed.'),
  );
  $form['cache']['flush'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Clear oEmbed cache when all Drupal caches are cleared'),
    '#default_value' => $config
      ->get('cache.flush'),
    '#description' => $this
      ->t('Unselect this to retain unexpired cached oEmbed output even when drupal_flush_all_caches() is called. In conjunction with a long %lifetime, this can help reduce costs when using an oEmbed provider service that charges a fee per request.', array(
      '%lifetime' => t('Minimum oEmbed cache lifetime'),
    )),
  );
  return parent::buildForm($form, $form_state);
}