diff --git a/oit.module b/oit.module index c6a19e0..41d6d8b 100644 --- a/oit.module +++ b/oit.module @@ -140,6 +140,15 @@ function oit_form_alter(&$form, FormStateInterface $form_state, $form_id) { $form['formId']['#default_value'] = 'webform_add_' . $webform_id; } + if ($form_id == "taxonomy_term_service_dashboard_category_form") { + $form['actions']['submit']['#submit'][] = 'oit_servicealert_dashboard_category_add'; + $form['actions']['overview']['#submit'][] = 'oit_servicealert_dashboard_category_add'; + } + + if ($form_id == "taxonomy_term_service_dashboard_category_delete_form") { + $form['actions']['submit']['#submit'][] = 'oit_servicealert_dashboard_category_delete'; + } + if ($form_id == 'node_news_form' || $form_id == 'node_news_edit_form' || $form_id == 'node_service_alert_form' || $form_id == 'node_service_alert_edit_form' ) { @@ -456,6 +465,42 @@ function oit_form_alter(&$form, FormStateInterface $form_state, $form_id) { } } +/** + * Service alert dashboard category add handler. + */ +function oit_servicealert_dashboard_category_add($form, FormStateInterface $form_state) { + $name = Xss::filter($form_state->getValue('name')[0]['value']); + $dashboard_state = \Drupal::state()->get('oit_dashboard_add'); + + if ($dashboard_state) { + $dashboard_state = json_decode($dashboard_state, TRUE); + } + + $dashboard_state[]= $name; + + // Add term_name to a drupal state for future GH action processing. + \Drupal::state()->set('oit_dashboard_add', json_encode($dashboard_state)); +} + +/** + * Service alert dashboard category delete handler. + */ +function oit_servicealert_dashboard_category_delete($form, FormStateInterface $form_state) { + $term = $form_state->getFormObject()->getEntity(); + $term_name = $term->getName(); + + $dashboard_state = \Drupal::state()->get('oit_dashboard_delete'); + + if ($dashboard_state) { + $dashboard_state = json_decode($dashboard_state, TRUE); + } + + $dashboard_state[]= $term_name; + + // Add term_name to a drupal state for future GH action processing. + \Drupal::state()->set('oit_dashboard_delete', json_encode($dashboard_state)); +} + /** * Node form validate for GP blank body. */ diff --git a/oit.routing.yml b/oit.routing.yml index 71781cf..46fa494 100644 --- a/oit.routing.yml +++ b/oit.routing.yml @@ -21,6 +21,13 @@ oit.saml.login: _permission: 'access content' options: no_cache: 'TRUE' +oit.cronJson: + path: '/cron/dashboard/json' + defaults: + _controller: '\Drupal\oit\Controller\OitController::oitCronJson' + _title: '' + requirements: + _permission: 'access content' oit.denied: path: '/denied' defaults: diff --git a/src/Controller/OitController.php b/src/Controller/OitController.php index efffb83..0853806 100644 --- a/src/Controller/OitController.php +++ b/src/Controller/OitController.php @@ -11,12 +11,14 @@ use Drupal\Core\PageCache\ResponsePolicy\KillSwitch; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\State\StateInterface; use Drupal\Core\Url; use Drupal\oit\Plugin\BlockUuidQuery; use Drupal\oit\Plugin\ServiceHealth; use Drupal\shortcode_svg\Plugin\ShortcodeIcon; use Drupal\views\Views; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RequestStack; @@ -102,6 +104,13 @@ class OitController extends ControllerBase { */ protected $shortcodeSvgIcon; + /** + * The state service. + * + * @var \Drupal\Core\State\StateInterface + */ + protected $state; + /** * Constructs request stuff. * @@ -127,6 +136,8 @@ class OitController extends ControllerBase { * Load entity. * @param \Drupal\shortcode_svg\Plugin\ShortcodeIcon $shortcode_svg_icon * Call shortcode svg icon. + * @param \Drupal\Core\State\StateInterface $state + * The state service. */ public function __construct( AccountInterface $account, @@ -140,6 +151,7 @@ public function __construct( ServiceHealth $service_health, EntityTypeManagerInterface $entity_type_manager, ShortcodeIcon $shortcode_svg_icon, + StateInterface $state, ) { $this->account = $account; $this->requestStack = $request_stack->getCurrentRequest(); @@ -152,6 +164,7 @@ public function __construct( $this->serviceHealth = $service_health; $this->entityTypeManager = $entity_type_manager; $this->shortcodeSvgIcon = $shortcode_svg_icon; + $this->state = $state; } /** @@ -169,7 +182,8 @@ public static function create(ContainerInterface $container): self { $container->get('renderer'), $container->get('oit.servicehealth'), $container->get('entity_type.manager'), - $container->get('shortcode_svg.icon') + $container->get('shortcode_svg.icon'), + $container->get('state') ); } @@ -291,7 +305,37 @@ public function oitSamlLogin() { } /** - * Routes for zap. + * Routes for cron json. + */ + public function oitCronJson() { + // Get state 'oit_dashboard_delete'. + $dashboard_delete = $this->state->get('oit_dashboard_delete'); + if ($dashboard_delete == NULL || $dashboard_delete == '' || $dashboard_delete == '[]') { + $dash_delete = FALSE; + } + else { + $dash_delete = TRUE; + } + + $dashboard_add = $this->state->get('oit_dashboard_add'); + + if ($dashboard_add == NULL || $dashboard_add == '' || $dashboard_add == '[]') { + $dash_add = FALSE; + } + else { + $dash_add = TRUE; + } + + $response = new JsonResponse(['dashboard_delete' => $dash_delete, 'dashboard_add' => $dash_add]); + + // Disable page caching for this response. + $this->killSwitch->trigger(); + + return $response; + } + + /** + * Routes for denied. */ public function oitDenied() { $content = $this->deniedContent();