You are here

private static function FocalPointImageWidget::createPreviewLink in Focal Point 8

Create the preview link form element.

Parameters

int $fid: The fid of the image file.

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::createPreviewLink()
FocalPointImageWidget::process in src/Plugin/Field/FieldWidget/FocalPointImageWidget.php
Processes an image_focal_point field Widget.

File

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

Class

FocalPointImageWidget
Plugin implementation of the 'image_focal_point' widget.

Namespace

Drupal\focal_point\Plugin\Field\FieldWidget

Code

private static function createPreviewLink($fid, $field_name, array $element_selectors, $default_focal_point_value) {

  // Replace comma (,) with an x to make javascript handling easier.
  $preview_focal_point_value = str_replace(',', 'x', $default_focal_point_value);

  // Create a token to be used during an access check on the preview page.
  $token = self::getPreviewToken();
  $preview_link = [
    '#type' => 'link',
    '#title' => new TranslatableMarkup('Preview'),
    '#url' => new Url('focal_point.preview', [
      'fid' => $fid,
      'focal_point_value' => $preview_focal_point_value,
    ], [
      'query' => [
        'focal_point_token' => $token,
      ],
    ]),
    '#attached' => [
      'library' => [
        'core/drupal.dialog.ajax',
      ],
    ],
    '#attributes' => [
      'class' => [
        'focal-point-preview-link',
        'use-ajax',
      ],
      'data-selector' => $element_selectors['focal_point'],
      'data-field-name' => $field_name,
      'data-dialog-type' => 'modal',
      'target' => '_blank',
    ],
  ];
  return $preview_link;
}