You are here

public function FlickityGroupForm::save in Flickity Carousel 8

Same name and namespace in other branches
  1. 8.2 src/Form/FlickityGroupForm.php \Drupal\flickity\Form\FlickityGroupForm::save()
  2. 3.0.x 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 206
Contains \Drupal\flickity\Form\FlickityGroupForm.

Class

FlickityGroupForm
Form controller for the group entity add/edit forms.

Namespace

Drupal\flickity\Form

Code

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');
}