diff --git a/message_subscribe.api.php b/message_subscribe.api.php
index fcf3010..1814e60 100644
--- a/message_subscribe.api.php
+++ b/message_subscribe.api.php
@@ -33,7 +33,10 @@ use Drupal\message_subscribe\Subscribers\DeliveryCandidateInterface;
function hook_message_subscribe_get_subscribers(MessageInterface $message, array $subscribe_options = [], array $context = []) {
return [
2 => new DeliveryCandidate(['subscribe_node'], ['sms'], 2),
- 7 => new DeliveryCandidate(['subscribe_og', 'subscribe_user'], ['sms', 'email'], 7),
+ 7 => new DeliveryCandidate(
+ ['subscribe_og', 'subscribe_user'],
+ ['sms', 'email'],
+ 7),
];
}
diff --git a/message_subscribe_email/message_subscribe_email.info.yml b/message_subscribe_email/message_subscribe_email.info.yml
index ac3854a..d41e3b6 100644
--- a/message_subscribe_email/message_subscribe_email.info.yml
+++ b/message_subscribe_email/message_subscribe_email.info.yml
@@ -1,4 +1,5 @@
name: 'Message subscribe email'
+description: 'Message subscribe email'
core_version_requirement: ^9 || ^10
package: Message
dependencies:
diff --git a/message_subscribe_email/message_subscribe_email.module b/message_subscribe_email/message_subscribe_email.module
index 78df915..13426aa 100644
--- a/message_subscribe_email/message_subscribe_email.module
+++ b/message_subscribe_email/message_subscribe_email.module
@@ -32,7 +32,7 @@ function message_subscribe_email_flag_action_access($action, FlagInterface $flag
if (empty($sid) && $account->isAnonymous()) {
// Ensure something is in $_SESSION, otherwise the session ID will
// not persist.
- // TODO: Replace this with something cleaner once core provides it.
+ // @todo Replace this with something cleaner once core provides it.
// See https://www.drupal.org/node/2865991.
$_SESSION['flag'] = TRUE;
@@ -60,8 +60,6 @@ function message_subscribe_email_flag_action_access($action, FlagInterface $flag
/**
* Implements hook_message_subscribe_get_subscribers_alter().
- *
- * Filters out subscribes to show only email subscribers.
*/
function message_subscribe_email_message_subscribe_get_subscribers_alter(array &$uids, array $values) {
if (empty($uids)) {
@@ -87,7 +85,10 @@ function message_subscribe_email_message_subscribe_get_subscribers_alter(array &
);
$debug && \Drupal::logger('message_subscribe_email')->debug(
'Gathering email subscriptions using flags: @flags for users: @uids',
- ['@flags' => implode(', ', $flag_ids), '@uids' => implode(', ', array_keys($uids))]
+ [
+ '@flags' => implode(', ', $flag_ids),
+ '@uids' => implode(', ', array_keys($uids)),
+ ]
);
$all_email_subscribers = [];
diff --git a/message_subscribe_email/tests/src/Functional/ViewsTest.php b/message_subscribe_email/tests/src/Functional/ViewsTest.php
index e91d53c..8ba4dcf 100644
--- a/message_subscribe_email/tests/src/Functional/ViewsTest.php
+++ b/message_subscribe_email/tests/src/Functional/ViewsTest.php
@@ -2,6 +2,7 @@
namespace Drupal\Tests\message_subscribe_email\Functional;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\BrowserTestBase;
@@ -15,6 +16,7 @@ class ViewsTest extends BrowserTestBase {
use ContentTypeCreationTrait;
use NodeCreationTrait;
+ use StringTranslationTrait;
/**
* {@inheritdoc}
@@ -101,7 +103,7 @@ class ViewsTest extends BrowserTestBase {
$this->assertSession()->statusCodeEquals(200);
$this->drupalGet('user/' . $user->id() . '/message-subscribe/subscribe_node');
$this->assertSession()->statusCodeEquals(200);
- $this->assertSession()->pageTextContains(t('You are not subscribed to any items.'));
+ $this->assertSession()->pageTextContains($this->t('You are not subscribed to any items.'));
}
// Add a node, and subscribe user 2 to that node.
@@ -113,19 +115,19 @@ class ViewsTest extends BrowserTestBase {
$this->drupalGet('user/' . $users[2]->id() . '/message-subscribe/subscribe_node');
// The node title (label) appears on the list of subscribed content.
$this->assertSession()->pageTextContains($node->label());
- $this->assertSession()->pageTextContains(t("Don't send email"));
+ $this->assertSession()->pageTextContains($this->t("Don't send email"));
// Subscribe user 2 to user 1.
$flag = $this->flagService->getFlagById('subscribe_user');
$this->flagService->flag($flag, $users[1], $users[2]);
$this->drupalGet('user/' . $users[2]->id() . '/message-subscribe/subscribe_user');
$this->assertSession()->pageTextContains($users[1]->label());
- $this->assertSession()->pageTextContains(t("Don't send email"));
+ $this->assertSession()->pageTextContains($this->t("Don't send email"));
// Login user 3.
$this->drupalLogin($users[3]);
$this->drupalGet('user/' . $users[3]->id() . '/message-subscribe');
- $this->assertSession()->pageTextContains(t('You are not subscribed to any items.'));
+ $this->assertSession()->pageTextContains($this->t('You are not subscribed to any items.'));
$flag = $this->flagService->getFlagById('subscribe_node');
$this->flagService->flag($flag, $node, $users[3]);
$this->drupalGet('user/' . $users[3]->id() . '/message-subscribe');
diff --git a/message_subscribe_email/tests/src/FunctionalJavascript/MessageSubscribeEmailTest.php b/message_subscribe_email/tests/src/FunctionalJavascript/MessageSubscribeEmailTest.php
index 63fa06b..6ebb6f9 100644
--- a/message_subscribe_email/tests/src/FunctionalJavascript/MessageSubscribeEmailTest.php
+++ b/message_subscribe_email/tests/src/FunctionalJavascript/MessageSubscribeEmailTest.php
@@ -2,6 +2,7 @@
namespace Drupal\Tests\message_subscribe_email\FunctionalJavascript;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
@@ -11,6 +12,8 @@ use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
*/
class MessageSubscribeEmailTest extends WebDriverTestBase {
+ use StringTranslationTrait;
+
/**
* {@inheritdoc}
*/
@@ -85,17 +88,17 @@ class MessageSubscribeEmailTest extends WebDriverTestBase {
$this->drupalGet($this->nodes[2]->toUrl());
// Subscribe to the node.
- $this->clickLink(t('Subscribe'));
+ $this->clickLink($this->t('Subscribe'));
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertTrue((bool) $this->flagService->getFlagging($flag, $this->nodes[2], $this->users[2]));
// Unsubscribe from the node.
- $this->clickLink(t('Unsubscribe'));
+ $this->clickLink($this->t('Unsubscribe'));
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertFalse((bool) $this->flagService->getFlagging($flag, $this->nodes[2], $this->users[2]));
// Subscribe again!
- $this->clickLink(t('Subscribe'));
+ $this->clickLink($this->t('Subscribe'));
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertTrue((bool) $this->flagService->getFlagging($flag, $this->nodes[2], $this->users[2]));
}
diff --git a/message_subscribe_example/README.md b/message_subscribe_example/README.md
index 7887817..c9b2ebe 100644
--- a/message_subscribe_example/README.md
+++ b/message_subscribe_example/README.md
@@ -21,13 +21,16 @@ This code starts with some of the example modules in the Message stack, changing
Add the following to your composer.json to add necessary patches:
```
- "patches": {
- "drupal/message_subscribe": {
- "Issue #2928789: Fatal exception with flag module": "https://www.drupal.org/files/issues/2019-12-15/account_id_2928789_0.patch",
- "Issue #3101137: Fix endless loop": "https://www.drupal.org/files/issues/2019-12-15/3101137-fix-endless-loop.patch,
- "Issue #3101141: Message Subscribe Email removes all emails": "https://www.drupal.org/files/issues/2019-12-15/3101141-check-email-flag_0.patch"
- }
- },
+"patches": {
+ "drupal/message_subscribe": {
+ "Issue #2928789:Fatal exception with flag module":
+ "https://www.drupal.org/files/issues/2019-12-15/account_id_2928789_0.patch",
+ "Issue #3101137: Fix endless loop":
+ "https://www.drupal.org/files/issues/2019-12-15/3101137-fix-endless-loop.patch,
+ "Issue #3101141: Message Subscribe Email removes all emails":
+ "https://www.drupal.org/files/issues/2019-12-15/3101141-check-email-flag_0.patch"
+ }
+},
```
@@ -58,4 +61,3 @@ Review the code in `message_implementation.module` to see what hooks are being
used to generate messages. You can alter them later as needed. Lots of examples
are provided, you won't use all of them, so remove and change as you
like.
-
diff --git a/message_subscribe_example/message_subscribe_example.module b/message_subscribe_example/message_subscribe_example.module
index 791dfd4..533ca9a 100644
--- a/message_subscribe_example/message_subscribe_example.module
+++ b/message_subscribe_example/message_subscribe_example.module
@@ -10,23 +10,10 @@ use Drupal\node\Entity\Node;
use Drupal\comment\Entity\Comment;
use Drupal\user\Entity\User;
use Drupal\message\Entity\Message;
-use Drupal\message\MessageInterface;
use Drupal\message_subscribe\Subscribers\DeliveryCandidate;
/**
* Implements hook_message_subscribe_get_subscribers_alter().
- *
- * Alter the subscribers list.
- *
- * @param \Drupal\message_subscribe\Subscribers\DeliveryCandidateInterface[] &$uids
- * The array of delivery candidates as defined by
- * `hook_message_subscribe_get_subscribers()`.
- * @param array $values
- * A keyed array of values containing:
- * - 'context' - The context array.
- * - 'entity_type' - The entity type ID.
- * - 'entity' - The entity object
- * - 'subscribe_options' - The subscribe options array.
*/
function message_subscribe_example_message_subscribe_get_subscribers_alter(array &$uids, array $values) {
@@ -52,7 +39,7 @@ function message_subscribe_example_message_subscribe_get_subscribers_alter(array
// a custom list (see hook_user_insert() below). This is just an
// illustration of another solution.
$query = \Drupal::entityQuery('user')
- ->condition('status', 1);
+ ->condition('status', 1);
$query->condition('roles', 'administrators');
$admin_uids = $query->execute();
foreach ($admin_uids as $uid) {
@@ -69,7 +56,10 @@ function message_subscribe_example_node_insert(Node $node) {
// Add a message for the node author.
$template = $node->isPublished() ? 'publish_node' : 'create_node';
- $message = Message::create(['template' => $template, 'uid' => $node->getOwnerId()]);
+ $message = Message::create([
+ 'template' => $template,
+ 'uid' => $node->getOwnerId(),
+ ]);
$message->set('field_node_reference', $node);
$message->set('field_published', $node->isPublished());
$message->save();
@@ -84,7 +74,7 @@ function message_subscribe_example_node_insert(Node $node) {
if (in_array($node->bundle(), ['article'])) {
// Find all active users.
$query = \Drupal::entityQuery('user')
- ->condition('status', 1);
+ ->condition('status', 1);
$uids = $query->execute();
$users = User::loadMultiple($uids);
@@ -165,7 +155,10 @@ function message_subscribe_example_comment_insert(Comment $comment) {
// Create a message for the node author.
$node = $comment->get('entity_id')->first()->get('entity')->getTarget()->getValue();
- $message = Message::create(['template' => 'create_comment', 'uid' => $node->getOwnerId()]);
+ $message = Message::create([
+ 'template' => 'create_comment',
+ 'uid' => $node->getOwnerId(),
+ ]);
$message->set('field_comment_reference', $comment);
$message->set('field_published', $comment->isPublished());
$message->save();
@@ -195,7 +188,7 @@ function message_subscribe_example_user_insert(User $account) {
// or if you're automatically flagging administrators. It's just another
// illustration of things that can be done.
$query = \Drupal::entityQuery('user')
- ->condition('status', 1);
+ ->condition('status', 1);
$query->condition('roles', 'administrator');
$admin_uids = $query->execute();
@@ -211,7 +204,10 @@ function message_subscribe_example_user_insert(User $account) {
}
// Queue messages to our custom list of subscribers.
- $message = Message::create(['template' => 'user_register', 'uid' => $account->id()]);
+ $message = Message::create([
+ 'template' => 'user_register',
+ 'uid' => $account->id(),
+ ]);
$message->set('field_user', $account);
$message->set('field_published', $account->isActive());
$message->save();
diff --git a/message_subscribe_ui/src/Controller/SubscriptionController.php b/message_subscribe_ui/src/Controller/SubscriptionController.php
index d6a8a38..af92473 100644
--- a/message_subscribe_ui/src/Controller/SubscriptionController.php
+++ b/message_subscribe_ui/src/Controller/SubscriptionController.php
@@ -180,7 +180,7 @@ class SubscriptionController extends ControllerBase {
$prefix = $this->config->get('flag_prefix');
// View name + display ID.
$default_view_name = $prefix . '_' . $entity_type . ':default';
- list($view_name, $display_id) = explode(':', $flag->getThirdPartySetting('message_subscribe_ui', 'view_name', $default_view_name));
+ [$view_name, $display_id] = explode(':', $flag->getThirdPartySetting('message_subscribe_ui', 'view_name', $default_view_name));
if (!$view = Views::getView($view_name)) {
// View doesn't exist.
diff --git a/message_subscribe_ui/src/Plugin/Block/Subscriptions.php b/message_subscribe_ui/src/Plugin/Block/Subscriptions.php
index 9eccc18..42f25d9 100644
--- a/message_subscribe_ui/src/Plugin/Block/Subscriptions.php
+++ b/message_subscribe_ui/src/Plugin/Block/Subscriptions.php
@@ -157,7 +157,10 @@ class Subscriptions extends BlockBase implements FormInterface, ContainerFactory
$entities += $entity->referencedEntities();
$form['description'] = [
'#type' => 'markup',
- '#markup' => $this->t('Manage all subscriptions.', [':url' => Url::fromRoute('message_subscribe_ui.tab', ['user' => \Drupal::currentUser()->id()])->toString()]),
+ '#markup' => $this->t('Manage all subscriptions.', [
+ ':url' => Url::fromRoute('message_subscribe_ui.tab',
+ ['user' => $this->currentUser->id()])->toString(),
+ ]),
];
$form['subscriptions'] = [
'#type' => 'container',
@@ -232,7 +235,7 @@ class Subscriptions extends BlockBase implements FormInterface, ContainerFactory
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
- // TODO: Implement validateForm() method.
+ // @todo Implement validateForm() method.
}
/**
diff --git a/message_subscribe_ui/tests/src/Functional/SubscriptionsBlockTest.php b/message_subscribe_ui/tests/src/Functional/SubscriptionsBlockTest.php
index 078a21c..c8fe20e 100644
--- a/message_subscribe_ui/tests/src/Functional/SubscriptionsBlockTest.php
+++ b/message_subscribe_ui/tests/src/Functional/SubscriptionsBlockTest.php
@@ -2,6 +2,7 @@
namespace Drupal\Tests\message_subscribe_ui\Functional;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\entity_test\FieldStorageDefinition;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\Tests\BrowserTestBase;
@@ -16,6 +17,7 @@ class SubscriptionsBlockTest extends BrowserTestBase {
use TaxonomyTestTrait;
use EntityReferenceTestTrait;
+ use StringTranslationTrait;
/**
* Admin user.
@@ -96,7 +98,8 @@ class SubscriptionsBlockTest extends BrowserTestBase {
],
];
$this->createEntityReferenceField('node', 'article', 'field_terms_' . $i, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinition::CARDINALITY_UNLIMITED);
- foreach (range(1, 5) as $j) {
+
+ for ($j = 1; $j <= 5; $j++) {
$this->terms[] = $this->createTerm($vocab);
}
}
@@ -115,7 +118,7 @@ class SubscriptionsBlockTest extends BrowserTestBase {
]);
// Place the subscription block.
- $this->placeBlock('message_subscribe_ui_block', ['label' => t('Manage subscriptions')]);
+ $this->placeBlock('message_subscribe_ui_block', ['label' => $this->t('Manage subscriptions')]);
$this->flagService = $this->container->get('flag');
}
@@ -127,24 +130,24 @@ class SubscriptionsBlockTest extends BrowserTestBase {
// Check that the block is empty when viewing another user.
$this->drupalGet($this->adminUser->toUrl());
- $this->assertSession()->pageTextNotContains(t('Manage subscriptions'));
- $this->assertSession()->pageTextNotContains(t('Subscribe to @label', ['@label' => $this->adminUser->getDisplayName()]));
+ $this->assertSession()->pageTextNotContains($this->t('Manage subscriptions'));
+ $this->assertSession()->pageTextNotContains($this->t('Subscribe to @label', ['@label' => $this->adminUser->getDisplayName()]));
$this->drupalGet($this->node->toUrl());
- $this->assertSession()->pageTextContains(t('Manage subscriptions'));
+ $this->assertSession()->pageTextContains($this->t('Manage subscriptions'));
foreach ([1, 3, 7, 9] as $i) {
- $this->assertSession()->pageTextContains(t('Subscribe to @title', ['@title' => $this->terms[$i]->label()]));
+ $this->assertSession()->pageTextContains($this->t('Subscribe to @title', ['@title' => $this->terms[$i]->label()]));
}
// The subscription to the node itself should be available.
- $this->assertSession()->pageTextContains(t('Subscribe to @title', ['@title' => $this->node->label()]));
- $this->assertSession()->pageTextNotContains(t('Subscribe to @label', ['@label' => $this->adminUser->getDisplayName()]));
+ $this->assertSession()->pageTextContains($this->t('Subscribe to @title', ['@title' => $this->node->label()]));
+ $this->assertSession()->pageTextNotContains($this->t('Subscribe to @label', ['@label' => $this->adminUser->getDisplayName()]));
// Subscribe to 1 and 7.
$edit = [
'subscriptions[taxonomy_term][' . $this->terms[1]->id() . ']' => TRUE,
'subscriptions[taxonomy_term][' . $this->terms[7]->id() . ']' => TRUE,
];
- $this->submitForm($edit, t('Save'));
+ $this->submitForm($edit, $this->t('Save'));
$flag = $this->flagService->getFlagById('subscribe_term');
foreach ([1, 3, 7, 9] as $i) {
$term = $this->terms[$i];
@@ -152,13 +155,13 @@ class SubscriptionsBlockTest extends BrowserTestBase {
$this->assertNotEmpty($this->flagService->getEntityFlaggings($flag, $term, $this->webUser));
// Subscriptions should be checked.
- $this->assertSession()->checkboxChecked(t('Subscribe to @label', ['@label' => $term->label()]));
+ $this->assertSession()->checkboxChecked($this->t('Subscribe to @label', ['@label' => $term->label()]));
}
else {
$this->assertEmpty($this->flagService->getEntityFlaggings($flag, $term, $this->webUser));
// Subscriptions should not be unchecked.
- $this->assertSession()->checkboxNotChecked(t('Subscribe to @label', ['@label' => $term->label()]));
+ $this->assertSession()->checkboxNotChecked($this->t('Subscribe to @label', ['@label' => $term->label()]));
}
}
@@ -170,19 +173,19 @@ class SubscriptionsBlockTest extends BrowserTestBase {
$role->save();
$this->drupalGet($this->node->toUrl());
- $this->assertSession()->pageTextContains(t('Subscribe to @label', ['@label' => $this->adminUser->getDisplayName()]));
+ $this->assertSession()->pageTextContains($this->t('Subscribe to @label', ['@label' => $this->adminUser->getDisplayName()]));
$this->drupalGet($this->adminUser->toUrl());
- $this->assertSession()->pageTextContains(t('Subscribe to @label', ['@label' => $this->adminUser->getDisplayName()]));
+ $this->assertSession()->pageTextContains($this->t('Subscribe to @label', ['@label' => $this->adminUser->getDisplayName()]));
$edit = [
'subscriptions[user][' . $this->adminUser->id() . ']' => TRUE,
];
- $this->submitForm($edit, t('Save'));
+ $this->submitForm($edit, $this->t('Save'));
$flag = $this->flagService->getFlagById('subscribe_user');
$this->assertNotEmpty($this->flagService->getEntityFlaggings($flag, $this->adminUser, $this->webUser));
// Subscriptions should be checked.
- $this->assertSession()->checkboxChecked(t('Subscribe to @label', ['@label' => $this->adminUser->getDisplayName()]));
+ $this->assertSession()->checkboxChecked($this->t('Subscribe to @label', ['@label' => $this->adminUser->getDisplayName()]));
// Remove node and taxonomy flagging, and recheck the node page.
$role->revokePermission('flag subscribe_term');
@@ -193,11 +196,11 @@ class SubscriptionsBlockTest extends BrowserTestBase {
$this->drupalGet($this->node->toUrl());
foreach ([1, 3, 7, 9] as $i) {
- $this->assertSession()->pageTextNotContains(t('Subscribe to @title', ['@title' => $this->terms[$i]->label()]));
+ $this->assertSession()->pageTextNotContains($this->t('Subscribe to @title', ['@title' => $this->terms[$i]->label()]));
}
// The subscription to the node itself should not be available.
- $this->assertSession()->pageTextNotContains(t('Subscribe to @title', ['@title' => $this->node->label()]));
- $this->assertSession()->pageTextContains(t('Subscribe to @label', ['@label' => $this->adminUser->getDisplayName()]));
+ $this->assertSession()->pageTextNotContains($this->t('Subscribe to @title', ['@title' => $this->node->label()]));
+ $this->assertSession()->pageTextContains($this->t('Subscribe to @label', ['@label' => $this->adminUser->getDisplayName()]));
}
}
diff --git a/src/Form/MessageSubscribeAdminSettings.php b/src/Form/MessageSubscribeAdminSettings.php
index f878dc1..e53f03c 100644
--- a/src/Form/MessageSubscribeAdminSettings.php
+++ b/src/Form/MessageSubscribeAdminSettings.php
@@ -2,14 +2,48 @@
namespace Drupal\message_subscribe\Form;
+use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
+use Drupal\message_notify\Plugin\Notifier\Manager;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Settings form for Message Subscribe.
*/
class MessageSubscribeAdminSettings extends ConfigFormBase {
+
+ /**
+ * The notifier plugin manager.
+ *
+ * @var \Drupal\message_notify\Plugin\Notifier\Manager
+ */
+ protected $notifierManager;
+
+ /**
+ * Constructs a new \Drupal\message_subscribe\Form\MessageSubscribeAdminSettings object.
+ *
+ * @param Drupal\Core\Config\ConfigFactoryInterface $config_factory
+ * The Config Factory.
+ * @param Drupal\message_notify\Plugin\Notifier\Manager $notifier_manager
+ * The notification manager of message_notify.
+ */
+ public function __construct(ConfigFactoryInterface $config_factory, Manager $notifier_manager) {
+ parent::__construct($config_factory);
+ $this->notifierManager = $notifier_manager;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('config.factory'),
+ $container->get('plugin.message_notify.notifier.manager')
+ );
+ }
+
/**
* {@inheritdoc}
*/
@@ -43,9 +77,7 @@ class MessageSubscribeAdminSettings extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
-
- /** @var \Drupal\Core\Plugin\DefaultPluginManager $message_notifiers */
- $message_notifiers = \Drupal::service('plugin.message_notify.notifier.manager');
+ $message_notifiers = $this->notifierManager;
$options = array_map(function ($definition) {
return $definition['title'];
}, $message_notifiers->getDefinitions());
diff --git a/src/Subscribers.php b/src/Subscribers.php
index 0bf6122..9b195e4 100644
--- a/src/Subscribers.php
+++ b/src/Subscribers.php
@@ -140,8 +140,8 @@ class Subscribers implements SubscribersInterface {
* {@inheritdoc}
*/
public function sendMessage(EntityInterface $entity, MessageInterface $message, array $notify_options = [], array $subscribe_options = [], array $context = []) {
- $use_queue = isset($subscribe_options['use queue']) ? $subscribe_options['use queue'] : $this->config->get('use_queue');
- $notify_message_owner = isset($subscribe_options['notify message owner']) ? $subscribe_options['notify message owner'] : $this->config->get('notify_own_actions');
+ $use_queue = $subscribe_options['use queue'] ?? $this->config->get('use_queue');
+ $notify_message_owner = $subscribe_options['notify message owner'] ?? $this->config->get('notify_own_actions');
// Save message by default.
$subscribe_options += [
@@ -239,7 +239,10 @@ class Subscribers implements SubscribersInterface {
];
$result = $this->messageNotifier->send($cloned_message, $options, $notifier_name);
- $this->debug($result ? 'Successfully sent message via notifier @notifier to user @uid' : 'Failed to send message via notifier @notifier to user @uid', ['@notifier' => $notifier_name, '@uid' => $uid]);
+ $this->debug($result ? 'Successfully sent message via notifier @notifier to user @uid' : 'Failed to send message via notifier @notifier to user @uid', [
+ '@notifier' => $notifier_name,
+ '@uid' => $uid,
+ ]);
// Check we didn't timeout.
if ($use_queue && $subscribe_options['queue']['end time'] && time() < $subscribe_options['queue']['end time']) {
@@ -271,7 +274,7 @@ class Subscribers implements SubscribersInterface {
*/
public function getSubscribers(EntityInterface $entity, MessageInterface $message, array $options = [], array &$context = []) {
$context = !empty($context) ? $context : $this->getBasicContext($entity, !empty($options['skip context']), $context);
- $notify_message_owner = isset($options['notify message owner']) ? $options['notify message owner'] : $this->config->get('notify_own_actions');
+ $notify_message_owner = $options['notify message owner'] ?? $this->config->get('notify_own_actions');
$uids = [];
diff --git a/src/SubscribersInterface.php b/src/SubscribersInterface.php
index 2971e2b..dde6466 100644
--- a/src/SubscribersInterface.php
+++ b/src/SubscribersInterface.php
@@ -59,18 +59,18 @@ interface SubscribersInterface {
* Example usage.
*
* @code
- * $subscribe_options['uids'] = array(
- * 1 => array(
- * 'notifiers' => array('email'),
- * ),
- * );
- * $context = array(
- * 'node' => array(1),
+ * $subscribe_options['uids'] = [
+ * 1 => [
+ * 'notifiers' => ['email'],
+ * ],
+ * ];
+ * $context = [
+ * 'node' => [1],
* // The node author.
- * 'user' => array(10),
+ * 'user' => [10],
* // Related taxonomy terms.
- * 'taxonomy_term' => array(100, 200, 300)
- * );
+ * 'taxonomy_term' => [100, 200, 300]
+ * ];
* @endcode
*/
public function sendMessage(EntityInterface $entity, MessageInterface $message, array $notify_options = [], array $subscribe_options = [], array $context = []);
diff --git a/tests/modules/message_subscribe_test/message_subscribe_test.info.yml b/tests/modules/message_subscribe_test/message_subscribe_test.info.yml
index 124b23a..eebc26a 100644
--- a/tests/modules/message_subscribe_test/message_subscribe_test.info.yml
+++ b/tests/modules/message_subscribe_test/message_subscribe_test.info.yml
@@ -3,5 +3,5 @@ description: 'Functionality to assist message subscribe testing.'
type: module
core_version_requirement: ^8 || ^9
dependencies:
- - message_subscribe
+ - message_subscribe:message_subscribe
package: Testing
diff --git a/tests/src/Functional/MenuTest.php b/tests/src/Functional/MenuTest.php
index d091e54..0647c50 100644
--- a/tests/src/Functional/MenuTest.php
+++ b/tests/src/Functional/MenuTest.php
@@ -2,6 +2,7 @@
namespace Drupal\Tests\message_subscribe\Functional;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
@@ -12,6 +13,8 @@ use Drupal\Tests\BrowserTestBase;
*/
class MenuTest extends BrowserTestBase {
+ use StringTranslationTrait;
+
/**
* {@inheritdoc}
*/
@@ -31,13 +34,13 @@ class MenuTest extends BrowserTestBase {
// Link should appear on main config page.
$this->drupalGet(Url::fromRoute('system.admin_config'));
- $this->assertSession()->linkExists(t('Message subscribe settings'));
+ $this->assertSession()->linkExists($this->t('Message subscribe settings'));
// Link should be on the message-specific overview page.
$this->drupalGet(Url::fromRoute('message.main_settings'));
- $this->assertSession()->linkExists(t('Message subscribe settings'));
+ $this->assertSession()->linkExists($this->t('Message subscribe settings'));
- $this->clickLink(t('Message subscribe settings'));
+ $this->clickLink($this->t('Message subscribe settings'));
$this->assertSession()->statusCodeEquals(200);
}
diff --git a/tests/src/Functional/UninstallTest.php b/tests/src/Functional/UninstallTest.php
index 8588168..8983669 100644
--- a/tests/src/Functional/UninstallTest.php
+++ b/tests/src/Functional/UninstallTest.php
@@ -2,6 +2,7 @@
namespace Drupal\Tests\message_subscribe\Functional;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
@@ -12,6 +13,8 @@ use Drupal\Tests\BrowserTestBase;
*/
class UninstallTest extends BrowserTestBase {
+ use StringTranslationTrait;
+
/**
* {@inheritdoc}
*/
@@ -36,11 +39,11 @@ class UninstallTest extends BrowserTestBase {
// Uninstall module.
$this->drupalGet('admin/modules/uninstall');
$this->assertSession()->statusCodeEquals(200);
- $this->submitForm(['uninstall[message_subscribe]' => TRUE], t('Uninstall'));
- $this->submitForm([], t('Uninstall'));
+ $this->submitForm(['uninstall[message_subscribe]' => TRUE], $this->t('Uninstall'));
+ $this->submitForm([], $this->t('Uninstall'));
// Validate Message Subscribe was uninstalled.
- $this->assertSession()->pageTextContains(t('The selected modules have been uninstalled.'));
+ $this->assertSession()->pageTextContains($this->t('The selected modules have been uninstalled.'));
$this->drupalGet(Url::fromRoute('message_subscribe.admin_settings'));
$this->assertSession()->statusCodeEquals(404);
}
diff --git a/tests/src/Kernel/SubscribersTest.php b/tests/src/Kernel/SubscribersTest.php
index fed1461..2cf9072 100644
--- a/tests/src/Kernel/SubscribersTest.php
+++ b/tests/src/Kernel/SubscribersTest.php
@@ -207,14 +207,14 @@ class SubscribersTest extends MessageSubscribeTestBase {
]);
$node = $this->nodes[0];
- $user1 = $this->users[1];
- $user2 = $this->users[2];
-
$uids = $this->messageSubscribers->getSubscribers($node, $message);
// Assert subscribers data.
$expected_uids = [
- $this->users[2]->id() => new DeliveryCandidate(['subscribe_node', 'subscribe_user'], [], $this->users[2]->id()),
+ $this->users[2]->id() => new DeliveryCandidate([
+ 'subscribe_node',
+ 'subscribe_user',
+ ], [], $this->users[2]->id()),
];
$this->assertEquals($uids, $expected_uids, 'All subscribers except for the triggering user were fetched.');
@@ -226,7 +226,10 @@ class SubscribersTest extends MessageSubscribeTestBase {
// Assert subscribers data.
$expected_uids = [
$this->users[1]->id() => new DeliveryCandidate(['subscribe_node'], [], $this->users[1]->id()),
- $this->users[2]->id() => new DeliveryCandidate(['subscribe_node', 'subscribe_user'], [], $this->users[2]->id()),
+ $this->users[2]->id() => new DeliveryCandidate([
+ 'subscribe_node',
+ 'subscribe_user',
+ ], [], $this->users[2]->id()),
];
$this->assertEquals($uids, $expected_uids, 'All subscribers including the triggering user were fetched.');
}
diff --git a/tests/src/Unit/Subscribers/DeliveryCandidateTest.php b/tests/src/Unit/Subscribers/DeliveryCandidateTest.php
index ad23222..83b441c 100644
--- a/tests/src/Unit/Subscribers/DeliveryCandidateTest.php
+++ b/tests/src/Unit/Subscribers/DeliveryCandidateTest.php
@@ -45,7 +45,10 @@ class DeliveryCandidateTest extends UnitTestCase {
$this->assertEquals(['foo' => 'foo'], $candidate->getFlags());
$this->assertInstanceOf(DeliveryCandidateInterface::class, $candidate->removeFlag('foo'));
$this->assertEmpty($candidate->getFlags());
- $this->assertInstanceOf(DeliveryCandidateInterface::class, $candidate->setFlags(['foo', 'bar']));
+ $this->assertInstanceOf(DeliveryCandidateInterface::class, $candidate->setFlags([
+ 'foo',
+ 'bar',
+ ]));
$this->assertEquals(['foo' => 'foo', 'bar' => 'bar'], $candidate->getFlags());
}
@@ -64,7 +67,10 @@ class DeliveryCandidateTest extends UnitTestCase {
$this->assertEquals(['foo' => 'foo'], $candidate->getNotifiers());
$this->assertInstanceOf(DeliveryCandidateInterface::class, $candidate->removeNotifier('foo'));
$this->assertEmpty($candidate->getNotifiers());
- $this->assertInstanceOf(DeliveryCandidateInterface::class, $candidate->setNotifiers(['foo', 'bar']));
+ $this->assertInstanceOf(DeliveryCandidateInterface::class, $candidate->setNotifiers([
+ 'foo',
+ 'bar',
+ ]));
$this->assertEquals(['foo' => 'foo', 'bar' => 'bar'], $candidate->getNotifiers());
}
diff --git a/tests/src/Unit/SubscribersTest.php b/tests/src/Unit/SubscribersTest.php
index f5be98f..20c18a9 100644
--- a/tests/src/Unit/SubscribersTest.php
+++ b/tests/src/Unit/SubscribersTest.php
@@ -4,21 +4,14 @@ namespace Drupal\Tests\message_subscribe\Unit;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
-use Drupal\Core\Entity\EntityInterface;
-use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
-use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
-use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Queue\QueueFactory;
use Drupal\flag\FlagInterface;
use Drupal\flag\FlagServiceInterface;
-use Drupal\message\Entity\Message;
use Drupal\message_notify\MessageNotifier;
use Drupal\message_subscribe\Subscribers;
use Drupal\Tests\UnitTestCase;
-use Drupal\user\UserInterface;
-use Prophecy\Argument;
/**
* Unit tests for the subscribers service.