diff --git a/.travis.yml b/.travis.yml index f9ab374..f36962f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,6 +50,8 @@ install: - test ${DRUPAL_VERSION} -eq 8.5.x || (cd drupal && composer run-script drupal-phpunit-upgrade && cd -) - mv /tmp/$MODULE_NAME drupal/modules/ - cd drupal + - composer require drupal/sms + - composer require drupal/dynamic_entity_reference # Install the message module from github # Use working branch until PRs are merged in main repo. - cd modules && git clone -b 8.x-1.x https://github.com/Gizra/message.git && cd - diff --git a/composer.json b/composer.json index 8b56a61..dc00c75 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,10 @@ "source": "https://cgit.drupalcode.org/message_notify" }, "require": { - "drupal/message": "~8.1.0" + "drupal/message": "~8.1.0" + }, + "suggest": { + "drupal/sms": "Allow message_notify_sms to send SMS." }, "minimum-stability": "dev" } diff --git a/modules/message_notify_sms/README.md b/modules/message_notify_sms/README.md new file mode 100644 index 0000000..e778761 --- /dev/null +++ b/modules/message_notify_sms/README.md @@ -0,0 +1,19 @@ +# Message Notify SMS + +Support sending of notifications over SMS + +## Requirements + +- [`message_notify`](https://www.drupal.org/project/message_notify) +- [`sms`](https://www.drupal.org/project/smsframework) + +## Installation + +- via admin: Go to `/admin/modules` and enable the module. +- via Drush: `drush en -y message_notify_sms` + +## Configuration + +- Go to `/admin/config/message/message-subscribe` +- Under "Default message notifiers", include `SMS` in your selection. +- Click "Save configuration". diff --git a/modules/message_notify_sms/config/install/core.entity_view_mode.message.sms_message.yml b/modules/message_notify_sms/config/install/core.entity_view_mode.message.sms_message.yml new file mode 100644 index 0000000..b6a9d6d --- /dev/null +++ b/modules/message_notify_sms/config/install/core.entity_view_mode.message.sms_message.yml @@ -0,0 +1,9 @@ +langcode: en +status: true +dependencies: + module: + - message +id: message.sms_message +label: 'Notify - SMS message' +targetEntityType: message +cache: true diff --git a/modules/message_notify_sms/message_notify_sms.info.yml b/modules/message_notify_sms/message_notify_sms.info.yml new file mode 100644 index 0000000..b03179e --- /dev/null +++ b/modules/message_notify_sms/message_notify_sms.info.yml @@ -0,0 +1,8 @@ +name: 'Message Notify SMS' +type: module +package: Message +description: 'Plugin for Message Notify to send SMS notifications.' +core: 8.x +dependencies: + - message_notify + - sms diff --git a/modules/message_notify_sms/src/Plugin/Notifier/Sms.php b/modules/message_notify_sms/src/Plugin/Notifier/Sms.php new file mode 100644 index 0000000..5f61a6c --- /dev/null +++ b/modules/message_notify_sms/src/Plugin/Notifier/Sms.php @@ -0,0 +1,177 @@ + FALSE]; + + parent::__construct($configuration, $plugin_id, $plugin_definition, $logger, $entity_type_manager, $renderer, $message); + + $this->phoneNumberProvider = $phone_number_provider; + $this->smsProvider = $sms_provider; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MessageInterface $message = NULL) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('logger.channel.message_notify'), + $container->get('entity_type.manager'), + $container->get('renderer'), + $message, + $container->get('sms.phone_number'), + $container->get('sms.provider') + ); + } + + /** + * {@inheritdoc} + */ + public function deliver(array $output = []) { + $message = trim(strip_tags($output['sms_message'])); + + if ($message === '') { + $this->logger->warning('Failed to send SMS. Message empty.', []); + return FALSE; + } + + try { + $phone_number = $this->configuration['phone_number']; + + if ($phone_number) { + $this->sendToNumber($message, $phone_number); + + $this->logger->info('Queued SMS for {phone_number}.', [ + 'phone_number' => $phone_number, + ]); + } + else { + $user = $this->message->getOwner(); + $this->sendToEntity($message, $user); + + $this->logger->info('Queued SMS for {name} (uid: {id}).', [ + 'id' => $user->id(), + 'name' => $user->getAccountName(), + ]); + } + + return TRUE; + } + catch (\Exception $e) { + $this->logger->error('Failed to send SMS.', [ + 'exception' => $e, + ]); + return FALSE; + } + } + + /** + * Send message to a phone number. + * + * @param string $message + * The rendered message. + * @param string $number + * The recepient's phone number. + * + * @throws \Drupal\sms\Exception\SmsDirectionException + * Thrown if no direction is set for the message. + * @throws \Drupal\sms\Exception\RecipientRouteException + * Thrown if no gateway could be determined for the message. + */ + protected function sendToNumber($message, $number) { + $sms_message = (new SmsMessage()) + ->setMessage($message) + ->addRecipient($number) + ->setDirection(Direction::OUTGOING); + + $this->smsProvider->queue($sms_message); + } + + /** + * Sends message to entity's configured phone number. + * + * @param string $message + * The rendered message. + * @param \Drupal\Core\Entity\EntityInterface $entity + * The receiving entity. + * + * @throws \Drupal\sms\Exception\NoPhoneNumberException + * Thrown if entity does not have a phone number. + */ + protected function sendToEntity($message, EntityInterface $entity) { + $sms_message = (new SmsMessage()) + ->setMessage($message); + + $this->phoneNumberProvider->sendMessage($entity, $sms_message); + } + +} diff --git a/modules/message_notify_sms/tests/src/Kernel/MessageNotifySmsTest.php b/modules/message_notify_sms/tests/src/Kernel/MessageNotifySmsTest.php new file mode 100644 index 0000000..ad385bc --- /dev/null +++ b/modules/message_notify_sms/tests/src/Kernel/MessageNotifySmsTest.php @@ -0,0 +1,221 @@ +installSchema('system', ['sequences']); + $this->installEntitySchema('user'); + $this->installEntitySchema('message'); + $this->installEntitySchema('phone_number_settings'); + $this->installEntitySchema('sms_phone_number_verification'); + $this->installEntitySchema('sms_report'); + $this->installEntitySchema('sms_gateway'); + $this->installEntitySchema('sms'); + $this->installEntitySchema('sms_result'); + $this->installConfig([ + 'sms', + 'message', + 'message_notify', + 'message_notify_sms', + 'message_notify_sms_test', + ]); + + $this->messageTemplate = MessageTemplate::load('message_notify_sms_test'); + + $this->messageNotifier = $this->container->get('message_notify.sender'); + } + + /** + * Tests notifier sending a message to an entity. + */ + public function testSendEntity() { + // Create an active user with a phone number. + $user = User::create([ + 'name' => $this->randomMachineName(), + 'field_sms' => $this->messageNumber, + 'status' => 1, + ]); + + $user->save(); + + $this->verifyEntityPhoneNumber($user); + + $message = $this->createEntityMessage($user); + $result = $this->messageNotifier->send($message, [], 'sms'); + + $this->assertTrue($result); + } + + /** + * Tests notifier sending a message to an inactive entity. + */ + public function testSendEntityInactive() { + // Create an active user with a phone number. + $user = User::create([ + 'name' => $this->randomMachineName(), + 'field_sms' => $this->messageNumber, + ]); + + $user->save(); + + $this->verifyEntityPhoneNumber($user); + + $message = $this->createEntityMessage($user); + $result = $this->messageNotifier->send($message, [], 'sms'); + + $this->assertFalse($result); + } + + /** + * Tests notifier sending a message to an entity with no phone number. + */ + public function testSendEntityNoNumber() { + // Create an active user with a phone number. + $user = User::create([ + 'name' => $this->randomMachineName(), + 'status' => 1, + ]); + + $user->save(); + + $message = $this->createEntityMessage($user); + $result = $this->messageNotifier->send($message, [], 'sms'); + + $this->assertFalse($result); + } + + /** + * Tests notifier sending a message to an unverified entity. + */ + public function testSendEntityUnverified() { + // Create an active user with a phone number. + $user = User::create([ + 'name' => $this->randomMachineName(), + 'field_sms' => $this->messageNumber, + 'status' => 1, + ]); + + $user->save(); + + $message = $this->createEntityMessage($user); + $result = $this->messageNotifier->send($message, [], 'sms'); + + $this->assertFalse($result); + } + + /** + * Tests notifier sending a message to a number. + */ + public function testSendNumber() { + $message = Message::create([ + 'template' => $this->messageTemplate->id(), + 'message_notify_sms_test_text' => $this->messageText, + ]); + + $result = $this->messageNotifier->send($message, ['phone_number' => $this->messageNumber], 'sms'); + + $this->assertTrue($result); + } + + /** + * Creates a Message object owned by the supplied entity. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity that owns the message. + * + * @return \Drupal\message\MessageInterface + * The message object. + */ + protected function createEntityMessage(EntityInterface $entity) { + return Message::create([ + 'uid' => $entity->id(), + 'template' => $this->messageTemplate->id(), + 'message_notify_sms_test_text' => $this->messageText, + ]); + } + + /** + * Verify an entity's phone number, if one exists. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity whose phone number to verify. + * + * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException + * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException + */ + protected function verifyEntityPhoneNumber(EntityInterface $entity) { + $verifications = \Drupal::entityTypeManager() + ->getStorage('sms_phone_number_verification') + ->loadByProperties([ + 'entity__target_type' => $entity->getEntityTypeId(), + 'entity__target_id' => $entity->id(), + 'phone' => $entity->field_sms->value, + ]); + $verification = reset($verifications); + $verification->setStatus(TRUE)->save(); + } + +} diff --git a/modules/message_notify_sms/tests/src/Unit/Plugin/Notifier/SmsTest.php b/modules/message_notify_sms/tests/src/Unit/Plugin/Notifier/SmsTest.php new file mode 100644 index 0000000..953f28a --- /dev/null +++ b/modules/message_notify_sms/tests/src/Unit/Plugin/Notifier/SmsTest.php @@ -0,0 +1,415 @@ +set('uuid', $this->getMockUuidService()); + \Drupal::setContainer($container); + + $this->entityConfiguration = []; + $this->numberConfiguration = ['phone_number' => '18001234567']; + $this->pluginId = $this->randomMachineName(); + $this->pluginDefinition = [ + 'title' => $this->randomMachineName(), + 'viewModes' => [ + 'sms_message', + ], + ]; + $this->logger = $this->prophesize(LoggerChannelInterface::class)->reveal(); + $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class)->reveal(); + $this->renderer = $this->prophesize(RendererInterface::class)->reveal(); + $this->phoneNumberProvider = $this->prophesize(PhoneNumberProviderInterface::class)->reveal(); + $this->smsProvider = $this->prophesize(SmsProviderInterface::class)->reveal(); + + $this->output = ['sms_message' => 'Hello, World!']; + } + + /** + * Test Sms::deliver empty message. + * + * @covers \Drupal\message_notify_sms\Plugin\Notifier\Sms::deliver + */ + public function testDeliverEmptyMessage() { + $this->logger = $this->getMockLogger('warning'); + $notifier = $this->getEntityNotifier(); + + $this->assertFalse($notifier->deliver(['sms_message' => ''])); + } + + /** + * Test Sms::deliver entity with happy path. + * + * @covers \Drupal\message_notify_sms\Plugin\Notifier\Sms::deliver + */ + public function testDeliverEntity() { + $this->phoneNumberProvider = $this->getMockRespondingPhoneNumberProvider(FALSE); + $this->logger = $this->getMockLogger('info'); + $notifier = $this->getEntityNotifier(); + + $this->assertTrue($notifier->deliver($this->output)); + } + + /** + * Test Sms::deliver entity that has no phone number. + * + * @covers \Drupal\message_notify_sms\Plugin\Notifier\Sms::deliver + */ + public function testDeliverEntityNoPhoneNumber() { + $this->phoneNumberProvider = $this->getMockThrowingPhoneProvider(NoPhoneNumberException::class); + $this->logger = $this->getMockLogger('error'); + $notifier = $this->getEntityNotifier(); + + $this->assertFalse($notifier->deliver($this->output)); + } + + /** + * Test Sms::deliver entity with a random exception. + * + * @covers \Drupal\message_notify_sms\Plugin\Notifier\Sms::deliver + */ + public function testDeliverEntityRandomException() { + $this->phoneNumberProvider = $this->getMockThrowingPhoneProvider(Exception::class); + $this->logger = $this->getMockLogger('error'); + $notifier = $this->getEntityNotifier(); + + $this->assertFalse($notifier->deliver($this->output)); + } + + /** + * Test Sms::deliver number happy path. + * + * @covers \Drupal\message_notify_sms\Plugin\Notifier\Sms::deliver + */ + public function testDeliverNumber() { + $this->logger = $this->getMockLogger('info'); + $this->smsProvider = $this->getMockRespondingSmsProvider(NULL); + $notifier = $this->getNumberNotifier(); + + $this->assertTrue($notifier->deliver($this->output)); + } + + /** + * Test Sms::deliver number with message that has no direction. + * + * @covers \Drupal\message_notify_sms\Plugin\Notifier\Sms::deliver + */ + public function testDeliverNumberNoDirection() { + $this->logger = $this->getMockLogger('error'); + $this->smsProvider = $this->getMockThrowingSmsProvider(SmsDirectionException::class); + $notifier = $this->getNumberNotifier(); + + $this->assertFalse($notifier->deliver($this->output)); + } + + /** + * Test Sms::deliver number with no gateway. + * + * @covers \Drupal\message_notify_sms\Plugin\Notifier\Sms::deliver + */ + public function testDeliverNumberRouteException() { + $this->logger = $this->getMockLogger('error'); + $this->smsProvider = $this->getMockThrowingSmsProvider(RecipientRouteException::class); + $notifier = $this->getNumberNotifier(); + + $this->assertFalse($notifier->deliver($this->output)); + } + + /** + * Test Sms::deliver number with a random exception. + * + * @covers \Drupal\message_notify_sms\Plugin\Notifier\Sms::deliver + */ + public function testDeliverNumberRandomException() { + $this->logger = $this->getMockLogger('error'); + $this->smsProvider = $this->getMockThrowingSmsProvider(Exception::class); + $notifier = $this->getNumberNotifier(); + + $this->assertFalse($notifier->deliver($this->output)); + } + + /** + * Returns a mocked logger expecting a single info call. + * + * @param string $level + * The log level. + * + * @return object + * The mock logger. + */ + protected function getMockLogger($level) { + $logger = $this->prophesize(LoggerChannelInterface::class); + $logger + ->$level(Argument::type('string'), Argument::type('array')) + ->shouldBeCalledTimes(1); + + return $logger->reveal(); + } + + /** + * Returns a mocked PhoneNumberProvider that returns the specified value. + * + * @param mixed $return_value + * The value PhoneNumberProvider::sendMessage should return. + * + * @return object + * The mock PhoneNumberProvider. + */ + protected function getMockRespondingPhoneNumberProvider($return_value) { + $phoneNumberProvider = $this->prophesize(PhoneNumberProviderInterface::class); + $phoneNumberProvider + ->sendMessage(Argument::type('Drupal\user\UserInterface'), Argument::type('Drupal\sms\Message\SmsMessageInterface')) + ->willReturn($return_value); + + return $phoneNumberProvider->reveal(); + } + + /** + * Returns a mocked PhoneNumberProvider that throws the specified exception. + * + * @param string $thrown_class + * The exception PhoneNumberProvider::sendMessage should throw. + * + * @return object + * The mock PhoneNumberProvider. + */ + protected function getMockThrowingPhoneProvider($thrown_class) { + $phoneNumberProvider = $this->prophesize(PhoneNumberProviderInterface::class); + $phoneNumberProvider + ->sendMessage(Argument::type('Drupal\user\UserInterface'), Argument::type('Drupal\sms\Message\SmsMessageInterface')) + ->willThrow($thrown_class); + + return $phoneNumberProvider->reveal(); + } + + /** + * Returns a mocked SmsProvider that returns the specified value. + * + * @param mixed $return_value + * The value SmsProvider::sendMessage should return. + * + * @return object + * The mock SmsProvider. + */ + protected function getMockRespondingSmsProvider($return_value) { + $smsProvider = $this->prophesize(SmsProviderInterface::class); + $smsProvider + ->queue(Argument::type('Drupal\sms\Message\SmsMessageInterface')) + ->willReturn($return_value); + + return $smsProvider->reveal(); + } + + /** + * Returns a mocked SmsProvider that throws the specified exception. + * + * @param string $thrown_class + * The exception SmsProvider::sendMessage should throw. + * + * @return object + * The mock SmsProvider. + */ + protected function getMockThrowingSmsProvider($thrown_class) { + $smsProvider = $this->prophesize(SmsProviderInterface::class); + $smsProvider + ->queue(Argument::type('Drupal\sms\Message\SmsMessageInterface')) + ->willThrow($thrown_class); + + return $smsProvider->reveal(); + + } + + /** + * Returns a mocked User. + * + * @return object + * The mocked user. + */ + protected function getMockUser() { + $user = $this->prophesize(UserInterface::class); + $user->id()->willReturn(42); + $user->getAccountName()->willReturn('user'); + $user->getEmail()->willReturn('user@example.com'); + $user->getPreferredLangcode()->willReturn(Language::LANGCODE_DEFAULT); + + return $user->reveal(); + } + + /** + * Returns a mocked Message. + * + * @param \Drupal\user\UserInterface $user + * The user object that owns the message. + * + * @return object + * The mocked Message + */ + protected function getMockMessage(UserInterface $user) { + $message = $this->prophesize(MessageInterface::class); + $message->getOwner()->willReturn($user); + $message->getOwnerId()->willReturn(42); + + return $message->reveal(); + } + + /** + * Returns a mocked Notifier plugin tied to an entity. + * + * @return \Drupal\message_notify_sms\Plugin\Notifier\Sms + * The notifier instance. + */ + protected function getEntityNotifier() { + $user = $this->getMockUser(); + $message = $this->getMockMessage($user); + + return new Sms( + $this->entityConfiguration, + $this->pluginId, + $this->pluginDefinition, + $this->logger, + $this->entityTypeManager, + $this->renderer, + $message, + $this->phoneNumberProvider, + $this->smsProvider + ); + } + + /** + * Returns a mocked Notifier plugin with manual options. + * + * @return \Drupal\message_notify_sms\Plugin\Notifier\Sms + * The notifier instance. + */ + protected function getNumberNotifier() { + return new Sms( + $this->numberConfiguration, + $this->pluginId, + $this->pluginDefinition, + $this->logger, + $this->entityTypeManager, + $this->renderer, + NULL, + $this->phoneNumberProvider, + $this->smsProvider + ); + } + + /** + * Returns a mocked UUID service. + * + * @return \Prophecy\Prophecy\ObjectProphecy + * The mocked UUID service. + */ + protected function getMockUuidService() { + $uuid = $this->prophesize(UuidInterface::class); + $uuid->generate(Argument::any())->willReturn(42); + + return $uuid; + } + +} diff --git a/modules/message_notify_sms_test/config/install/core.entity_form_display.user.user.default.yml b/modules/message_notify_sms_test/config/install/core.entity_form_display.user.user.default.yml new file mode 100644 index 0000000..245c6d2 --- /dev/null +++ b/modules/message_notify_sms_test/config/install/core.entity_form_display.user.user.default.yml @@ -0,0 +1,43 @@ +langcode: en +status: true +dependencies: + config: + - field.field.user.user.field_sms + module: + - path + - sms + - user +id: user.user.default +targetEntityType: user +bundle: user +mode: default +content: + account: + weight: -10 + settings: { } + third_party_settings: { } + region: content + field_sms: + weight: 31 + settings: + placeholder: '' + third_party_settings: { } + type: sms_telephone + region: content + language: + weight: 0 + settings: { } + third_party_settings: { } + region: content + path: + type: path + weight: 30 + region: content + settings: { } + third_party_settings: { } + timezone: + weight: 6 + settings: { } + third_party_settings: { } + region: content +hidden: { } diff --git a/modules/message_notify_sms_test/config/install/core.entity_view_display.message.message_notify_sms_test.sms_message.yml b/modules/message_notify_sms_test/config/install/core.entity_view_display.message.message_notify_sms_test.sms_message.yml new file mode 100644 index 0000000..d67a34c --- /dev/null +++ b/modules/message_notify_sms_test/config/install/core.entity_view_display.message.message_notify_sms_test.sms_message.yml @@ -0,0 +1,19 @@ +langcode: en +status: true +dependencies: + config: + - core.entity_view_mode.message.sms_message + - field.field.message.message_notify_sms_test.message_notify_sms_test_text + - message.template.message_notify_sms_test +id: message.message_notify_sms_test.sms_message +targetEntityType: message +bundle: message_notify_sms_test +mode: sms_message +content: + message_notify_sms_test_text: + weight: -10 + settings: { } + third_party_settings: { } + label: hidden +hidden: + partial_0: true diff --git a/modules/message_notify_sms_test/config/install/field.field.message.message_notify_sms_test.message_notify_sms_test_text.yml b/modules/message_notify_sms_test/config/install/field.field.message.message_notify_sms_test.message_notify_sms_test_text.yml new file mode 100644 index 0000000..9efc6bf --- /dev/null +++ b/modules/message_notify_sms_test/config/install/field.field.message.message_notify_sms_test.message_notify_sms_test_text.yml @@ -0,0 +1,18 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.message.message_notify_sms_test_text + - message.template.message_notify_sms_test +id: message.message_notify_sms_test.message_notify_sms_test_text +field_name: message_notify_sms_test_text +entity_type: message +bundle: message_notify_sms_test +label: 'Message text' +description: '' +required: true +translatable: false +default_value: { } +default_value_callback: '' +settings: { } +field_type: string_long diff --git a/modules/message_notify_sms_test/config/install/field.field.user.user.field_sms.yml b/modules/message_notify_sms_test/config/install/field.field.user.user.field_sms.yml new file mode 100644 index 0000000..27616c4 --- /dev/null +++ b/modules/message_notify_sms_test/config/install/field.field.user.user.field_sms.yml @@ -0,0 +1,20 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.user.field_sms + module: + - telephone + - user +id: user.user.field_sms +field_name: field_sms +entity_type: user +bundle: user +label: SMS +description: '' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: { } +field_type: telephone diff --git a/modules/message_notify_sms_test/config/install/field.storage.message.message_notify_sms_test_text.yml b/modules/message_notify_sms_test/config/install/field.storage.message.message_notify_sms_test_text.yml new file mode 100644 index 0000000..420ff53 --- /dev/null +++ b/modules/message_notify_sms_test/config/install/field.storage.message.message_notify_sms_test_text.yml @@ -0,0 +1,19 @@ +langcode: en +status: true +dependencies: + module: + - field + - message +id: message.message_notify_sms_test_text +field_name: message_notify_sms_test_text +entity_type: message +type: string_long +settings: + case_sensitive: false +module: core +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/modules/message_notify_sms_test/config/install/field.storage.user.field_sms.yml b/modules/message_notify_sms_test/config/install/field.storage.user.field_sms.yml new file mode 100644 index 0000000..bde76b3 --- /dev/null +++ b/modules/message_notify_sms_test/config/install/field.storage.user.field_sms.yml @@ -0,0 +1,18 @@ +langcode: en +status: true +dependencies: + module: + - telephone + - user +id: user.field_sms +field_name: field_sms +entity_type: user +type: telephone +settings: { } +module: telephone +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/modules/message_notify_sms_test/config/install/message.template.message_notify_sms_test.yml b/modules/message_notify_sms_test/config/install/message.template.message_notify_sms_test.yml new file mode 100644 index 0000000..61c691f --- /dev/null +++ b/modules/message_notify_sms_test/config/install/message.template.message_notify_sms_test.yml @@ -0,0 +1,16 @@ +langcode: en +status: true +dependencies: { } +template: message_notify_sms_test +label: 'Message Notify SMS Test' +description: 'Message template for testing purposes.' +text: + - + value: "
Partial
" + format: basic_html +settings: + 'token options': + clear: false + 'token replace': true + purge_override: false + purge_methods: { } diff --git a/modules/message_notify_sms_test/config/install/sms.phone.user.user.yml b/modules/message_notify_sms_test/config/install/sms.phone.user.user.yml new file mode 100644 index 0000000..a856d94 --- /dev/null +++ b/modules/message_notify_sms_test/config/install/sms.phone.user.user.yml @@ -0,0 +1,15 @@ +langcode: en +status: true +dependencies: + config: + - field.field.user.user.field_sms +id: user.user +entity_type: user +bundle: user +automated_optout: null +verification_message: "Your verification code is '[sms-message:verification-code]'.\r\nGo to [sms:verification-url] to verify your phone number.\r\n- [site:name]" +verification_code_lifetime: 3600 +purge_verification_phone_number: true +fields: + phone_number: field_sms + automated_opt_out: '' diff --git a/modules/message_notify_sms_test/message_notify_sms_test.info.yml b/modules/message_notify_sms_test/message_notify_sms_test.info.yml new file mode 100644 index 0000000..b699401 --- /dev/null +++ b/modules/message_notify_sms_test/message_notify_sms_test.info.yml @@ -0,0 +1,8 @@ +name: 'Message Notify SMS Test' +description: 'Installs assisting config for testing message_notify_sms' +type: module +core: 8.x +dependencies: + - field + - message_notify_sms +package: Testing diff --git a/src/Plugin/Notifier/Email.php b/src/Plugin/Notifier/Email.php index 7e133be..3ad6d5e 100644 --- a/src/Plugin/Notifier/Email.php +++ b/src/Plugin/Notifier/Email.php @@ -56,10 +56,7 @@ class Email extends MessageNotifierBase { */ public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerChannelInterface $logger, EntityTypeManagerInterface $entity_type_manager, RendererInterface $render, MessageInterface $message = NULL, MailManagerInterface $mail_manager) { // Set configuration defaults. - $configuration += [ - 'mail' => FALSE, - 'language override' => FALSE, - ]; + $configuration = $configuration + ['mail' => FALSE]; parent::__construct($configuration, $plugin_id, $plugin_definition, $logger, $entity_type_manager, $render, $message); diff --git a/src/Plugin/Notifier/MessageNotifierBase.php b/src/Plugin/Notifier/MessageNotifierBase.php index a1b500c..96cc2a2 100644 --- a/src/Plugin/Notifier/MessageNotifierBase.php +++ b/src/Plugin/Notifier/MessageNotifierBase.php @@ -68,6 +68,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition $configuration += [ 'save on success' => TRUE, 'save on fail' => FALSE, + 'language override' => FALSE, ]; parent::__construct($configuration, $plugin_id, $plugin_definition); diff --git a/src/Plugin/Notifier/Sms.php b/src/Plugin/Notifier/Sms.php deleted file mode 100644 index 4d14ca1..0000000 --- a/src/Plugin/Notifier/Sms.php +++ /dev/null @@ -1,34 +0,0 @@ -message->smsNumber)) { - // Try to get the SMS number from the account. - $account = $this->message->uid->entitiy; - if (!empty($account->sms_user['number'])) { - $this->message->smsNumber = $account->sms_user['number']; - } - } - - if (empty($this->message->smsNumber)) { - throw new MessageNotifyException('Message cannot be sent using SMS as the "smsNumber" property is missing from the Message entity or user entity.'); - } - - return sms_send($this->message->smsNumber, strip_tags($output['message_notify_sms_body'])); - } - -}