Skip to content

Commit 3646491

Browse files
authored
Merge pull request #13 from UCBoulder/d-1098
D 1098
2 parents ee496de + 8e22ebb commit 3646491

3 files changed

Lines changed: 98 additions & 2 deletions

File tree

oit.module

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ function oit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
143143
$form['formId']['#default_value'] = 'webform_add_' . $webform_id;
144144
}
145145

146+
if ($form_id == "taxonomy_term_service_dashboard_category_form") {
147+
$form['actions']['submit']['#submit'][] = 'oit_servicealert_dashboard_category_add';
148+
$form['actions']['overview']['#submit'][] = 'oit_servicealert_dashboard_category_add';
149+
}
150+
151+
if ($form_id == "taxonomy_term_service_dashboard_category_delete_form") {
152+
$form['actions']['submit']['#submit'][] = 'oit_servicealert_dashboard_category_delete';
153+
}
154+
146155
if ($form_id == 'node_news_form' || $form_id == 'node_news_edit_form' ||
147156
$form_id == 'node_service_alert_form' || $form_id == 'node_service_alert_edit_form'
148157
) {
@@ -459,6 +468,42 @@ function oit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
459468
}
460469
}
461470

471+
/**
472+
* Service alert dashboard category add handler.
473+
*/
474+
function oit_servicealert_dashboard_category_add($form, FormStateInterface $form_state) {
475+
$name = Xss::filter($form_state->getValue('name')[0]['value']);
476+
$dashboard_state = \Drupal::state()->get('oit_dashboard_add');
477+
478+
if ($dashboard_state) {
479+
$dashboard_state = json_decode($dashboard_state, TRUE);
480+
}
481+
482+
$dashboard_state[]= $name;
483+
484+
// Add term_name to a drupal state for future GH action processing.
485+
\Drupal::state()->set('oit_dashboard_add', json_encode($dashboard_state));
486+
}
487+
488+
/**
489+
* Service alert dashboard category delete handler.
490+
*/
491+
function oit_servicealert_dashboard_category_delete($form, FormStateInterface $form_state) {
492+
$term = $form_state->getFormObject()->getEntity();
493+
$term_name = $term->getName();
494+
495+
$dashboard_state = \Drupal::state()->get('oit_dashboard_delete');
496+
497+
if ($dashboard_state) {
498+
$dashboard_state = json_decode($dashboard_state, TRUE);
499+
}
500+
501+
$dashboard_state[]= $term_name;
502+
503+
// Add term_name to a drupal state for future GH action processing.
504+
\Drupal::state()->set('oit_dashboard_delete', json_encode($dashboard_state));
505+
}
506+
462507
/**
463508
* Node form validate for GP blank body.
464509
*/

oit.routing.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ oit.saml.login:
2121
_permission: 'access content'
2222
options:
2323
no_cache: 'TRUE'
24+
oit.cronJson:
25+
path: '/cron/dashboard/json'
26+
defaults:
27+
_controller: '\Drupal\oit\Controller\OitController::oitCronJson'
28+
_title: ''
29+
requirements:
30+
_permission: 'access content'
2431
oit.denied:
2532
path: '/denied'
2633
defaults:

src/Controller/OitController.php

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
use Drupal\Core\PageCache\ResponsePolicy\KillSwitch;
1212
use Drupal\Core\Render\RendererInterface;
1313
use Drupal\Core\Session\AccountInterface;
14+
use Drupal\Core\State\StateInterface;
1415
use Drupal\Core\Url;
1516
use Drupal\oit\Plugin\BlockUuidQuery;
1617
use Drupal\oit\Plugin\ServiceHealth;
1718
use Drupal\shortcode_svg\Plugin\ShortcodeIcon;
1819
use Drupal\views\Views;
1920
use Symfony\Component\DependencyInjection\ContainerInterface;
21+
use Symfony\Component\HttpFoundation\JsonResponse;
2022
use Symfony\Component\HttpFoundation\RedirectResponse;
2123
use Symfony\Component\HttpFoundation\RequestStack;
2224

@@ -102,6 +104,13 @@ class OitController extends ControllerBase {
102104
*/
103105
protected $shortcodeSvgIcon;
104106

107+
/**
108+
* The state service.
109+
*
110+
* @var \Drupal\Core\State\StateInterface
111+
*/
112+
protected $state;
113+
105114
/**
106115
* Constructs request stuff.
107116
*
@@ -127,6 +136,8 @@ class OitController extends ControllerBase {
127136
* Load entity.
128137
* @param \Drupal\shortcode_svg\Plugin\ShortcodeIcon $shortcode_svg_icon
129138
* Call shortcode svg icon.
139+
* @param \Drupal\Core\State\StateInterface $state
140+
* The state service.
130141
*/
131142
public function __construct(
132143
AccountInterface $account,
@@ -140,6 +151,7 @@ public function __construct(
140151
ServiceHealth $service_health,
141152
EntityTypeManagerInterface $entity_type_manager,
142153
ShortcodeIcon $shortcode_svg_icon,
154+
StateInterface $state,
143155
) {
144156
$this->account = $account;
145157
$this->requestStack = $request_stack->getCurrentRequest();
@@ -152,6 +164,7 @@ public function __construct(
152164
$this->serviceHealth = $service_health;
153165
$this->entityTypeManager = $entity_type_manager;
154166
$this->shortcodeSvgIcon = $shortcode_svg_icon;
167+
$this->state = $state;
155168
}
156169

157170
/**
@@ -169,7 +182,8 @@ public static function create(ContainerInterface $container): self {
169182
$container->get('renderer'),
170183
$container->get('oit.servicehealth'),
171184
$container->get('entity_type.manager'),
172-
$container->get('shortcode_svg.icon')
185+
$container->get('shortcode_svg.icon'),
186+
$container->get('state')
173187
);
174188
}
175189

@@ -291,7 +305,37 @@ public function oitSamlLogin() {
291305
}
292306

293307
/**
294-
* Routes for zap.
308+
* Routes for cron json.
309+
*/
310+
public function oitCronJson() {
311+
// Get state 'oit_dashboard_delete'.
312+
$dashboard_delete = $this->state->get('oit_dashboard_delete');
313+
if ($dashboard_delete == NULL || $dashboard_delete == '' || $dashboard_delete == '[]') {
314+
$dash_delete = FALSE;
315+
}
316+
else {
317+
$dash_delete = TRUE;
318+
}
319+
320+
$dashboard_add = $this->state->get('oit_dashboard_add');
321+
322+
if ($dashboard_add == NULL || $dashboard_add == '' || $dashboard_add == '[]') {
323+
$dash_add = FALSE;
324+
}
325+
else {
326+
$dash_add = TRUE;
327+
}
328+
329+
$response = new JsonResponse(['dashboard_delete' => $dash_delete, 'dashboard_add' => $dash_add]);
330+
331+
// Disable page caching for this response.
332+
$this->killSwitch->trigger();
333+
334+
return $response;
335+
}
336+
337+
/**
338+
* Routes for denied.
295339
*/
296340
public function oitDenied() {
297341
$content = $this->deniedContent();

0 commit comments

Comments
 (0)