You are here

protected function RemoteImageItem::defaultImageForm in Remote image 8

Builds the default_image details element.

Parameters

array $element: The form associative array passed by reference.

array $settings: The field settings array.

File

src/Plugin/Field/FieldType/RemoteImageItem.php, line 105
Contains Drupal\remote_image\Plugin\Field\FieldType\RemoteImageField.

Class

RemoteImageItem
Plugin implementation of the 'remote_image' field type.

Namespace

Drupal\remote_image\Plugin\Field\FieldType

Code

protected function defaultImageForm(array &$element, array $settings) {

  // Add the default image form element.
  // @todo Add url validation @see \Drupal\link\Plugin\Field\FieldWidget\LinkWidget.
  // @todo Add autocomplete for internal urls @see \Drupal\link\Plugin\Field\FieldWidget\LinkWidget.
  // @todo Figure out why default width and height won't save.
  $element['default_image'] = [
    '#type' => 'details',
    '#title' => t('Default image'),
    '#open' => TRUE,
    'uri' => [
      '#type' => 'url',
      '#title' => $this
        ->t('Default image URL'),
      '#default_value' => $settings['default_image']['uri'],
      '#maxlength' => 2048,
      '#description' => $this
        ->t('The URL of the remote image.'),
    ],
    'alt' => [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Alternative text'),
      '#description' => $this
        ->t('This text will be used by screen readers, search engines, and when the image cannot be loaded.'),
      '#default_value' => $settings['default_image']['alt'],
      '#maxlength' => 512,
    ],
    'title' => [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Title'),
      '#description' => t('The title attribute is used as a tooltip when the mouse hovers over the image.'),
      '#default_value' => $settings['default_image']['title'],
      '#maxlength' => 1024,
    ],
    'width' => [
      '#type' => 'number',
      '#title' => $this
        ->t('Width'),
      '#description' => t('The width of the image'),
      '#value' => $settings['default_image']['width'],
    ],
    'height' => [
      '#type' => 'number',
      '#title' => $this
        ->t('Height'),
      '#description' => t('The height of the image.'),
      '#value' => $settings['default_image']['height'],
    ],
  ];
}