You are here

private static function FocalPointImageWidget::createFocalPointField in Focal Point 8

Create the focal point form element.

Parameters

string $field_name: The name of the field element for the image field.

array $element_selectors: The element selectors to ultimately be used by javascript.

string $default_focal_point_value: The default focal point value in the form x,y.

Return value

array The preview link form element.

1 call to FocalPointImageWidget::createFocalPointField()
FocalPointImageWidget::process in src/Plugin/Field/FieldWidget/FocalPointImageWidget.php
Processes an image_focal_point field Widget.

File

src/Plugin/Field/FieldWidget/FocalPointImageWidget.php, line 262

Class

FocalPointImageWidget
Plugin implementation of the 'image_focal_point' widget.

Namespace

Drupal\focal_point\Plugin\Field\FieldWidget

Code

private static function createFocalPointField($field_name, array $element_selectors, $default_focal_point_value) {
  $field = [
    '#type' => 'textfield',
    '#title' => new TranslatableMarkup('Focal point'),
    '#description' => new TranslatableMarkup('Specify the focus of this image in the form "leftoffset,topoffset" where offsets are in percents. Ex: 25,75'),
    '#default_value' => $default_focal_point_value,
    '#element_validate' => [
      [
        static::class,
        'validateFocalPoint',
      ],
    ],
    '#attributes' => [
      'class' => [
        'focal-point',
        $element_selectors['focal_point'],
      ],
      'data-selector' => $element_selectors['focal_point'],
      'data-field-name' => $field_name,
    ],
    '#wrapper_attributes' => [
      'class' => [
        'focal-point-wrapper',
      ],
    ],
    '#attached' => [
      'library' => [
        'focal_point/drupal.focal_point',
      ],
    ],
  ];
  return $field;
}