You are here

public function GroupAddForm::save in Entity Share 8

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

Class

GroupAddForm
Class GroupAddForm.

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_groups = $channel
    ->get('channel_groups');
  if (is_null($channel_groups)) {
    $channel_groups = [];
  }
  $channel_groups[$form_state
    ->getValue('group_id')] = [
    'conjunction' => $form_state
      ->getValue('conjunction'),
  ];
  if (!empty($form_state
    ->getValue('memberof'))) {
    $channel_groups[$form_state
      ->getValue('group_id')]['memberof'] = $form_state
      ->getValue('memberof');
  }
  $channel
    ->set('channel_groups', $channel_groups);
  $channel
    ->save();
  $form_state
    ->setRedirectUrl($channel
    ->toUrl('edit-form'));
}