You are here

public function Settings::buildForm in Flickr API Integration 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/Settings.php, line 71

Class

Settings
Implements the Flickr API Settings form controller.

Namespace

Drupal\flickr_api\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('flickr_api.settings');
  $form['credentials'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('OAuth Settings'),
  ];
  $form['credentials']['help'] = [
    '#type' => '#markup',
    '#markup' => $this
      ->t('API Key from Flickr. Get an API Key at @link.', [
      '@link' => Link::fromTextAndUrl('https://www.flickr.com/services/apps/create/apply', Url::fromUri('https://www.flickr.com/services/apps/create/apply'))
        ->toString(),
    ]),
  ];
  $form['credentials']['api_key'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('API Key'),
    '#default_value' => $config
      ->get('api_key'),
  ];
  $form['credentials']['api_secret'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('API key secret'),
    '#default_value' => $config
      ->get('api_secret'),
  ];
  $form['flickr_api'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Flickr API Settings'),
    '#description' => $this
      ->t('The following settings connect Flickr API module with external APIs.'),
  ];
  $form['flickr_api']['host_uri'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Flickr URL'),
    '#default_value' => $config
      ->get('host_uri'),
  ];
  $form['flickr_api']['api_uri'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Flickr API URL'),
    '#default_value' => $config
      ->get('api_uri'),
  ];
  $form['caching'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Flickr API Caching'),
    '#open' => TRUE,
    '#description' => $this
      ->t('API caching is recommended for all websites.'),
  ];

  // Identical options to the ones for block caching.
  // @see \Drupal\Core\Block\BlockBase::buildConfigurationForm()
  $period = [
    0,
    60,
    180,
    300,
    600,
    900,
    1800,
    2700,
    3600,
    10800,
    21600,
    32400,
    43200,
    86400,
  ];
  $period = array_map([
    $this->dateFormatter,
    'formatInterval',
  ], array_combine($period, $period));
  $period[0] = '<' . $this
    ->t('no caching') . '>';
  $form['caching']['api_cache_maximum_age'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('API cache maximum age'),
    '#default_value' => $config
      ->get('api_cache_maximum_age'),
    '#options' => $period,
    '#description' => $this
      ->t('The maximum time a API request can be cached by Drupal.'),
  ];
  return parent::buildForm($form, $form_state);
}