3 namespace Drupal\fontyourface\Controller;
6 use Drupal\Core\Ajax\AjaxResponse;
7 use Drupal\Core\Ajax\ReplaceCommand;
8 use Drupal\Core\Controller\ControllerBase;
9 use Drupal\fontyourface\Entity\Font;
12 * Controller routines for forum routes.
14 class FontYourFaceController extends ControllerBase {
19 public function activateFont(Font $font, $js) {
23 $url = Url::fromRoute('entity.font.deactivate', ['js' => 'nojs', 'font' => $font->id()], ['query' => \Drupal::destination()->getAsArray()]);
24 $url->setOptions(['attributes' => ['id' => 'font-status-' . $font->id(), 'class' => ['font-status', 'enabled', 'use-ajax']]]);
25 $text = $this->t('Enable');
26 $link = \Drupal::l($text, $url);
28 $response = new AjaxResponse();
29 return $response->addCommand(new ReplaceCommand('#font-status-' . $font->id(), $link));
32 drupal_set_message($this->t('Font @font successfully enabled', ['@font' => $font->name->value]));
33 return $this->redirect('entity.font.collection');
36 catch (Exception $e) {
37 $error = $e->getMessage();
39 return new AjaxResponse([
45 drupal_set_message($error, 'error');
46 return $this->redirect('entity.font.collection');
54 public function deactivateFont(Font $font, $js) {
58 $url = Url::fromRoute('entity.font.activate', ['js' => 'nojs', 'font' => $font->id()], ['query' => \Drupal::destination()->getAsArray()]);
59 $url->setOptions(['attributes' => ['id' => 'font-status-' . $font->id(), 'class' => ['font-status', 'disabled', 'use-ajax']]]);
60 $text = $this->t('Enable');
61 $link = \Drupal::l($text, $url);
63 $response = new AjaxResponse();
64 return $response->addCommand(new ReplaceCommand('#font-status-' . $font->id(), $link));
67 drupal_set_message($this->t('Font @font successfully disabled', ['@font' => $font->name->value]));
68 return $this->redirect('entity.font.collection');
71 catch (Exception $e) {
72 $error = $e->getMessage();
74 return new AjaxResponse([
80 drupal_set_message($error, 'error');
81 return $this->redirect('entity.font.collection');