public function ContextUIController::addReaction in Context 8.0
Same name and namespace in other branches
- 8.4 modules/context_ui/src/Controller/ContextUIController.php \Drupal\context_ui\Controller\ContextUIController::addReaction()
- 8 modules/context_ui/src/Controller/ContextUIController.php \Drupal\context_ui\Controller\ContextUIController::addReaction()
Add the specified reaction to the context.
Parameters
Request $request: The current request.
ContextInterface $context: The context to add the reaction to.
$reaction_id: The ID of the reaction to add.
Return value
1 string reference to 'ContextUIController::addReaction'
- context_ui.routing.yml in modules/
context_ui/ context_ui.routing.yml - modules/context_ui/context_ui.routing.yml
File
- modules/
context_ui/ src/ Controller/ ContextUIController.php, line 276
Class
Namespace
Drupal\context_ui\ControllerCode
public function addReaction(Request $request, ContextInterface $context, $reaction_id) {
if ($context
->hasReaction($reaction_id)) {
throw new HttpException(403, 'The specified condition had already been added to the context.');
}
// Create an instance of the reaction and add it to the context.
try {
$reaction = $this->contextReactionManager
->createInstance($reaction_id);
} catch (PluginException $e) {
throw new HttpException(400, $e
->getMessage());
}
$context
->addReaction($reaction
->getConfiguration());
$context
->save();
// If the request is an AJAX request then return an AJAX response with
// commands to replace the content on the page.
if ($request
->isXmlHttpRequest()) {
$response = new AjaxResponse();
$contextForm = $this->contextManager
->getForm($context, 'edit');
$response
->addCommand(new CloseModalDialogCommand());
$response
->addCommand(new ReplaceCommand('#context-reactions', $contextForm['reactions']));
return $response;
}
$url = $context
->urlInfo('edit-form');
return $this
->redirect($url
->getRouteName(), $url
->getRouteParameters());
}