You are here

public function FocalPointImageWidget::settingsForm in Focal Point 8

Returns a form to configure settings for the widget.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form definition for the widget settings.

Overrides ImageWidget::settingsForm

File

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

Class

FocalPointImageWidget
Plugin implementation of the 'image_focal_point' widget.

Namespace

Drupal\focal_point\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $form = parent::settingsForm($form, $form_state);

  // We need a preview image for this widget.
  $form['preview_image_style']['#required'] = TRUE;
  unset($form['preview_image_style']['#empty_option']);

  // @todo Implement https://www.drupal.org/node/2872960
  //   The preview image should not be generated using a focal point effect
  //   and should maintain the aspect ratio of the original image.
  $form['preview_image_style']['#description'] = t($form['preview_image_style']['#description']
    ->getUntranslatedString() . "<br/>Do not choose an image style that alters the aspect ratio of the original image nor an image style that uses a focal point effect.", $form['preview_image_style']['#description']
    ->getArguments(), $form['preview_image_style']['#description']
    ->getOptions());
  $form['preview_link'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display preview link'),
    '#default_value' => $this
      ->getSetting('preview_link'),
    '#weight' => 30,
  ];
  $form['offsets'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Default focal point value'),
    '#default_value' => $this
      ->getSetting('offsets'),
    '#description' => $this
      ->t('Specify the default focal point of this widget in the form "leftoffset,topoffset" where offsets are in percentages. Ex: 25,75.'),
    '#size' => 7,
    '#maxlength' => 7,
    '#element_validate' => [
      [
        $this,
        'validateFocalPointWidget',
      ],
    ],
    '#required' => TRUE,
    '#weight' => 35,
  ];
  return $form;
}