public function CropWidgetForm::buildForm in Image Widget Crop 8.2
Same name and namespace in other branches
- 8 src/Form/CropWidgetForm.php \Drupal\image_widget_crop\Form\CropWidgetForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ CropWidgetForm.php, line 99
Class
- CropWidgetForm
- Configure ImageWidgetCrop general settings for this site.
Namespace
Drupal\image_widget_crop\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$url = 'https://cdnjs.com/libraries/cropper';
$cdn_js = IMAGE_WIDGET_CROP_JS_CDN;
$cdn_css = IMAGE_WIDGET_CROP_CSS_CDN;
$form['library'] = [
'#type' => 'details',
'#title' => $this
->t('Cropper library settings'),
'#description' => $this
->t('Changes here require a cache rebuild to take full effect.'),
];
$form['library']['library_url'] = [
'#type' => 'textfield',
'#title' => $this
->t('Custom Cropper library'),
'#description' => $this
->t('Set the URL or local path for the file, or leave empty to use the installed library (if present) or a <a href="@file">CDN</a> fallback. You can retrieve the library file from <a href="@url">Cropper CDN</a>.', [
'@url' => $url,
'@file' => $cdn_js,
]),
'#default_value' => $this->settings
->get('settings.library_url'),
];
$form['library']['css_url'] = [
'#type' => 'textfield',
'#title' => $this
->t('Custom Cropper CSS file'),
'#description' => $this
->t('Set the URL or local path for the file, or leave empty to use installed library (if installed) or a <a href="@file">CDN</a> fallback. You can retrieve the CSS file from <a href="@url">Cropper CDN</a>.', [
'@url' => $url,
'@file' => $cdn_css,
]),
'#default_value' => $this->settings
->get('settings.css_url'),
];
// Indicate which files are used when custom urls are not set.
if ($this->moduleHandler
->moduleExists('libraries') && ($info = libraries_detect('cropper')) && $info['installed']) {
$form['library']['library_url']['#attributes']['placeholder'] = $info['library path'] . '/dist/' . key($info['files']['js']);
$form['library']['css_url']['#attributes']['placeholder'] = $info['library path'] . '/dist/' . key($info['files']['css']);
}
else {
$form['library']['library_url']['#attributes']['placeholder'] = $cdn_js;
$form['library']['css_url']['#attributes']['placeholder'] = $cdn_css;
}
$form['image_crop'] = [
'#type' => 'details',
'#title' => $this
->t('General configuration'),
];
$form['image_crop']['crop_preview_image_style'] = [
'#title' => $this
->t('Crop preview image style'),
'#type' => 'select',
'#options' => image_style_options(FALSE),
'#default_value' => $this->settings
->get('settings.crop_preview_image_style'),
'#description' => $this
->t('The preview image will be shown while editing the content.'),
'#weight' => 15,
];
$form['image_crop']['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->settings
->get('settings.crop_list'),
'#multiple' => 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,
];
$form['image_crop']['show_crop_area'] = [
'#title' => $this
->t('Always expand crop area'),
'#type' => 'checkbox',
'#default_value' => $this->settings
->get('settings.show_crop_area'),
];
$form['image_crop']['warn_multiple_usages'] = [
'#title' => $this
->t('Warn user when a file have multiple usages'),
'#type' => 'checkbox',
'#default_value' => $this->settings
->get('settings.warn_multiple_usages'),
];
$form['image_crop']['show_default_crop'] = [
'#title' => $this
->t('Show default crop area'),
'#type' => 'checkbox',
'#default_value' => $this->settings
->get('settings.show_default_crop'),
];
$form['image_crop']['crop_types_required'] = [
'#title' => $this
->t('Set Crop Type as required'),
'#type' => 'select',
'#options' => $this->imageWidgetCropManager
->getAvailableCropType(CropType::getCropTypeNames()),
'#empty_option' => $this
->t("- Any crop selected -"),
'#default_value' => $this->settings
->get('settings.crop_types_required'),
'#multiple' => TRUE,
'#description' => $this
->t('Set active crop as required.'),
'#weight' => 16,
];
$form['image_crop']['notify'] = [
'#type' => 'details',
'#title' => $this
->t('Cropping Notifications'),
];
$form['image_crop']['notify']['notify_apply'] = [
'#title' => $this
->t('Crop apply'),
'#type' => 'checkbox',
'#default_value' => $this->settings
->get('settings.notify_apply'),
];
$form['image_crop']['notify']['notify_update'] = [
'#title' => $this
->t('Crop update'),
'#type' => 'checkbox',
'#default_value' => $this->settings
->get('settings.notify_update'),
];
return parent::buildForm($form, $form_state);
}