Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions oit.module
Original file line number Diff line number Diff line change
Expand Up @@ -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'
) {
Expand Down Expand Up @@ -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.
*/
Expand Down
7 changes: 7 additions & 0 deletions oit.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
48 changes: 46 additions & 2 deletions src/Controller/OitController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -102,6 +104,13 @@ class OitController extends ControllerBase {
*/
protected $shortcodeSvgIcon;

/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;

/**
* Constructs request stuff.
*
Expand All @@ -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,
Expand All @@ -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();
Expand All @@ -152,6 +164,7 @@ public function __construct(
$this->serviceHealth = $service_health;
$this->entityTypeManager = $entity_type_manager;
$this->shortcodeSvgIcon = $shortcode_svg_icon;
$this->state = $state;
}

/**
Expand All @@ -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')
);
}

Expand Down Expand Up @@ -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();
Expand Down