protected function GroupContentMenuController::handleOneMenuLimitation in Group Content Menu 8
Handle one menu per group limitation.
Parameters
\Drupal\group\Entity\GroupInterface $group: The group.
string $plugin_id: The group content plugin ID.
Return value
\Symfony\Component\HttpFoundation\RedirectResponse|bool The redirect response or FALSE if no need to handle..
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
2 calls to GroupContentMenuController::handleOneMenuLimitation()
- GroupContentMenuController::addPage in src/
Controller/ GroupContentMenuController.php - Provides the group content creation overview page.
- GroupContentMenuController::createForm in src/
Controller/ GroupContentMenuController.php - Provides the group content creation form.
File
- src/
Controller/ GroupContentMenuController.php, line 105
Class
- GroupContentMenuController
- Returns responses for 'group_content_menu' GroupContent routes.
Namespace
Drupal\group_content_menu\ControllerCode
protected function handleOneMenuLimitation(GroupInterface $group, $plugin_id) {
if ($group_contents = $this->entityTypeManager
->getStorage('group_content')
->loadByGroup($group, $plugin_id)) {
$group_content = reset($group_contents);
if ($menu_type = $this->entityTypeManager
->getStorage('group_content_menu_type')
->load($group_content
->getEntity()
->bundle())) {
$this
->messenger()
->addError($this
->t('This group already has a menu "%menu" of type "%type". Only one menu per type per group is allowed.', [
'%menu' => $group_content
->getEntity()
->label(),
'%type' => $menu_type
->label(),
]));
$route_params = [
'group' => $group_content
->getGroup()
->id(),
];
$url = Url::fromRoute('entity.group_content_menu.collection', $route_params, [
'absolute' => TRUE,
]);
return new RedirectResponse($url
->toString());
}
}
}