You are here

public function SettingsForm::buildForm in Imagecache External 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 76

Class

SettingsForm
Defines a form that configures uploadcare settings.

Namespace

Drupal\imagecache_external\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('imagecache_external.settings');
  $form['imagecache_directory'] = [
    '#type' => 'textfield',
    '#title' => t('Imagecache Directory'),
    '#required' => TRUE,
    '#description' => t('Where, within the files directory, should the downloaded images be stored?'),
    '#default_value' => $config
      ->get('imagecache_directory'),
    '#validate' => '::validateForm',
  ];
  $form['imagecache_default_extension'] = [
    '#type' => 'select',
    '#options' => [
      '' => 'none',
      '.jpg' => 'jpg',
      '.png' => 'png',
      '.gif' => 'gif',
      '.jpeg' => 'jpeg',
    ],
    '#title' => t('Imagecache default extension'),
    '#required' => FALSE,
    '#description' => t('If no extension is provided by the external host, specify a default extension'),
    '#default_value' => $config
      ->get('imagecache_default_extension'),
  ];
  $form['imagecache_external_management'] = [
    '#type' => 'radios',
    '#title' => t('How should Drupal handle the files?'),
    '#description' => t('Managed files can be re-used elsewhere on the site, for instance in the Media Library if you use the Media module. Unmanaged files are not saved to the database, but can be cached using Image Styles.'),
    '#options' => [
      'unmanaged' => t('Unmanaged: Only save the images to the files folder to be able to cache them. This is  default.'),
      'managed' => t('Managed: Download the images and save its metadata to the database.'),
    ],
    '#default_value' => $config
      ->get('imagecache_external_management'),
  ];
  $form['imagecache_external_use_whitelist'] = [
    '#type' => 'checkbox',
    '#title' => t('Use whitelist'),
    '#description' => t('By default, all images are blocked except for images served from white-listed hosts. You can define hosts below.'),
    '#default_value' => $config
      ->get('imagecache_external_use_whitelist'),
  ];
  $form['imagecache_external_hosts'] = [
    '#type' => 'textarea',
    '#title' => t('Imagecache External hosts'),
    '#description' => t('Add one host per line. You can use top-level domains to whitelist subdomains. Ex: staticflickr.com to whitelist farm1.staticflickr.com and farm2.staticflickr.com'),
    '#default_value' => $config
      ->get('imagecache_external_hosts'),
    '#states' => [
      'visible' => [
        ':input[name="imagecache_external_use_whitelist"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['imagecache_fallback_image'] = [
    '#type' => 'managed_file',
    '#name' => 'imagecache_fallback_image',
    '#title' => t('Fallback image'),
    '#description' => t("When an external image couldn't be found, use this image as a fallback."),
    '#default_value' => $config
      ->get('imagecache_fallback_image'),
    '#upload_location' => 'public://',
  ];
  $form['imagecache_external_cron_flush_frequency'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Cron cache flush frequency'),
    '#description' => $this
      ->t('The flush frequency, represented as the number of days, for flushing cached images during cron. Enter 0 to disable cron flushing.'),
    '#field_suffix' => $this
      ->t('number of days'),
    '#default_value' => $config
      ->get('imagecache_external_cron_flush_frequency', 0),
    '#min' => 0,
    '#required' => TRUE,
  ];
  $form['#validate'][] = '::validateForm';
  return parent::buildForm($form, $form_state);
}