public function MediaWatermarkForm::form in Media watermark 8
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ MediaWatermarkForm.php, line 43
Class
- MediaWatermarkForm
- Class MediaWatermarkForm.
Namespace
Drupal\media_watermark\FormCode
public function form(array $form, FormStateInterface $form_state) {
$media_watermark = $this->entity;
$is_new = $media_watermark
->isNew();
$form = parent::form($form, $form_state);
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $media_watermark
->label(),
'#description' => $this
->t("Media Watermark Label."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $media_watermark
->id(),
'#machine_name' => [
'exists' => [
$this,
'exist',
],
],
'#disabled' => !$is_new,
];
$form['fid'] = [
'#type' => 'managed_file',
'#title' => t('Watermark image'),
'#upload_location' => 'public://watermark',
'#upload_validators' => [
'file_validate_extensions' => [
'png gif',
],
],
'#description' => t('allowed files extensions are .png and .gif'),
'#required' => TRUE,
'#default_value' => $is_new ? '' : $media_watermark
->getFid(),
];
$form['horizontalPosition'] = [
'#type' => 'select',
'#title' => t('Horizontal position of watermark'),
'#options' => [
'left' => t('left'),
'middle' => t('middle'),
'right' => t('right'),
],
'#default_value' => $is_new ? 'left' : $media_watermark
->getHorizontalPosition(),
'#required' => TRUE,
];
$form['verticalPosition'] = [
'#type' => 'select',
'#title' => t('Vertical position of watermark'),
'#options' => [
'top' => t('top'),
'center' => t('center'),
'bottom' => t('bottom'),
],
'#default_value' => $is_new ? 'bottom' : $media_watermark
->getVerticalPosition(),
'#required' => TRUE,
];
$form['horizontalMargin'] = [
'#type' => 'textfield',
'#title' => t('Horizontal margin, px'),
'#default_value' => $is_new ? '0' : $media_watermark
->getHorizontalMargin(),
'#description' => t('Set minus or plus signed value for moving watermark to left or right from defined position.'),
'#required' => TRUE,
];
$form['verticalMargin'] = [
'#type' => 'textfield',
'#title' => t('Vertical margin, px'),
'#default_value' => $is_new ? '0' : $media_watermark
->getVerticalMargin(),
'#description' => t('Set minus or plus signed value for moving watermark to higher or lower from defined position.'),
'#required' => TRUE,
];
// You will need additional form elements for your custom properties.
return $form;
}