You are here

public function BatchWatermarkForm::buildForm in Media watermark 8

Define the form used for ContentEntityExample settings.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: An associative array containing the current state of the form.

Return value

array Form definition array.

Overrides FormInterface::buildForm

File

src/Form/BatchWatermarkForm.php, line 76

Class

BatchWatermarkForm
Class BatchWatermarkForm.

Namespace

Drupal\media_watermark\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Set actions field set.
  $form['actions'] = [
    '#type' => 'fieldset',
    '#collapsed' => FALSE,
    '#collapsible' => FALSE,
  ];
  $form['actions']['search_name'] = [
    '#type' => 'textfield',
    '#title' => t('Enter file name'),
    '#default_value' => !empty($_GET['search']) ? $_GET['search'] : '',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => t('Search'),
    '#submit' => [
      [
        $this,
        'searchRedirect',
      ],
    ],
  ];
  $form['actions']['back'] = [
    '#type' => 'submit',
    '#value' => t('Reset'),
    '#submit' => [
      [
        $this,
        'resetRedirect',
      ],
    ],
  ];

  // Get watermarks.
  $watermarks = MediaWatermark::loadMultiple();
  if (!empty($watermarks)) {
    $names = $this
      ->getWatermarksOptions();
    $form['actions']['watermarks_names'] = [
      '#type' => 'select',
      '#options' => $names,
      '#description' => t('Choose watermark you need in dropdown'),
      '#weight' => 19,
    ];

    // Hide select list if one watermark.
    if (count($watermarks) == 1) {
      $form['actions']['watermarks_names']['#prefix'] = '<div class="hide-select-list">';
      $form['actions']['watermarks_names']['#suffix'] = '</div>';
    }
    $form['actions']['watermarks_images'] = $this
      ->prepareImages($watermarks);
    $form['#attached']['library'][] = 'media_watermark/media_watermark.scripts';
    $this->watermarksFids = array_keys($names);
  }
  $form += $this
    ->getImageFiles();
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => t('Add watermark'),
  ];
  return $form;
}