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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# OIT Module

Module that has all misc functions that don't make sense under any specific modules.
Module that has all misc functions that don't make sense under any
specific modules.

![Axolotl Keyboard](https://giphy.com/embed/RE5iREBNhI0Ok)
29 changes: 29 additions & 0 deletions config/install/ultimate_cron.job.delete_news.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
langcode: en
status: true
dependencies:
module:
- oit
title: 'Delete Old News'
id: delete_news
weight: -10
module: oit
callback: '\Drupal\oit\Services\CronManager::deleteNews'
scheduler:
id: crontab
configuration:
rules:
- '0 0 1 */6 *'
catch_up: 14400
launcher:
id: serial
configuration:
timeouts:
lock_timeout: 3600
launcher:
thread: 0
logger:
id: database
configuration:
method: '3'
expire: 1209600
retain: 1000
1 change: 1 addition & 0 deletions drush.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ services:
- '@database'
- '@oit.userclean'
- '@oit.toppages'
- '@oit.deletenews'
tags:
- { name: drush.command }
19 changes: 13 additions & 6 deletions oit.install
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @file
* Install, update and uninstall functions for the sympa_initialize module.
* Install, update and uninstall functions for the OIT module.
*/

use Drupal\Component\Utility\Random;
Expand All @@ -13,6 +13,13 @@ use Drupal\user\Entity\User;

/**
* Helper function to update node body text.
*
* @param int $nid
* The node ID.
* @param string $body
* The body text value.
* @param string $format
* The text format machine name.
*/
function update_node_body($nid, $body, $format) {
$query = \Drupal::entityQuery('node')
Expand Down Expand Up @@ -134,7 +141,7 @@ function oit_update_9005() {
}

/**
* Implements hook_update().
* Enable show_login_form setting.
*/
function oit_update_9006() {
$config = \Drupal::configFactory()->getEditable('oit.settings');
Expand Down Expand Up @@ -299,7 +306,8 @@ function oit_update_10006() {
function oit_update_10007() {
\Drupal::database()->truncate('node__field_domain_source')->execute();

// Sql query to 'node__field_domain_access' table where delta = 0 pulling in all columns.
// Sql query to 'node__field_domain_access' table where delta = 0 pulling
// in all columns.
$query = \Drupal::database()->select('node__field_domain_access', 'nfa');
$query->fields('nfa', [
'bundle',
Expand All @@ -319,7 +327,7 @@ function oit_update_10007() {
$lang = $row->langcode;
$bundle = $row->bundle;
$target_id = $row->field_domain_access_target_id;
$insert = \Drupal::database()->insert('node__field_domain_source')
\Drupal::database()->insert('node__field_domain_source')
->fields([
'bundle',
'deleted',
Expand Down Expand Up @@ -687,7 +695,7 @@ function oit_update_10018() {
}

/**
* Clear field_news_front_image values from news nodes and delete associated files.
* Remove field_news_front_image values and associated files from news nodes.
*/
function oit_update_10019() {
$database = \Drupal::database();
Expand All @@ -696,4 +704,3 @@ function oit_update_10019() {
$database->truncate('node__field_news_front_image')->execute();
$database->truncate('node_revision__field_news_front_image')->execute();
}

1 change: 0 additions & 1 deletion oit.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,3 @@ oit_env:
license:
name: 'GPL-2.0-or-later'
url: 'https://www.drupal.org/licensing/faq'

1 change: 0 additions & 1 deletion oit.links.task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ oit.abusetable:
route_name: oit.abusetable
title: 'Low Confidence Banned ips'
base_route: entity.autoban.list

58 changes: 35 additions & 23 deletions oit.module
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
use Drupal\oit\Plugin\OitImageStyled;
use Drupal\user\Entity\User;
Expand All @@ -30,7 +28,7 @@ function oit_preprocess_html(&$variables) {
$title[0] = $variables['head_title']['name'] ?? '';
$title[1] = '';
if (isset($variables['head_title']['title'])) {
$title[1] = is_string($variables['head_title']['title'])?$variables['head_title']['title']:$variables['head_title']['title']->__toString();
$title[1] = is_string($variables['head_title']['title']) ? $variables['head_title']['title'] : $variables['head_title']['title']->__toString();
}
$getEnv = \Drupal::service('oit.environment.icon');
$variables['head_title'] = $getEnv->getEnv() . ' ' . $title[1] . ' | ' . $title[0];
Expand All @@ -55,7 +53,7 @@ function oit_webform_access_rules_alter(array &$access_rules) {
}

/**
* Implements oit_webform_access_rules_alter().
* Implements hook_entity_create().
*/
function oit_entity_create(EntityInterface $entity) {
if ($entity->getEntityType()->getBundleEntityType() == 'node_type' && $entity->getType() == 'webform') {
Expand All @@ -65,7 +63,7 @@ function oit_entity_create(EntityInterface $entity) {
}

/**
* hook_preprocess().
* Implements hook_preprocess().
*/
function oit_preprocess(&$variables, $hook) {
$theme = \Drupal::service('theme.manager')->getActiveTheme()->getName();
Expand Down Expand Up @@ -190,7 +188,22 @@ function oit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
\Drupal::messenger()->addMessage($message, 'warning');
$form['#access'] = FALSE;
}
_oit_form_set_domain('content', 'oit_colorado_edu');
// Get query string.
$query = \Drupal::request()->query->all();
$domain_set = FALSE;
foreach ($query as $key => $value) {
if ($key == 'field_domain_access_target_id') {
$domain_set = TRUE;
}
}
if (!$domain_set) {
// Redirect to query string
// "field_domain_access_target_id=oit_colorado_edu".
$query['field_domain_access_target_id'] = 'oit_colorado_edu';
$query = http_build_query($query);
$response = new RedirectResponse('/admin/content?' . $query);
$response->send();
}
}
}

Expand All @@ -199,11 +212,6 @@ function oit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Get query string.
$query = \Drupal::request()->query->all();
$search_key = isset($query['keys']) ? Xss::filter(strtolower($query['keys'])) : 0;
$space = [
'space monkey',
'space+monkey',
'spacemonkey',
];
if ($search_key == 'space monkey' || $search_key == 'space+monkey' || $search_key == 'spacemonkey') {
$form['#attached']['library'][] = 'oit/spacemonkey';
}
Expand Down Expand Up @@ -385,7 +393,7 @@ function oit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form['#attached']['library'][] = 'oit/oit_node_news_form';
$form['#validate'][] = 'oit_news_types_categories';
// Add submit handler.
$form['actions']['submit']['#submit'][] = 'news_node_form_submit';
$form['actions']['submit']['#submit'][] = 'oit_news_node_form_submit';
break;

case "user_login_form":
Expand All @@ -398,8 +406,8 @@ function oit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (!$show_login_form) {
// Cache is breaking the redirect, so kill it.
\Drupal::service('page_cache_kill_switch')->trigger();
$dest_get = \Drupal::request()->get('dest') != null ? Xss::filter(\Drupal::request()->get('dest')) : '';
$destination_get = \Drupal::request()->get('destination') != null ? Xss::filter(\Drupal::request()->get('destination')) : '';
$dest_get = \Drupal::request()->get('dest') != NULL ? Xss::filter(\Drupal::request()->get('dest')) : '';
$destination_get = \Drupal::request()->get('destination') != NULL ? Xss::filter(\Drupal::request()->get('destination')) : '';
$destination = "";
if (!empty($dest_get)) {
$destination = '?destination=' . preg_replace('/https:\/\/[^\/]+/', '', $dest_get);
Expand Down Expand Up @@ -456,7 +464,7 @@ function oit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
}

/**
* Set domain on content to match site domain
* Set domain on content to match site domain.
*/
function _oit_set_oit_domain(&$form, FormStateInterface $form_state) {
_oit_set_domain_submit($form, $form_state, 'oit', 'oit_colorado_edu');
Expand Down Expand Up @@ -511,7 +519,8 @@ function oit_set_domain_defaults(array &$form, $domain_name, $domain_id) {

// Force access and source if not set.
array_unshift($form['actions']['submit']['#submit'], '_' . $domain_name . '_set_' . $domain_name . '_domain');
} else {
}
else {
// Disable source locally.
$form['field_domain_source']['widget']['#default_value'] = [];
$form['field_domain_source']['widget']['#default_value'][] = '_none';
Expand Down Expand Up @@ -540,10 +549,11 @@ function _oit_set_domain_submit(array &$form, FormStateInterface $form_state, $d
}

/**
* News node form submit handler to un-promote other news nodes when a news
* node is promoted.
* News node form submit handler.
*
* Un-promotes other news nodes when a news node is promoted.
*/
function news_node_form_submit(&$form, FormStateInterface $form_state) {
function oit_news_node_form_submit(&$form, FormStateInterface $form_state) {
if ($form_state->getValues()['promote']['value']) {
$node = $form_state->getFormObject()->getEntity();
$node_id = $node->id();
Expand Down Expand Up @@ -578,7 +588,7 @@ function oit_servicealert_dashboard_category_add($form, FormStateInterface $form
$dashboard_state = json_decode($dashboard_state, TRUE);
}

$dashboard_state[]= $name;
$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));
Expand All @@ -597,7 +607,7 @@ function oit_servicealert_dashboard_category_delete($form, FormStateInterface $f
$dashboard_state = json_decode($dashboard_state, TRUE);
}

$dashboard_state[]= $term_name;
$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));
Expand Down Expand Up @@ -1075,8 +1085,10 @@ function _oit_security_window_warning(array &$form, string $form_id): void {

// Check if it's Wednesday between 1600 and 2200 UTC.
$now = new \DateTime('now', new \DateTimeZone('UTC'));
$day_of_week = (int) $now->format('N'); // ISO: 3 = Wednesday.
$hour = (int) $now->format('G'); // 0–23.
// ISO: 3 = Wednesday.
$day_of_week = (int) $now->format('N');
// 0–23.
$hour = (int) $now->format('G');
if ($day_of_week !== 3 || $hour < 16 || $hour >= 22) {
return;
}
Expand Down
8 changes: 8 additions & 0 deletions oit.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ services:
oit.userclean:
class: Drupal\oit\Plugin\Util\UserClean
arguments: ["@entity_type.manager", "@oit.teamsalert"]
oit.deletenews:
class: Drupal\oit\Plugin\Util\DeleteNews
arguments:
- "@database"
- "@entity_type.manager"
- "@entity_field.manager"
- "@path_alias.manager"
- "@logger.factory"
oit.servicehealth:
class: Drupal\oit\Plugin\ServiceHealth
arguments: ["@config.factory", "@date.formatter", "@entity_type.manager"]
Expand Down
Loading
Loading