You are here

public function ImageCropWidget::settingsForm in Image Widget Crop 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/ImageCropWidget.php \Drupal\image_widget_crop\Plugin\Field\FieldWidget\ImageCropWidget::settingsForm()

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/ImageCropWidget.php, line 171

Class

ImageCropWidget
Plugin implementation of the 'image_widget_crop' widget.

Namespace

Drupal\image_widget_crop\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element = parent::settingsForm($form, $form_state);
  $element['crop_preview_image_style'] = [
    '#title' => $this
      ->t('Crop preview image style'),
    '#type' => 'select',
    '#options' => $this->imageWidgetCropManager
      ->getAvailableCropImageStyle(image_style_options(FALSE)),
    '#default_value' => $this
      ->getSetting('crop_preview_image_style'),
    '#description' => $this
      ->t('The preview image will be shown while editing the content.'),
    '#weight' => 15,
  ];
  $element['crop_list'] = [
    '#title' => $this
      ->t('Crop Type'),
    '#type' => 'select',
    '#options' => $this->imageWidgetCropManager
      ->getAvailableCropType(CropType::getCropTypeNames()),
    '#empty_option' => $this
      ->t('<@no-preview>', [
      '@no-preview' => $this
        ->t('no preview'),
    ]),
    '#default_value' => $this
      ->getSetting('crop_list'),
    '#multiple' => TRUE,
    '#required' => TRUE,
    '#description' => $this
      ->t('The type of crop to apply to your image. If your Crop Type not appear here, set an image style use your Crop Type'),
    '#weight' => 16,
  ];
  $element['show_crop_area'] = [
    '#title' => $this
      ->t('Always expand crop area'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('show_crop_area'),
  ];
  $element['show_default_crop'] = [
    '#title' => $this
      ->t('Show default crop area'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('show_default_crop'),
  ];
  $element['warn_multiple_usages'] = [
    '#title' => $this
      ->t('Warn the user if the crop is used more than once.'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('warn_multiple_usages'),
  ];
  return $element;
}