class FlickityGroupForm in Flickity Carousel 8
Same name and namespace in other branches
- 8.2 src/Form/FlickityGroupForm.php \Drupal\flickity\Form\FlickityGroupForm
- 3.0.x src/Form/FlickityGroupForm.php \Drupal\flickity\Form\FlickityGroupForm
Form controller for the group entity add/edit forms.
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\flickity\Form\FlickityGroupForm
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
Expanded class hierarchy of FlickityGroupForm
File
- src/
Form/ FlickityGroupForm.php, line 17 - Contains \Drupal\flickity\Form\FlickityGroupForm.
Namespace
Drupal\flickity\FormView source
class FlickityGroupForm extends EntityForm {
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
$group = FlickityGroup::load('default_group');
$settings = $group
->getSettings();
if ($entity
->getSettings()) {
$settings = $entity
->getSettings();
}
$form['label'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Group name'),
'#default_value' => $entity
->label(),
'#size' => 30,
'#required' => TRUE,
'#maxlength' => 64,
'#description' => $this
->t('The settings group identifier.'),
);
$form['id'] = array(
'#type' => 'machine_name',
'#default_value' => $entity
->id(),
'#required' => TRUE,
'#disabled' => !$entity
->isNew(),
'#size' => 30,
'#maxlength' => 64,
'#machine_name' => array(
'exists' => [
'\\Drupal\\flickity\\Entity\\FlickityGroup',
'load',
],
),
);
// Setup
$form['images_loaded'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('imagesLoaded'),
'#default_value' => $settings['images_loaded'],
'#description' => $this
->t('Unloaded images have no size, which can throw off cell positions. To fix this, the imagesLoaded option re-positions cells once their images have loaded.'),
);
$form['cell_selector'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Cell selector'),
'#default_value' => $settings['cell_selector'],
'#size' => 30,
'#description' => $this
->t('Specify selector for cell elements. This is useful if you have other elements in your gallery elements that are not cells.'),
);
$form['initial_index'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Initial index'),
'#default_value' => $settings['initial_index'],
'#size' => 30,
'#description' => $this
->t('Zero-based index of the initial selected cell.'),
);
$form['accessibility'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Accessibility'),
'#default_value' => $settings['accessibility'],
'#description' => $this
->t('Enable keyboard navigation. Users can tab to a Flickity gallery, and pressing left & right keys to change cells.'),
);
$form['set_gallery_size'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Set gallery size'),
'#default_value' => $settings['set_gallery_size'],
'#description' => $this
->t('Sets the height of the gallery to the height of the tallest cell.'),
);
$form['resize'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Resize'),
'#default_value' => $settings['resize'],
'#description' => $this
->t('Adjusts sizes and positions when window is resized.'),
);
// Cell position
$form['cell_align'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Cell align'),
'#default_value' => $settings['cell_align'],
'#size' => 30,
'#description' => $this
->t('Align cells within the gallery element.'),
);
$form['contain'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Contain'),
'#default_value' => $settings['contain'],
'#description' => $this
->t('Contains cells to gallery element to prevent excess scroll at beginning or end.'),
);
$form['percent_position'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Percent position'),
'#default_value' => $settings['percent_position'],
'#description' => $this
->t('Sets positioning in percent values, rather than pixel values.'),
);
$form['right_to_left'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Right to left'),
'#default_value' => $settings['right_to_left'],
'#description' => $this
->t('Enables right-to-left layout.'),
);
// Behavior
$form['draggable'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Draggable'),
'#default_value' => $settings['draggable'],
'#description' => $this
->t('Enables dragging and flicking.'),
);
$form['free_scroll'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Free scroll'),
'#default_value' => $settings['free_scroll'],
'#description' => $this
->t('Enables content to be freely scrolled and flicked without aligning cells to an end position.'),
);
$form['wrap_around'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Wrap around'),
'#default_value' => $settings['wrap_around'],
'#description' => $this
->t('At the end of cells, wrap-around to the other end for infinite scrolling.'),
);
// @todo, provide additional field if #state is true.
$form['lazy_load'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Lazy load'),
'#default_value' => $settings['lazy_load'],
'#description' => $this
->t('Loads cell images when a cell is selected.'),
);
// @todo, provide additional field if #state is true.
$form['auto_play'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Auto play'),
'#default_value' => $settings['auto_play'],
'#description' => $this
->t('Auto-playing will pause when mouse is hovered over, and resume when mouse is hovered off. Auto-playing will stop when the gallery is clicked or a cell is selected.'),
);
// Extra
$form['watch_css'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Watch CSS'),
'#default_value' => $settings['watch_css'],
'#description' => $this
->t('You can enable and disable Flickity with CSS. watchCSS option watches the content of :after of the gallery element. Flickity is enabled if :after content is flickity.'),
);
$form['as_nav_for'] = array(
'#type' => 'textfield',
'#title' => $this
->t('As nav for'),
'#default_value' => $settings['as_nav_for'],
'#size' => 30,
'#description' => $this
->t('Use one Flickity gallery as navigation for another. This can be set a selector string'),
);
// Display
$form['selected_attraction'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Selected attraction'),
'#default_value' => $settings['selected_attraction'],
'#size' => 30,
'#description' => $this
->t('Attracts the position of the slider to the selected cell. Higher attraction makes the slider move faster.'),
);
$form['friction'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Friction'),
'#default_value' => $settings['friction'],
'#size' => 30,
'#description' => $this
->t('Slows the movement of slider. Higher friction makes the slider feel stickier and less bouncy. Lower friction makes the slider feel looser and more wobbly.'),
);
$form['free_scroll_friction'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Free scroll friction'),
'#default_value' => $settings['free_scroll_friction'],
'#size' => 30,
'#description' => $this
->t('Slows movement of slider when freeScroll: true. Higher friction makes the slider feel stickier. Lower friction makes the slider feel looser.'),
);
// UI
$form['prev_next_buttons'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Previous next buttons'),
'#default_value' => $settings['prev_next_buttons'],
'#description' => $this
->t('Creates and enables previous & next buttons.'),
);
$form['page_dots'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Page dots'),
'#default_value' => $settings['page_dots'],
'#description' => $this
->t('Creates and enables page dots.'),
);
return parent::form($form, $form_state, $entity);
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
$entity
->set('label', trim($entity
->label()));
$entity
->set('settings', array(
'images_loaded' => $form_state
->getValue('images_loaded'),
'cell_selector' => $form_state
->getValue('cell_selector'),
'initial_index' => $form_state
->getValue('initial_index'),
'accessibility' => $form_state
->getValue('accessibility'),
'set_gallery_size' => $form_state
->getValue('set_gallery_size'),
'resize' => $form_state
->getValue('resize'),
'cell_align' => $form_state
->getValue('cell_align'),
'contain' => $form_state
->getValue('contain'),
'percent_position' => $form_state
->getValue('percent_position'),
'right_to_left' => $form_state
->getValue('right_to_left'),
'draggable' => $form_state
->getValue('draggable'),
'free_scroll' => $form_state
->getValue('free_scroll'),
'wrap_around' => $form_state
->getValue('wrap_around'),
'lazy_load' => $form_state
->getValue('lazy_load'),
'auto_play' => $form_state
->getValue('auto_play'),
'watch_css' => $form_state
->getValue('watch_css'),
'as_nav_for' => $form_state
->getValue('as_nav_for'),
'selected_attraction' => $form_state
->getValue('selected_attraction'),
'friction' => $form_state
->getValue('friction'),
'free_scroll_friction' => $form_state
->getValue('free_scroll_friction'),
'prev_next_buttons' => $form_state
->getValue('prev_next_buttons'),
'page_dots' => $form_state
->getValue('page_dots'),
));
$status = $entity
->save();
$edit_link = $this->entity
->link($this
->t('Edit'));
$action = $status == SAVED_UPDATED ? 'updated' : 'added';
// Group has been updated.
drupal_set_message($this
->t('Group %label has been %action.', [
'%label' => $entity
->label(),
'%action' => $action,
]));
$this
->logger('flickity')
->notice('Group %label has been %action.', array(
'%label' => $entity
->label(),
'link' => $edit_link,
));
// Redirect back to display view.
$form_state
->setRedirect('flickity.group_list');
}
/**
* {@inheritdoc}
*/
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this->entity
->isNew() ? $this
->t('Add group') : $this
->t('Update group');
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:: |
protected | function | Copies top-level form values to entity properties | 7 |
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 | ||
FlickityGroupForm:: |
protected | function |
Returns an array of supported actions for the current entity form. Overrides EntityForm:: |
|
FlickityGroupForm:: |
public | function |
Gets the actual form array to be built. Overrides EntityForm:: |
|
FlickityGroupForm:: |
public | function |
Form submission handler for the 'save' action. Overrides EntityForm:: |
|
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. | |
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. |