Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDPA-5959] coding standards fixes #317

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion css/content_moderation.theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
}

.entity-moderation-form__item {
width: 50%
width: 50%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

use Drupal\block_inactive_users\InactiveUsersHandler;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\KeyValueStore\KeyValueFactory;
use Drupal\Core\Logger\LoggerChannelFactory;
use Drupal\Core\Queue\QueueFactory;
use Drupal\user\Entity\User;
use Drush\Commands\DrushCommands;

/**
Expand Down Expand Up @@ -72,10 +73,24 @@ class TideInactiveUsersManagementCommands extends DrushCommands {
*/
protected $queue;

/**
* KeyValue service.
*
* @var \Drupal\Core\KeyValueStore\KeyValueFactory
*/
protected $keyvalue;

/**
* KeyValue service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;

/**
* {@inheritdoc}
*/
public function __construct(ConfigFactoryInterface $configFactory, InactiveUsersHandler $handler, LoggerChannelFactory $logger, QueueFactory $queueFactory) {
public function __construct(ConfigFactoryInterface $configFactory, InactiveUsersHandler $handler, LoggerChannelFactory $logger, QueueFactory $queueFactory, KeyValueFactory $keyValueFactory, EntityTypeManagerInterface $entityTypeManager) {
parent::__construct();
$this->config = $configFactory;
$this->blockUserhandler = $handler;
Expand All @@ -85,6 +100,8 @@ public function __construct(ConfigFactoryInterface $configFactory, InactiveUsers
$this->includeNeverAccessed = $this->blockInactiveUsers->get('block_inactive_users_include_never_accessed');
$this->excludeUserRoles = $this->blockInactiveUsers->get('block_inactive_users_exclude_roles');
$this->queue = $queueFactory->get('tide_block_inactive_users_queue');
$this->keyvalue = $keyValueFactory;
$this->entityTypeManager = $entityTypeManager;
}

/**
Expand All @@ -102,8 +119,7 @@ public function notify() {
if ($last_access != 0 && !$user->hasRole('administrator')) {
if ($this->blockUserhandler->timestampdiff($last_access, $current_time) >= $this->idleTime) {
// Ensure the email only send once.
if (!\Drupal::keyValue('tide_inactive_users_management')
->get($user->id())) {
if (!$this->keyvalue->get('tide_inactive_users_management')->get($user->id())) {
$item = new \stdClass();
$item->uid = $user->id();
$this->queue->createItem($item);
Expand All @@ -112,8 +128,7 @@ public function notify() {
}
if ($this->includeNeverAccessed == 1 && $last_access == 0) {
if ($this->blockUserhandler->timestampdiff($user->getCreatedTime(), $current_time) >= $this->idleTime) {
if (!\Drupal::keyValue('tide_inactive_users_management')
->get($user->id())) {
if (!$this->keyvalue->get('tide_inactive_users_management')->get($user->id())) {
$item = new \stdClass();
$item->uid = $user->id();
$this->queue->createItem($item);
Expand All @@ -131,14 +146,14 @@ public function notify() {
* @aliases inactive-block
*/
public function block() {
$tide_inactive_users_management_results = \Drupal::keyValue('tide_inactive_users_management');
$tide_inactive_users_management_results = $this->keyvalue->get('tide_inactive_users_management');
if ($times = $tide_inactive_users_management_results->getAll()) {
foreach ($times as $uid => $time) {
$user = User::load($uid);
$user = $this->entityTypeManager->getStorage('user')->load($uid);
if ($user && time() > $time) {
$user->block();
$user->save();
\Drupal::keyValue('tide_inactive_users_management')
$this->keyvalue->get('tide_inactive_users_management')
->delete($user->id());
}
}
Expand All @@ -149,13 +164,13 @@ public function block() {
* Gets users.
*/
public function getUsers() {
$query = \Drupal::entityQuery('user')->condition('status', 1);
$query = $this->entityTypeManager->getStorage('user')->getQuery()->condition('status', 1);
if (!empty($this->excludeUserRoles)) {
$query->condition('roles.target_id', $this->excludeUserRoles, 'NOT IN');
}
$user_ids = $query->execute();
if ($user_ids) {
return User::loadMultiple($user_ids);
return $this->entityTypeManager->getStorage('user')->loadMultiple($user_ids);
}
return [];
}
Expand Down
10 changes: 6 additions & 4 deletions modules/tide_block_inactive_users/src/Form/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
Expand All @@ -14,6 +15,7 @@
* @package Drupal\tide_block_inactive_users\Form
*/
class SettingsForm extends ConfigFormBase {
use StringTranslationTrait;

/**
* A logger instance.
Expand Down Expand Up @@ -95,10 +97,10 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#title' => $this->t('Time unit'),
'#default_value' => $config->get('time_unit'),
'#options' => [
'day' => 'Day(s)',
'week' => 'Week(s)',
'month' => 'Month(s)',
'hour' => 'Hour(s)',
'day' => $this->t('Day(s)'),
'week' => $this->t('Week(s)'),
'month' => $this->t('Month(s)'),
'hour' => $this->t('Hour(s)'),
],
'#required' => TRUE,
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
tide_inactive_users_management.commands:
class: \Drupal\tide_block_inactive_users\Commands\TideInactiveUsersManagementCommands
arguments: ['@config.factory','@block_inactive_users.deactivate_users','@logger.factory','@queue' ]
class: Drupal\tide_block_inactive_users\Commands\TideInactiveUsersManagementCommands
arguments: ['@config.factory','@block_inactive_users.deactivate_users','@logger.factory','@queue', '@keyvalue', '@entity_type.manager' ]
tags:
- { name: drush.command }
2 changes: 1 addition & 1 deletion modules/tide_spell_checker/tide_spell_checker.install
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function tide_spell_checker_install() {
if (isset($rows)) {
$updated_rows = [];

foreach ($rows as $key => $row) {
foreach ($rows as $row) {
if ($row['name'] === 'Tools' && !in_array('Scayt', $row['items'])) {
array_splice($row['items'], 7, 0, 'Scayt');
}
Expand Down
4 changes: 3 additions & 1 deletion src/Form/NodeActionForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand All @@ -16,6 +17,7 @@
* Provides nodes deletion confirmation form.
*/
class NodeActionForm extends ConfirmFormBase {
use StringTranslationTrait;

/**
* The current user.
Expand Down Expand Up @@ -133,7 +135,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$ops[] = [get_class($this) . '::doAction', [$ids, $this->action]];
}
$batch = [
'title' => t('Processing selected content'),
'title' => $this->t('Processing selected content'),
'operations' => $ops,
'finished' => [get_class($this), 'finishBatch'],
];
Expand Down
4 changes: 3 additions & 1 deletion src/Plugin/CKEditorPlugin/TideCallout.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\ckeditor\CKEditorPluginInterface;
use Drupal\ckeditor\CKEditorPluginButtonsInterface;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\editor\Entity\Editor;

/**
Expand All @@ -16,6 +17,7 @@
* )
*/
class TideCallout extends PluginBase implements CKEditorPluginInterface, CKEditorPluginButtonsInterface {
use StringTranslationTrait;

/**
* {@inheritdoc}
Expand Down Expand Up @@ -55,7 +57,7 @@ public function getButtons() {
// Return the CKEditor plugin button details.
return [
'TideCallout' => [
'label' => t('Callout template'),
'label' => $this->t('Callout template'),
'image' => $iconImage,
],
];
Expand Down
4 changes: 3 additions & 1 deletion src/Plugin/CKEditorPlugin/TideEmbeddedGoogleMapsButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Drupal\ckeditor\CKEditorPluginBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\editor\Entity\Editor;

/**
Expand All @@ -23,6 +24,7 @@
* )
*/
class TideEmbeddedGoogleMapsButton extends CKEditorPluginBase {
use StringTranslationTrait;

/**
* {@inheritdoc}
Expand All @@ -36,7 +38,7 @@ public function getButtons() {
// the CKEditor plugin you are implementing.
return [
'wenzgmap' => [
'label' => t('Embedded Google Maps'),
'label' => $this->t('Embedded Google Maps'),
'image' => drupal_get_path('module', 'tide_core') . '/js/plugins/wenzgmap/icons/wenzgmap.png',
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceLabelFormatter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
* Plugin implementation of the 'entity_reference_revisions_label' formatter.
Expand All @@ -21,6 +22,7 @@
* )
*/
class EntityReferenceRevisionsLabelFormatter extends EntityReferenceLabelFormatter {
use StringTranslationTrait;

/**
* {@inheritdoc}
Expand All @@ -37,7 +39,7 @@ public static function defaultSettings() {
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = parent::settingsForm($form, $form_state);
$elements['show_revision_number'] = [
'#title' => t('Show revision number of the referenced entity'),
'#title' => $this->t('Show revision number of the referenced entity'),
'#type' => 'checkbox',
'#default_value' => $this->getSetting('show_revision_number'),
];
Expand All @@ -51,7 +53,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
public function settingsSummary() {
$summary = parent::settingsSummary();
if ($this->getSetting('show_revision_number')) {
$summary[] = t('Show revision number of the referenced entity');
$summary[] = $this->t('Show revision number of the referenced entity');
}

return $summary;
Expand Down
6 changes: 4 additions & 2 deletions src/Plugin/Field/FieldWidget/PresetParagraphsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\tide_core\Plugin\Field\FieldWidget;

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\paragraphs\Plugin\Field\FieldWidget\ParagraphsWidget;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
Expand All @@ -26,6 +27,7 @@
* )
*/
class PresetParagraphsWidget extends ParagraphsWidget {
use StringTranslationTrait;

/**
* Indicates whether the current widget instance is in translation.
Expand All @@ -52,7 +54,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
$form['preset_number'] = [
'#type' => 'number',
'#title' => 'Default number of paragraphs',
'#description' => t('Set the default number of paragraphs.'),
'#description' => $this->t('Set the default number of paragraphs.'),
'#min' => 1,
'#default_value' => $this->getSetting('preset_number'),
];
Expand All @@ -65,7 +67,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
*/
public function settingsSummary() {
$summary = parent::settingsSummary();
$summary[] = t('Number of paragraphs: @number', ['@number' => $this->getSetting('preset_number')]);
$summary[] = $this->t('Number of paragraphs: @number', ['@number' => $this->getSetting('preset_number')]);

return $summary;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Plugin/views/filter/EnhancedMineTypeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\tide_core\Plugin\views\filter;

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\views\Plugin\views\filter\InOperator;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
Expand All @@ -14,13 +15,14 @@
* @ViewsFilter("tide_enhanced_mime_type_filter")
*/
class EnhancedMineTypeFilter extends InOperator {
use StringTranslationTrait;

/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$this->valueTitle = t('Enhanced MIME Type Filter');
$this->valueTitle = $this->t('Enhanced MIME Type Filter');
$this->definition['options callback'] = [$this, 'generateOptions'];
}

Expand Down
7 changes: 3 additions & 4 deletions tide_core.install
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,6 @@ function tide_core_update_8030() {
->getStorage('entity_view_display');
$skipped_items = ['title', 'uuid', 'created'];
foreach ($node_types as $node_type_id => $node_type) {
$order = [];
$entity_view_display_id = 'node.' . $node_type_id . '.default';
$field_name = 'field_' . $node_type_id . '_intro_text';
// Some of fields named as field_{node_type_id}_intro_text,
Expand Down Expand Up @@ -921,7 +920,7 @@ function tide_core_update_8034() {
$config = \Drupal::configFactory()
->getEditable('field.storage.paragraph.field_paragraph_accordion_style');
$settings = $config->get('settings');
foreach ($settings['allowed_values'] as $key => &$allowed_value) {
foreach ($settings['allowed_values'] as &$allowed_value) {
if ($allowed_value['label'] == 'Basic') {
$allowed_value['label'] = 'Standard';
}
Expand Down Expand Up @@ -1003,7 +1002,7 @@ function tide_core_update_8038() {
}
$updated_rows = [];

foreach ($rows as $key => $row) {
foreach ($rows as $row) {
if ($row['name'] === 'Media' && !in_array('TideCallout', $row['items'])) {
// Insert tide_callout inside Media group toolbar.
array_splice($row['items'], 1, 0, 'TideCallout');
Expand Down Expand Up @@ -1106,7 +1105,7 @@ function tide_core_update_8043() {
}
$updated_rows = [];

foreach ($rows as $key => $row) {
foreach ($rows as $row) {
if ($row['name'] === 'Tools' && !in_array('Maximize', $row['items'])) {
// Insert Maximise inside Tools group toolbar.
array_splice($row['items'], 3, 0, 'Maximize');
Expand Down