Skip to content
Snippets Groups Projects
Commit 597f779a authored by Steven Ayers's avatar Steven Ayers
Browse files

Issue #3415288 by Rohit Sankhla: Issues reported by phpstan

parent 036ef522
No related branches found
No related tags found
1 merge request!36Issue #3415288 by bluegeek9: Issues reported by phpstan
Pipeline #260846 passed with warnings
Showing
with 129 additions and 72 deletions
genc
......@@ -44,9 +44,9 @@ Tokens
* Custom message arguments (Custom callbacks)
When creating a message, it's possible to store custom arguments that will be
replaced when presenting the message.
E.g. If the message was created with an argument called "@sometext", it will
E.g. If the message was created with an argument called "@some_text", it will
get inserted to the message text (On display time) whenever the string
"@sometext" is encountered.
"@some_text" is encountered.
This method also supports custom call-back functions with optional arguments
stored on the message; In order to use a callback, create the message with
an argument such as:
......
......@@ -14,12 +14,13 @@ function message_uninstall() {
}
/**
* Fixes the typo in 'adminster messages' permission.
* Fixes the typo in 'administer messages' permission.
*/
function message_update_8100() {
$entityTypeManager = \Drupal::service('entity_type.manager');
$roles = $entityTypeManager->getStorage('user_role')->loadMultiple();
foreach ($roles as $role) {
// cspell:ignore adminster
if ($role->hasPermission('adminster messages')) {
$role->revokePermission('adminster messages');
$role->grantPermission('administer messages');
......
......@@ -25,7 +25,7 @@ function message_help($route_name, RouteMatchInterface $route_match) {
$output .= '<dt>' . t('General') . '</dt>';
$output .= '<dd>' . t('There are three main use cases for the message stack.') . '</dd>';
$output .= '<dt>' . t('Logging and Displaying System Events') . '</dt>';
$output .= '<dd>' . t('The basic use case for the message stack is <em>a tool for logging and displaying system events</em>. The events may be user initiated (e.g. a page is created) or system initiated. User-initiated events are sometimes called activity streams. The <a href=":newsfeed">News Feed at Facebook</a> is a an example of an activity stream and Google has launched its own tool for tracking changes to files and folders in Google Drive.', [':newsfeed' => 'https://en.wikipedia.org/wiki/List_of_Facebook_features#News_Feed']) . '</dd>';
$output .= '<dd>' . t('The basic use case for the message stack is <em>a tool for logging and displaying system events</em>. The events may be user initiated (e.g. a page is created) or system initiated. User-initiated events are sometimes called activity streams. The <a href=":news_feed">News Feed at Facebook</a> is a an example of an activity stream and Google has launched its own tool for tracking changes to files and folders in Google Drive.', [':news_feed' => 'https://en.wikipedia.org/wiki/List_of_Facebook_features#News_Feed']) . '</dd>';
$output .= '<dt>' . t('Notifying users when messages are generated') . '</dt>';
$output .= '<dd>' . t('A second major use case is to <em>notify recipients when messages are generated</em>. This functionality is provided by the <a href=":message-notify"> Message Notify</a> module which provides a method for sending a message via a notifier plugin. Message Notify comes with plugins for email and SMS and may be extended to other transport mechanisms as required. Message Notify includes an example module that demonstrates the usage of notifier plugins. The module also provides hook support for the Rules module, which may be an option for site builders who are familiar with the Rules module or who do not want to use Message Notify methods directly in their code.', [':message-notify' => 'https://www.drupal.org/project/message_notify']) . '</dd>';
$output .= '<dt>' . t('Notifying users who subscribe to certain content') . '</dt>';
......
......@@ -206,7 +206,7 @@ class Message extends ContentEntityBase implements MessageInterface {
$fields['arguments'] = BaseFieldDefinition::create('map')
->setLabel(t('Arguments'))
->setDescription(t('Holds the arguments of the message in serialise format.'));
->setDescription(t('Holds the arguments of the message in serialize format.'));
return $fields;
}
......
......@@ -85,7 +85,7 @@ class MessageTemplate extends ConfigEntityBundleBase implements MessageTemplateI
protected $description;
/**
* The serialised text of the message template.
* The serialized text of the message template.
*
* @var array
*/
......@@ -147,7 +147,7 @@ class MessageTemplate extends ConfigEntityBundleBase implements MessageTemplateI
* - 'token options': Array with options to be passed to
* token_replace().
*
* Tokens settings assigned to message-template can be overriden by the ones
* Tokens settings assigned to message-template can be overridden by the ones
* assigned to the message.
*
* @var array
......
......@@ -14,7 +14,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Configure file system settings for this site.
*/
class MessageSettingsForm extends ConfigFormBase {
final class MessageSettingsForm extends ConfigFormBase {
/**
* The entity type manager.
......@@ -86,7 +86,7 @@ class MessageSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
return new self(
$container->get('config.factory'),
$container->get('entity_type.manager'),
$container->get('plugin.manager.message.purge'),
......
......@@ -14,7 +14,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Form controller for node type forms.
*/
class MessageTemplateForm extends EntityForm {
final class MessageTemplateForm extends EntityForm {
/**
* The entity being used by this form.
......@@ -44,7 +44,7 @@ class MessageTemplateForm extends EntityForm {
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
return new self(
$container->get('plugin.manager.message.purge')
);
}
......
......@@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -15,7 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*
* @see \Drupal\Message\Entity\Message
*/
class MessageListBuilder extends EntityListBuilder {
final class MessageListBuilder extends EntityListBuilder {
/**
* The date service.
......@@ -24,6 +25,13 @@ class MessageListBuilder extends EntityListBuilder {
*/
protected $dateService;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Creates a Message ListBuilder.
*
......@@ -35,15 +43,19 @@ class MessageListBuilder extends EntityListBuilder {
* The date service.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
*/
public function __construct(
EntityTypeInterface $entity_type,
EntityStorageInterface $storage,
DateFormatter $date_service,
TranslationInterface $string_translation) {
TranslationInterface $string_translation,
LanguageManagerInterface $language_manager) {
parent::__construct($entity_type, $storage);
$this->dateService = $date_service;
$this->languageManager = $language_manager;
$this->setStringTranslation($string_translation);
}
......@@ -51,11 +63,12 @@ class MessageListBuilder extends EntityListBuilder {
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
return new self(
$entity_type,
$container->get('entity_type.manager')->getStorage($entity_type->id()),
$container->get('date.formatter'),
$container->get('string_translation')
$container->get('string_translation'),
$container->get('language_manager')
);
}
......@@ -80,7 +93,7 @@ class MessageListBuilder extends EntityListBuilder {
],
];
if (\Drupal::languageManager()->isMultilingual()) {
if ($this->languageManager->isMultilingual()) {
$header['language_name'] = [
'data' => $this->t('Language'),
'class' => [RESPONSIVE_PRIORITY_LOW],
......
......@@ -3,12 +3,9 @@
namespace Drupal\message;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Base implementation for MessagePurge plugins.
......@@ -38,41 +35,6 @@ abstract class MessagePurgeBase extends PluginBase implements MessagePurgeInterf
*/
protected $queue;
/**
* Constructs a MessagePurgeBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\Query\QueryInterface $message_query
* The entity query object for message items.
* @param \Drupal\Core\Queue\QueueInterface $queue
* The message deletion queue.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryInterface $message_query, QueueInterface $queue) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->messageQuery = $message_query;
$this->queue = $queue;
$this->setConfiguration($configuration);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager')->getStorage('message')->getQuery(),
$container->get('queue')->get('message_delete')
);
}
/**
* {@inheritdoc}
*/
......
......@@ -27,15 +27,12 @@ interface MessagePurgeInterface extends ConfigurableInterface, PluginFormInterfa
public function fetch(MessageTemplateInterface $template);
/**
* Process the purgeable messages.
* Process the purge-able messages.
*
* Normally this is a bulk delete operation.
*
* @param array $ids
* The message IDs to be processed.
*
* @return bool
* The result of the process.
*/
public function process(array $ids);
......
......@@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*
* @see \Drupal\message\Entity\MessageTemplate
*/
class MessageTemplateListBuilder extends ConfigEntityListBuilder {
final class MessageTemplateListBuilder extends ConfigEntityListBuilder {
/**
* Creates a Message Template ListBuilder.
......@@ -40,7 +40,7 @@ class MessageTemplateListBuilder extends ConfigEntityListBuilder {
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
return new self(
$entity_type,
$container->get('entity_type.manager')->getStorage($entity_type->id()),
$container->get('string_translation')
......
......@@ -19,7 +19,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
* description = @Translation("Delete messages older than a given amount of days."),
* )
*/
class Days extends MessagePurgeBase {
final class Days extends MessagePurgeBase {
/**
* The request stack.
......@@ -47,13 +47,17 @@ class Days extends MessagePurgeBase {
public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryInterface $message_query, QueueInterface $queue, RequestStack $request_stack) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $message_query, $queue);
$this->requestStack = $request_stack;
$this->messageQuery = $message_query;
$this->queue = $queue;
$this->setConfiguration($configuration);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
return new self(
$configuration,
$plugin_id,
$plugin_definition,
......
......@@ -2,9 +2,12 @@
namespace Drupal\message\Plugin\MessagePurge;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Queue\QueueInterface;
use Drupal\message\MessagePurgeBase;
use Drupal\message\MessageTemplateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Maximal (approximate) amount of messages.
......@@ -17,6 +20,41 @@ use Drupal\message\MessageTemplateInterface;
*/
class Quota extends MessagePurgeBase {
/**
* Constructs a MessagePurgeBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\Query\QueryInterface $message_query
* The entity query object for message items.
* @param \Drupal\Core\Queue\QueueInterface $queue
* The message deletion queue.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryInterface $message_query, QueueInterface $queue) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->messageQuery = $message_query;
$this->queue = $queue;
$this->setConfiguration($configuration);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new self(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager')->getStorage('message')->getQuery(),
$container->get('queue')->get('message_delete')
);
}
/**
* {@inheritdoc}
*/
......
......@@ -23,7 +23,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* cron = {"time" = 10}
* )
*/
class MessageCheckAndDeleteWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {
final class MessageCheckAndDeleteWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* The message storage handler.
......@@ -53,7 +53,7 @@ class MessageCheckAndDeleteWorker extends QueueWorkerBase implements ContainerFa
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
return new self(
$configuration,
$plugin_id,
$plugin_definition,
......
......@@ -20,7 +20,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* cron = {"time" = 10}
* )
*/
class MessageDeletionWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {
final class MessageDeletionWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* The message storage handler.
......@@ -50,7 +50,7 @@ class MessageDeletionWorker extends QueueWorkerBase implements ContainerFactoryP
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
return new self(
$configuration,
$plugin_id,
$plugin_definition,
......
......@@ -19,10 +19,12 @@ class MessageTemplateDestination extends EntityConfigBase {
* {@inheritdoc}
*/
protected function updateEntity(EntityInterface $entity, Row $row) {
parent::updateEntity($entity, $row);
$ret = parent::updateEntity($entity, $row);
if ($row->getDestinationProperty('text')) {
$entity->set('text', $row->getDestinationProperty('text'));
}
return $ret;
}
}
......@@ -2,9 +2,13 @@
namespace Drupal\message\Plugin\migrate\process;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Message template text process plugin.
......@@ -13,7 +17,42 @@ use Drupal\migrate\Row;
* id = "d7_message_template_text"
* )
*/
class MessageTemplateProcessText extends ProcessPluginBase {
class MessageTemplateProcessText extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The migration.
*
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migration = $migration;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new self(
$configuration,
$plugin_id,
$plugin_definition,
$migration,
$container->get('entity_type.manager'));
}
/**
* {@inheritdoc}
......@@ -22,7 +61,7 @@ class MessageTemplateProcessText extends ProcessPluginBase {
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$source = $row->getSource();
$message_tpl = \Drupal::entityTypeManager()->getStorage('message_template')->load($row->getSource()['name']);
$message_tpl = $this->entityTypeManager->getStorage('message_template')->load($row->getSource()['name']);
$texts = [];
if (!empty($message_tpl)) {
......
......@@ -57,7 +57,7 @@ class MessageTemplateSource extends DrupalSqlBase {
'name' => $this->t('Unique message type name.'),
'category' => $this->t('Message type category.'),
'description' => $this->t('Message type description.'),
'argument_keys' => $this->t('Message type argumented keys.'),
'argument_keys' => $this->t('Message type augmented keys.'),
'language' => $this->t('Message type language.'),
'status' => $this->t('Message type status.'),
'module' => $this->t('Message type module.'),
......@@ -66,7 +66,7 @@ class MessageTemplateSource extends DrupalSqlBase {
'message_text_value' => $this->t('Message text value.'),
'message_text_format' => $this->t('Message text format.'),
'delta' => $this->t('Message text number.'),
'concat_id' => $this->t('Concats the id of the message type and the delta of the message text.'),
'concat_id' => $this->t('Concat the id of the message type and the delta of the message text.'),
];
}
......
......@@ -24,7 +24,7 @@ class MessageCreateTest extends MessageTestBase {
public function setUp():void {
parent::setUp();
$this->user = $this->drupalcreateuser();
$this->user = $this->drupalCreateUser();
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment