diff --git a/group.module b/group.module index fe030ad..759e789 100644 --- a/group.module +++ b/group.module @@ -16,6 +16,7 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\group\Entity\GroupContent; use Drupal\user\RoleInterface; +use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException; /** * Implements hook_help(). @@ -508,9 +509,19 @@ function group_content_entity_submit($form, FormStateInterface $form_state) { // 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()); + // If the entity don't have 'canonical' or uri_callback, $entity->toUrl() + // will throw exception, the "try/catch" make the program don't stop. + try { + $entity_url = $entity->toUrl(); + } catch (UndefinedLinkTemplateException $e) { + // Nothing to do here. + } + if (isset($entity_url)) { + $form_state->setRedirectUrl($entity_url); + return; + } } - elseif ($group->access('view')) { + if ($group->access('view')) { $form_state->setRedirectUrl($group->toUrl()); } else {