public function AutomatedCropEffect::buildConfigurationForm in Automated Crop 8
Form constructor.
Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.
Parameters
array $form: An associative array containing the initial structure of the plugin form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Return value
array The form structure.
Overrides PluginFormInterface::buildConfigurationForm
File
- src/
Plugin/ ImageEffect/ AutomatedCropEffect.php, line 127
Class
- AutomatedCropEffect
- Provide an Automatic crop tools.
Namespace
Drupal\automated_crop\Plugin\ImageEffectCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['provider'] = [
'#type' => 'select',
'#required' => TRUE,
'#title' => $this
->t('Automated crop provider'),
'#empty_option' => $this
->t("- Select a Provider -"),
'#options' => $this->automatedCropManager
->getProviderOptionsList(),
'#default_value' => $this->configuration['provider'],
'#description' => $this
->t('The name of automated crop provider plugin to use.'),
];
$form['width'] = [
'#type' => 'number',
'#title' => $this
->t('Width'),
'#default_value' => $this->configuration['width'],
'#field_suffix' => ' ' . $this
->t('pixels'),
'#description' => $this
->t("If your sizes W + H not respect original aspect ratio, the system adapt it to ensure you don't deform image."),
];
$form['height'] = [
'#type' => 'number',
'#title' => $this
->t('Height'),
'#default_value' => $this->configuration['height'],
'#field_suffix' => ' ' . $this
->t('pixels'),
'#description' => $this
->t("If your sizes W + H not respect original aspect ratio, the system adapt it to ensure you don't deform image."),
];
$form['min_sizes'] = [
'#type' => 'details',
'#title' => $this
->t('Min sizes limits'),
'#description' => $this
->t('Define crop size minimum limit.'),
'#open' => FALSE,
];
$form['min_sizes']['min_width'] = [
'#type' => 'number',
'#title' => $this
->t('Min Width'),
'#default_value' => $this->configuration['min_width'],
'#field_suffix' => ' ' . $this
->t('pixels'),
];
$form['min_sizes']['min_height'] = [
'#type' => 'number',
'#title' => $this
->t('Min Height'),
'#default_value' => $this->configuration['min_height'],
'#field_suffix' => ' ' . $this
->t('pixels'),
];
$form['max_sizes'] = [
'#type' => 'details',
'#title' => $this
->t('Max sizes limits'),
'#description' => $this
->t('Define crop size maximum limit.'),
'#open' => FALSE,
];
$form['max_sizes']['max_width'] = [
'#type' => 'number',
'#title' => $this
->t('Max Width'),
'#default_value' => $this->configuration['max_width'],
'#field_suffix' => ' ' . $this
->t('pixels'),
];
$form['max_sizes']['max_height'] = [
'#type' => 'number',
'#title' => $this
->t('Max Height'),
'#default_value' => $this->configuration['max_height'],
'#field_suffix' => ' ' . $this
->t('pixels'),
];
$form['aspect_ratio'] = [
'#title' => $this
->t('Aspect Ratio'),
'#type' => 'textfield',
'#default_value' => $this->configuration['aspect_ratio'],
'#attributes' => [
'placeholder' => 'W:H',
],
'#description' => $this
->t('Set an aspect ratio <b>eg: 16:9</b> or leave this empty for arbitrary aspect ratio'),
];
return $form;
}