You are here

public function SettingsForm::buildForm in TinyPNG 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 33

Class

SettingsForm
Defines a form that configures forms module settings.

Namespace

Drupal\tinypng\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
  $config = $this
    ->config('tinypng.settings');
  $form['api_key'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('API Key'),
    '#default_value' => $config
      ->get('api_key'),
    '#required' => TRUE,
  ];
  $form['on_upload'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Compress on upload'),
    '#default_value' => $config
      ->get('on_upload'),
    '#description' => $this
      ->t('Enable this if you want to compress every uploaded image.'),
  ];
  $form['upload_method'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Integration Method'),
    '#default_value' => $config
      ->get('upload_method'),
    '#options' => [
      'download' => $this
        ->t('Download', [], [
        'context' => 'tinypng',
      ]),
      'upload' => $this
        ->t('Upload', [], [
        'context' => 'tinypng',
      ]),
    ],
    '#states' => [
      'visible' => [
        '[data-drupal-selector="edit-on-upload"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
    '#description' => $this
      ->t('The download method requires that your site is hosted
       in a server accessible through the internet. The upload method is required
       on localhost.'),
  ];
  $form['image_action'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable TinyPNG image action'),
    '#default_value' => $config
      ->get('image_action'),
    '#description' => $this
      ->t('Define the TinyPNG image action that you can add to any of your image styles.'),
  ];
  return parent::buildForm($form, $form_state);
}