You are here

public function FilterEditForm::save in Entity Share 8.2

Same name and namespace in other branches
  1. 8.3 modules/entity_share_server/src/Form/FilterEditForm.php \Drupal\entity_share_server\Form\FilterEditForm::save()
  2. 8 modules/entity_share_server/src/Form/FilterEditForm.php \Drupal\entity_share_server\Form\FilterEditForm::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

modules/entity_share_server/src/Form/FilterEditForm.php, line 102

Class

FilterEditForm
Class FilterEditForm.

Namespace

Drupal\entity_share_server\Form

Code

public function save(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\entity_share_server\Entity\ChannelInterface $channel */
  $channel = $this->entity;
  $channel_filters = $channel
    ->get('channel_filters');

  // Add the filter.
  $edited_filter = [
    'path' => $form_state
      ->getValue('path'),
    'operator' => $form_state
      ->getValue('operator'),
  ];
  $value = $form_state
    ->getValue([
    'value_wrapper',
    'value',
  ]);
  if (!is_null($value)) {
    $edited_filter['value'] = array_filter($value);
  }
  $memberof = $form_state
    ->getValue('memberof');
  if (!empty($memberof)) {
    $edited_filter['memberof'] = $memberof;
  }
  $channel_filters[$form_state
    ->getValue('filter_id')] = $edited_filter;
  $channel
    ->set('channel_filters', $channel_filters);
  $channel
    ->save();
  $form_state
    ->setRedirectUrl($channel
    ->toUrl('edit-form'));
}