public function ParallaxElementForm::form in Parallax Background 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/ ParallaxElementForm.php, line 18
Class
- ParallaxElementForm
- Class ParallaxElementForm.
Namespace
Drupal\parallax_bg\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
/** @var \Drupal\parallax_bg\Entity\ParallaxElementInterface $parallax_element */
$parallax_element = $this->entity;
$form['selector'] = [
'#type' => 'textfield',
'#title' => $this
->t('Valid jQuery selector'),
'#maxlength' => 255,
'#default_value' => $parallax_element
->getSelector(),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $parallax_element
->id(),
'#machine_name' => [
'exists' => '\\Drupal\\parallax_bg\\Entity\\ParallaxElement::load',
],
'#disabled' => !$parallax_element
->isNew(),
];
$position = $parallax_element
->getPosition();
$form['position'] = [
'#type' => 'select',
'#title' => $this
->t('Position'),
'#default_value' => isset($position) ? $position : '50%',
'#options' => [
'0' => $this
->t('Left'),
'50%' => $this
->t('Center'),
'100%' => $this
->t('Right'),
],
];
$speed = $parallax_element
->getSpeed();
$form['speed'] = [
'#type' => 'select',
'#title' => $this
->t('Relative speed'),
'#default_value' => isset($speed) ? $speed : '0.1',
'#options' => [
'0' => 0,
'0.1' => 0.1,
'0.2' => 0.2,
'0.3' => 0.3,
'0.4' => 0.4,
'0.5' => 0.5,
'0.6' => 0.6,
'0.7' => 0.7,
'0.8' => 0.8,
'0.9' => 0.9,
'1' => 1,
'1.25' => 1.25,
'1.5' => 1.5,
'1.75' => 1.75,
'2' => 2,
'2.5' => 2.5,
'3' => 3,
],
];
return $form;
}