public function WebhookController::toggleActive in Webhooks 8
Toggle the active state.
Parameters
mixed $id: The id of the entity given by route url.
Return value
\Symfony\Component\HttpFoundation\RedirectResponse A redirect response object that may be returned by the controller.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
\Drupal\Core\Entity\EntityStorageException
1 string reference to 'WebhookController::toggleActive'
File
- src/
Controller/ WebhookController.php, line 164
Class
- WebhookController
- Class Webhook.
Namespace
Drupal\webhooks\ControllerCode
public function toggleActive($id) {
$webhooks_storage = $this->entityTypeManager
->getStorage('webhook_config');
/** @var \Drupal\webhooks\Entity\WebhookConfig $webhook_config */
$webhook_config = $webhooks_storage
->load($id);
$webhook_config
->setStatus(!$webhook_config
->status());
$webhook_config
->save();
$this
->messenger()
->addStatus($this
->t('Webhook <a href=":url">@webhook</a> has been %status.', [
':url' => Url::fromRoute('entity.webhook_config.edit_form', [
'webhook_config' => $webhook_config
->getId(),
])
->toString(),
'@webhook' => $webhook_config
->getLabel(),
'%status' => $webhook_config
->status() ? 'enabled' : 'disabled',
]));
return $this
->redirect("entity.webhook_config.collection");
}