public function FlickityGroupForm::save in Flickity Carousel 3.0.x
Same name and namespace in other branches
- 8.2 src/Form/FlickityGroupForm.php \Drupal\flickity\Form\FlickityGroupForm::save()
- 8 src/Form/FlickityGroupForm.php \Drupal\flickity\Form\FlickityGroupForm::save()
Form submission handler for the 'save' action.
Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides EntityForm::save
File
- src/
Form/ FlickityGroupForm.php, line 224 - Contains \Drupal\flickity\Form\FlickityGroupForm.
Class
- FlickityGroupForm
- Form controller for the group entity add/edit forms.
Namespace
Drupal\flickity\FormCode
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'),
'group_cells' => $form_state
->getValue('group_cells'),
'adaptive_height' => $form_state
->getValue('adaptive_height'),
'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'),
'drag_threshold' => $form_state
->getValue('drag_threshold'),
'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();
// TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
// Please confirm that `$entity` is an instance of `\Drupal\Core\Entity\EntityInterface`. Only the method name and not the class name was checked for this replacement, so this may be a false positive.
$edit_link = $this->entity
->toLink($this
->t('Edit'))
->toString();
$action = $status == SAVED_UPDATED ? 'updated' : 'added';
// Group has been updated.
$this
->messenger()
->addStatus($this
->t('Group %label has been %action.', array(
'%label' => $entity
->label(),
'%action' => $action,
)));
$this
->logger('flickity')
->notice('Group %label has been %action.', array(
'%label' => $entity
->label(),
'%action' => $action,
));
// Redirect back to display view.
$form_state
->setRedirect('flickity.group_list');
}