You are here

function group_content_entity_submit in Group 8

Same name and namespace in other branches
  1. 2.0.x group.module \group_content_entity_submit()

Adds a newly saved entity to a group.

See also

group_form_alter()

\Drupal\group\Entity\Controller\GroupContentController::createForm()

1 string reference to 'group_content_entity_submit'
group_form_alter in ./group.module
Implements hook_form_alter().

File

./group.module, line 653
Allows you to group users, content and other entities.

Code

function group_content_entity_submit($form, FormStateInterface $form_state) {

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $form_state
    ->getFormObject()
    ->getEntity();

  /** @var \Drupal\group\Entity\GroupInterface $group */
  $group = $form_state
    ->get('group');
  $group
    ->addContent($entity, $form_state
    ->get('group_content_enabler'));

  // This submit handler is only called when creating new content within a group
  // without using the 2-step wizard. We can therefore safely assume the user
  // wants to see the entity itself and not the relationship (group content).
  // This only applies if there was no destination GET parameter set in the URL.
  if ($entity
    ->access('view')) {
    $form_state
      ->setRedirectUrl($entity
      ->toUrl());
  }
  elseif ($group
    ->access('view')) {
    $form_state
      ->setRedirectUrl($group
      ->toUrl());
  }
  else {
    $form_state
      ->setRedirect('<front>');
  }
}