public function FontYourFaceController::deactivateFont in @font-your-face 8.3
1 string reference to 'FontYourFaceController::deactivateFont'
File
- src/
Controller/ FontYourFaceController.php, line 67
Class
- FontYourFaceController
- Controller routines for forum routes.
Namespace
Drupal\fontyourface\ControllerCode
public function deactivateFont(Font $font, $js) {
try {
$font
->deactivate();
if ($js == 'ajax') {
$url = Url::fromRoute('entity.font.activate', [
'js' => 'nojs',
'font' => $font
->id(),
], [
'query' => \Drupal::destination()
->getAsArray(),
]);
$url
->setOptions([
'attributes' => [
'id' => 'font-status-' . $font
->id(),
'class' => [
'font-status',
'disabled',
'use-ajax',
],
],
]);
$text = $this
->t('Enable');
$link = Link::fromTextAndUrl($text, $url)
->toString();
$response = new AjaxResponse();
return $response
->addCommand(new ReplaceCommand('#font-status-' . $font
->id(), $link));
}
else {
\Drupal::messenger()
->addMessage($this
->t('Font @font successfully disabled', [
'@font' => $font->name->value,
]));
return $this
->redirect('entity.font.collection');
}
} catch (Exception $e) {
$error = $e
->getMessage();
if ($js == 'ajax') {
return new AjaxResponse([
'response' => TRUE,
'message' => $error,
], 503);
}
else {
\Drupal::messenger()
->addMessage($error, 'error');
return $this
->redirect('entity.font.collection');
}
}
}