class SliderProForm in Slider Pro 8
Class SliderProForm @package Drupal\slider_pro\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
- class \Drupal\slider_pro\Form\SliderProForm
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
Expanded class hierarchy of SliderProForm
File
- src/
Form/ SliderProForm.php, line 14
Namespace
Drupal\slider_pro\FormView source
class SliderProForm extends EntityForm {
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
/** @var \Drupal\slider_pro\Entity\SliderProInterface $slider_pro */
$slider_pro = $this->entity;
$options = array_merge(SliderProDefaults::defaultOptions(), $slider_pro
->getOptions());
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $slider_pro
->label(),
'#description' => $this
->t('A human-readable title for this option set.'),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $slider_pro
->id(),
'#machine_name' => [
'exists' => '\\Drupal\\slider_pro\\Entity\\SliderPro::load',
],
'#disabled' => !$slider_pro
->isNew(),
];
// Options Vertical Tab Group table.
$form['tabs'] = [
'#type' => 'vertical_tabs',
];
// General Settings.
$form['general'] = [
'#type' => 'details',
'#title' => $this
->t('General Settings'),
'#group' => 'tabs',
'#open' => TRUE,
];
$form['general']['width'] = [
'#type' => 'textfield',
'#title' => $this
->t('Width'),
'#description' => 'The width of the slider. Eg 200px or 50%',
'#default_value' => $options['width'],
'#required' => TRUE,
];
$form['general']['visible_size'] = [
'#type' => 'textfield',
'#title' => $this
->t('Visible size'),
'#description' => 'Sets the size (for example 100%) of the visible area, allowing for more slides to become visible near the selected slide. Be sure that the width of your slider is less than 100%. Example',
'#default_value' => $options['visible_size'],
'#required' => TRUE,
];
$form['general']['force_size'] = [
'#type' => 'select',
'#title' => $this
->t('Force size'),
'#options' => [
'none' => $this
->t('None'),
'fullWidth' => $this
->t('Full width'),
'fullWindow' => $this
->t('Full window'),
],
'#default_value' => $options['force_size'],
'#description' => $this
->t('Indicates if the size of the slider will be forced to full width or full window.'),
'#required' => TRUE,
];
$form['general']['height'] = [
'#type' => 'textfield',
'#title' => $this
->t('Height'),
'#default_value' => $options['height'],
'#description' => 'The height of the slider. Eg 200px or 50%',
];
$form['general']['orientation'] = [
'#type' => 'select',
'#title' => $this
->t('Orientation'),
'#options' => [
'horizontal' => $this
->t('Horizontal'),
'vertical' => $this
->t('Vertical'),
],
'#default_value' => $options['orientation'],
'#description' => $this
->t('Indicates whether the slides will be arranged horizontally or vertically.'),
'#required' => TRUE,
];
$form['general']['buttons'] = [
'#type' => 'select',
'#title' => $this
->t('Buttons'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['buttons'],
'#description' => $this
->t('Indicates whether the buttons will be created.'),
'#required' => TRUE,
];
$form['general']['transition'] = [
'#type' => 'select',
'#title' => $this
->t('Transition'),
'#options' => [
0 => $this
->t('Slide'),
1 => $this
->t('Fade'),
],
'#default_value' => $options['transition'],
'#description' => $this
->t('Indicates which transition will be used.'),
'#required' => TRUE,
];
$form['general']['arrows'] = [
'#type' => 'select',
'#title' => $this
->t('Arrows'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['arrows'],
'#description' => $this
->t('Indicates whether the arrow buttons will be created.'),
'#required' => TRUE,
];
// Thumbnail Settings.
$form['thumbnails'] = [
'#type' => 'details',
'#title' => $this
->t('Thumbnail Settings'),
'#group' => 'tabs',
'#open' => FALSE,
];
$form['thumbnails']['thumbnail_position'] = [
'#type' => 'select',
'#title' => $this
->t('Position'),
'#options' => [
0 => $this
->t('No thumbs'),
'left' => $this
->t('Left'),
'right' => $this
->t('Right'),
'top' => $this
->t('Top'),
'bottom' => $this
->t('Bottom'),
],
'#default_value' => $options['thumbnail_position'],
'#required' => TRUE,
'#description' => $this
->t('Sets the position of the thumbnail scroller.'),
];
$form['thumbnails']['thumbnail_width'] = [
'#type' => 'number',
'#title' => $this
->t('Width'),
'#description' => $this
->t('The width of each thumbnail. Eg 200px.'),
'#default_value' => $options['thumbnail_width'],
'#required' => TRUE,
'#states' => [
'invisible' => [
'select[name="thumbnail_position"]' => [
'value' => '0',
],
],
],
];
$form['thumbnails']['thumbnail_height'] = [
'#type' => 'number',
'#title' => $this
->t('height'),
'#description' => $this
->t('The height of each thumbnail. Eg 200px.'),
'#default_value' => $options['thumbnail_height'],
'#required' => TRUE,
'#states' => [
'invisible' => [
'select[name="thumbnail_position"]' => [
'value' => '0',
],
],
],
];
$form['thumbnails']['thumbnail_pointer'] = [
'#type' => 'select',
'#title' => $this
->t('Pointer'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['thumbnail_pointer'],
'#required' => TRUE,
'#description' => $this
->t('Indicates if a pointer will be displayed for the selected thumbnail.'),
'#states' => [
'invisible' => [
'select[name="thumbnail_position"]' => [
'value' => '0',
],
],
],
];
$form['thumbnails']['thumbnail_arrows'] = [
'#type' => 'select',
'#title' => $this
->t('Arrows'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['thumbnail_arrows'],
'#required' => TRUE,
'#description' => $this
->t('Indicates whether the thumbnail arrows will be enabled.'),
'#states' => [
'invisible' => [
'select[name="thumbnail_position"]' => [
'value' => '0',
],
],
],
];
$form['thumbnails']['fade_thumbnail_arrows'] = [
'#type' => 'select',
'#title' => $this
->t('Fade arrows'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['fade_thumbnail_arrows'],
'#required' => TRUE,
'#description' => $this
->t('Indicates whether the thumbnail arrows will be faded.'),
'#states' => [
'invisible' => [
[
'select[name="thumbnail_position"]' => [
'value' => '0',
],
],
[
'select[name="thumbnail_arrows"]' => [
'value' => '0',
],
],
],
],
];
// Layer Settings.
$form['layers'] = [
'#type' => 'details',
'#title' => $this
->t('Layer Settings'),
'#group' => 'tabs',
'#open' => FALSE,
];
$form['layers']['wait_for_layers'] = [
'#type' => 'select',
'#title' => $this
->t('Wait for layers'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['wait_for_layers'],
'#description' => $this
->t('Indicates whether the slider will wait for the layers to disappear before going to a new slide.'),
];
$form['layers']['auto_scale_layers'] = [
'#type' => 'select',
'#title' => $this
->t('Auto scale layers'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['auto_scale_layers'],
'#description' => $this
->t('Indicates whether the layers will be scaled automatically.'),
];
// Advanced Settings.
$form['advanced'] = [
'#type' => 'details',
'#title' => $this
->t('Advanced Settings'),
'#group' => 'tabs',
'#open' => FALSE,
];
$form['advanced']['center_image'] = [
'#type' => 'select',
'#title' => $this
->t('Center image'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['center_image'],
'#description' => $this
->t('Indicates if the image will be centered.'),
'#required' => TRUE,
];
$form['advanced']['allow_scale_up'] = [
'#type' => 'select',
'#title' => $this
->t('Allow scale up'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['allow_scale_up'],
'#description' => $this
->t('Indicates if the image can be scaled up more than its original size.'),
'#required' => TRUE,
];
$form['advanced']['auto_height'] = [
'#type' => 'select',
'#title' => $this
->t('Auto height'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['auto_height'],
'#description' => $this
->t('Indicates if height of the slider will be adjusted to the height of the selected slide.'),
'#required' => TRUE,
];
$form['advanced']['slide_distance'] = [
'#type' => 'number',
'#title' => $this
->t('Slide distance'),
'#default_value' => $options['slide_distance'],
'#description' => $this
->t('Sets the distance between the slides.'),
'#required' => TRUE,
];
$form['advanced']['start_slide'] = [
'#type' => 'number',
'#title' => $this
->t('Start slide'),
'#default_value' => $options['start_slide'],
'#description' => $this
->t('Sets the slide that will be selected when the slider loads.'),
'#required' => TRUE,
];
$form['advanced']['shuffle'] = [
'#type' => 'select',
'#title' => $this
->t('Shuffle'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['shuffle'],
'#description' => $this
->t('Indicates if the slides will be shuffled.'),
'#required' => TRUE,
];
$form['advanced']['loop'] = [
'#type' => 'select',
'#title' => $this
->t('Loop'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['loop'],
'#description' => $this
->t('Indicates if the slider will be loopable (infinite scrolling).'),
'#required' => TRUE,
];
$form['advanced']['autoplay'] = [
'#type' => 'select',
'#title' => $this
->t('Autoplay'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['autoplay'],
'#description' => $this
->t('Indicates whether or not autoplay will be enabled.'),
'#required' => TRUE,
];
$form['advanced']['autoplay_delay'] = [
'#type' => 'number',
'#title' => $this
->t('Autoplay delay'),
'#default_value' => $options['autoplay_delay'],
'#description' => $this
->t('Sets the delay/interval (in milliseconds) at which the autoplay will run.'),
'#required' => TRUE,
'#states' => [
'visible' => [
'select[name="autoplay"]' => [
'value' => '1',
],
],
],
];
$form['advanced']['autoplay_direction'] = [
'#type' => 'select',
'#title' => $this
->t('Autoplay direction'),
'#options' => [
'normal' => $this
->t('Normal'),
'backwards' => $this
->t('Backwards'),
],
'#default_value' => $options['autoplay_direction'],
'#description' => $this
->t('Indicates whether autoplay will navigate to the next slide or previous slide.'),
'#required' => TRUE,
'#states' => [
'visible' => [
'select[name="autoplay"]' => [
'value' => '1',
],
],
],
];
$form['advanced']['autoplay_on_hover'] = [
'#type' => 'select',
'#title' => $this
->t('Autoplay on hover'),
'#options' => [
'pause' => $this
->t('Pause'),
'stop' => $this
->t('Stop'),
'none' => $this
->t('None'),
],
'#default_value' => $options['autoplay_on_hover'],
'#description' => $this
->t('Indicates if the autoplay will be paused or stopped when the slider is hovered.'),
'#required' => TRUE,
'#states' => [
'visible' => [
'select[name="autoplay"]' => [
'value' => '1',
],
],
],
];
$form['advanced']['keyboard'] = [
'#type' => 'select',
'#title' => $this
->t('Keyboard'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['keyboard'],
'#description' => $this
->t('Indicates whether keyboard navigation will be enabled.'),
'#required' => TRUE,
];
$form['advanced']['full_screen'] = [
'#type' => 'select',
'#title' => $this
->t('Full screen'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['full_screen'],
'#description' => $this
->t('Indicates whether the full-screen button is enabled.'),
'#required' => TRUE,
];
$form['advanced']['fade_full_screen'] = [
'#type' => 'select',
'#title' => $this
->t('Fade full screen'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['fade_full_screen'],
'#description' => $this
->t('Indicates whether the button will fade in only on hover.'),
'#required' => TRUE,
'#states' => [
'visible' => [
'select[name="full_screen"]' => [
'value' => '1',
],
],
],
];
$form['advanced']['update_hash'] = [
'#type' => 'select',
'#title' => $this
->t('Update hash'),
'#options' => [
0 => $this
->t('No'),
1 => $this
->t('Yes'),
],
'#default_value' => $options['update_hash'],
'#description' => $this
->t('Indicates whether the hash will be updated when a new slide is selected.'),
'#required' => TRUE,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
/** @var \Drupal\slider_pro\SliderProInterface $slider_pro */
$slider_pro = $this->entity;
$status = parent::save($form, $form_state);
switch ($status) {
case SAVED_NEW:
drupal_set_message($this
->t('Created the %label Slider Pro optionset.', [
'%label' => $slider_pro
->label(),
]));
break;
default:
drupal_set_message($this
->t('Saved the %label Slider Pro optionset.', [
'%label' => $slider_pro
->label(),
]));
}
$form_state
->setRedirectUrl($slider_pro
->toUrl('collection'));
}
/**
* {@inheritdoc}
*/
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
$options = [];
$values = $form_state
->getValues();
foreach ($values as $key => $value) {
if (in_array($key, [
'id',
'label',
])) {
$entity
->set($key, $value);
}
else {
$options[$key] = $value;
}
}
$entity
->set('options', $options);
}
/**
* {@inheritdoc}
*/
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
// Prevent access to delete button when editing default configuration.
if ($this->entity
->id() == 'default' && isset($actions['delete'])) {
$actions['delete']['#access'] = FALSE;
}
return $actions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityForm:: |
protected | property | The entity being used by this form. | 7 |
EntityForm:: |
protected | property | The entity type manager. | 3 |
EntityForm:: |
protected | property | The module handler service. | |
EntityForm:: |
protected | property | The name of the current operation. | |
EntityForm:: |
private | property | The entity manager. | |
EntityForm:: |
protected | function | Returns the action form element for the current entity form. | |
EntityForm:: |
public | function | Form element #after_build callback: Updates the entity with submitted data. | |
EntityForm:: |
public | function |
Builds an updated entity object based upon the submitted form values. Overrides EntityFormInterface:: |
2 |
EntityForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
10 |
EntityForm:: |
public | function |
Returns a string identifying the base form. Overrides BaseFormIdInterface:: |
5 |
EntityForm:: |
public | function |
Gets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Determines which entity will be used by this form from a RouteMatch object. Overrides EntityFormInterface:: |
1 |
EntityForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
10 |
EntityForm:: |
public | function |
Gets the operation identifying the form. Overrides EntityFormInterface:: |
|
EntityForm:: |
protected | function | Initialize the form state and the entity before the first form build. | 3 |
EntityForm:: |
protected | function | Prepares the entity object before the form is built first. | 3 |
EntityForm:: |
protected | function | Invokes the specified prepare hook variant. | |
EntityForm:: |
public | function | Process callback: assigns weights and hides extra fields. | |
EntityForm:: |
public | function |
Sets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity manager for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity type manager for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the module handler for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the operation for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
This is the default entity object builder function. It is called before any
other submit handler to build the new entity object to be used by the
following submit handlers. At this point of the form workflow the entity is
validated and the form state… Overrides FormInterface:: |
17 |
EntityForm:: |
public | function | ||
EntityForm:: |
public | function | ||
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
87 |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
SliderProForm:: |
protected | function |
Returns an array of supported actions for the current entity form. Overrides EntityForm:: |
|
SliderProForm:: |
protected | function |
Copies top-level form values to entity properties Overrides EntityForm:: |
|
SliderProForm:: |
public | function |
Gets the actual form array to be built. Overrides EntityForm:: |
|
SliderProForm:: |
public | function |
Form submission handler for the 'save' action. Overrides EntityForm:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |