You are here

public function Dropdown::selectionElement in Image Effects 8.3

Same name in this branch
  1. 8.3 src/Plugin/image_effects/FontSelector/Dropdown.php \Drupal\image_effects\Plugin\image_effects\FontSelector\Dropdown::selectionElement()
  2. 8.3 src/Plugin/image_effects/ImageSelector/Dropdown.php \Drupal\image_effects\Plugin\image_effects\ImageSelector\Dropdown::selectionElement()
Same name and namespace in other branches
  1. 8 src/Plugin/image_effects/ImageSelector/Dropdown.php \Drupal\image_effects\Plugin\image_effects\ImageSelector\Dropdown::selectionElement()
  2. 8.2 src/Plugin/image_effects/ImageSelector/Dropdown.php \Drupal\image_effects\Plugin\image_effects\ImageSelector\Dropdown::selectionElement()

Return a form element to select the plugin content.

Parameters

array $options: (Optional) An array of additional Form API keys and values.

Return value

array Render array of the form element.

Overrides ImageEffectsPluginBase::selectionElement

File

src/Plugin/image_effects/ImageSelector/Dropdown.php, line 116

Class

Dropdown
Dropdown image selector plugin.

Namespace

Drupal\image_effects\Plugin\image_effects\ImageSelector

Code

public function selectionElement(array $options = []) {

  // Get list of images.
  $image_files = $this
    ->getList();
  if (empty($image_files)) {
    $this->messenger
      ->addWarning($this
      ->t('No images available. Make sure at least one image is available in the directory specified in the <a href=":url">configuration page</a>.', [
      ':url' => Url::fromRoute('image_effects.settings')
        ->toString(),
    ]));
  }

  // Strip the path from the URI.
  $options['#default_value'] = isset($options['#default_value']) ? pathinfo($options['#default_value'], PATHINFO_BASENAME) : '';

  // Element.
  return array_merge([
    '#type' => 'select',
    '#title' => $this
      ->t('Image'),
    '#description' => $this
      ->t('Select an image.'),
    '#options' => array_combine($image_files, $image_files),
    '#element_validate' => [
      [
        $this,
        'validateSelectorUri',
      ],
    ],
  ], $options);
}