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/FontSelector/Dropdown.php \Drupal\image_effects\Plugin\image_effects\FontSelector\Dropdown::selectionElement()
  2. 8.2 src/Plugin/image_effects/FontSelector/Dropdown.php \Drupal\image_effects\Plugin\image_effects\FontSelector\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 Basic::selectionElement

File

src/Plugin/image_effects/FontSelector/Dropdown.php, line 57

Class

Dropdown
Dropdown font selector plugin.

Namespace

Drupal\image_effects\Plugin\image_effects\FontSelector

Code

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

  // Get list of font names.
  $fonts_list = $this
    ->getList();
  if (empty($fonts_list)) {
    $this->logger
      ->warning('No fonts available. Make sure at least one font is available in the directory specified in the <a href=":url">configuration page</a>.', [
      ':url' => Url::fromRoute('image_effects.settings')
        ->toString(),
    ]);
    return [];
  }

  // 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('Font'),
    '#description' => $this
      ->t('Select a font.'),
    '#options' => $fonts_list,
    '#limit_validation_errors' => FALSE,
    '#required' => TRUE,
    '#element_validate' => [
      [
        $this,
        'validateSelectorUri',
      ],
    ],
  ], $options);
}