From 8d8191cd904fffb131ce52264ec203f436d12c27 Mon Sep 17 00:00:00 2001 From: mccrodp Date: Sun, 24 Jul 2016 17:55:16 +0100 Subject: [PATCH] Reworked from "Message Type" to use "Message Template" --- README.md | 6 +++--- ...ntity_form_display.message.private_message.default.yml | 2 +- ...ntity_view_display.message.private_message.default.yml | 2 +- ...message.private_message.field_message_private_body.yml | 2 +- ...sage.private_message.field_message_private_subject.yml | 2 +- ...sage.private_message.field_message_private_to_user.yml | 2 +- ...message.private_message.field_message_private_body.yml | 2 +- ...sage.private_message.field_message_private_subject.yml | 2 +- ...sage.private_message.field_message_private_to_user.yml | 2 +- ...e_message.yml => message.template.private_message.yml} | 4 ++-- config/optional/views.view.message_private.yml | 2 +- message_private.module | 8 ++++---- src/Tests/MessagePrivatePermissions.php | 6 +++--- 13 files changed, 21 insertions(+), 21 deletions(-) rename config/optional/{message.type.private_message.yml => message.template.private_message.yml} (76%) diff --git a/README.md b/README.md index 7ac30f3..00d44f1 100755 --- a/README.md +++ b/README.md @@ -14,13 +14,13 @@ CONTENTS OF THIS FILE INTRODUCTION ------------ -A message type and entity reference fields, enabling sending and receiving -private messages using The Message Stack. Messages of type "Private Message" can +A message template and entity reference fields, enabling sending and receiving +private messages using The Message Stack. Messages of template "Private Message" can be sent by creating the private_message message instance with fields referencing user entities. The message_private module includes the following. -+ A message type "Private Message" with entity reference field referencing users ++ A message template "Private Message" with entity reference field referencing users + A message view, message_private for "User Messages" diff --git a/config/optional/core.entity_form_display.message.private_message.default.yml b/config/optional/core.entity_form_display.message.private_message.default.yml index 7318eaf..8af6902 100644 --- a/config/optional/core.entity_form_display.message.private_message.default.yml +++ b/config/optional/core.entity_form_display.message.private_message.default.yml @@ -6,7 +6,7 @@ dependencies: - field.field.message.private_message.field_message_private_body - field.field.message.private_message.field_message_private_subject - field.field.message.private_message.field_message_private_to_user - - message.type.private_message + - message.template.private_message _core: default_config_hash: 0IDVLOZjSksUi025JzU3KA6363ZSA3OK8jTdtFtK_x8 id: message.private_message.default diff --git a/config/optional/core.entity_view_display.message.private_message.default.yml b/config/optional/core.entity_view_display.message.private_message.default.yml index 13755b0..419bc01 100644 --- a/config/optional/core.entity_view_display.message.private_message.default.yml +++ b/config/optional/core.entity_view_display.message.private_message.default.yml @@ -6,7 +6,7 @@ dependencies: - field.field.message.private_message.field_message_private_body - field.field.message.private_message.field_message_private_subject - field.field.message.private_message.field_message_private_to_user - - message.type.private_message + - message.template.private_message module: - user _core: diff --git a/config/optional/field.field.message.private_message.field_message_private_body.yml b/config/optional/field.field.message.private_message.field_message_private_body.yml index 962b086..df292f6 100644 --- a/config/optional/field.field.message.private_message.field_message_private_body.yml +++ b/config/optional/field.field.message.private_message.field_message_private_body.yml @@ -4,7 +4,7 @@ status: true dependencies: config: - field.storage.message.field_message_private_body - - message.type.private_message + - message.template.private_message _core: default_config_hash: pJ31I7cSY8uoEz0deyB78BXJdE7gjs-jnfmHFW_FpAQ id: message.private_message.field_message_private_body diff --git a/config/optional/field.field.message.private_message.field_message_private_subject.yml b/config/optional/field.field.message.private_message.field_message_private_subject.yml index 94a8307..f2368f2 100644 --- a/config/optional/field.field.message.private_message.field_message_private_subject.yml +++ b/config/optional/field.field.message.private_message.field_message_private_subject.yml @@ -4,7 +4,7 @@ status: true dependencies: config: - field.storage.message.field_message_private_subject - - message.type.private_message + - message.template.private_message _core: default_config_hash: qbIzNtN7amEbCO0VrcDJtqc_T18qsnHpV8DakClDBrc id: message.private_message.field_message_private_subject diff --git a/config/optional/field.field.message.private_message.field_message_private_to_user.yml b/config/optional/field.field.message.private_message.field_message_private_to_user.yml index 06ae395..afa65d1 100644 --- a/config/optional/field.field.message.private_message.field_message_private_to_user.yml +++ b/config/optional/field.field.message.private_message.field_message_private_to_user.yml @@ -4,7 +4,7 @@ status: true dependencies: config: - field.storage.message.field_message_private_to_user - - message.type.private_message + - message.template.private_message _core: default_config_hash: t64WDBnlclOIEL1--tV8MkrvOrIGJ121lW3NJa9Xpsk id: message.private_message.field_message_private_to_user diff --git a/config/optional/message.private_message.field_message_private_body.yml b/config/optional/message.private_message.field_message_private_body.yml index c263e3a..9f1cd22 100644 --- a/config/optional/message.private_message.field_message_private_body.yml +++ b/config/optional/message.private_message.field_message_private_body.yml @@ -3,7 +3,7 @@ langcode: en status: true dependencies: config: - - message.type.private_message + - message.template.private_message id: message.private_message.field_message_private_body field_name: field_message_private_body entity_type: message diff --git a/config/optional/message.private_message.field_message_private_subject.yml b/config/optional/message.private_message.field_message_private_subject.yml index c52be7d..2d4560c 100644 --- a/config/optional/message.private_message.field_message_private_subject.yml +++ b/config/optional/message.private_message.field_message_private_subject.yml @@ -3,7 +3,7 @@ langcode: en status: true dependencies: config: - - message.type.private_message + - message.template.private_message id: message.private_message.field_message_private_subject field_name: field_message_private_subject entity_type: message diff --git a/config/optional/message.private_message.field_message_private_to_user.yml b/config/optional/message.private_message.field_message_private_to_user.yml index 6e9e78d..ab844a6 100644 --- a/config/optional/message.private_message.field_message_private_to_user.yml +++ b/config/optional/message.private_message.field_message_private_to_user.yml @@ -3,7 +3,7 @@ langcode: en status: true dependencies: config: - - message.type.private_message + - message.template.private_message id: message.private_message.field_message_private_to_user field_name: field_message_private_to_user entity_type: message diff --git a/config/optional/message.type.private_message.yml b/config/optional/message.template.private_message.yml similarity index 76% rename from config/optional/message.type.private_message.yml rename to config/optional/message.template.private_message.yml index 9beaf3f..6b2dfff 100644 --- a/config/optional/message.type.private_message.yml +++ b/config/optional/message.template.private_message.yml @@ -4,9 +4,9 @@ status: true dependencies: { } _core: default_config_hash: QzVUBM8GTfka1Gk4FkMXtpB__vi9CQkfSbyBeEScCN8 -type: private_message +template: private_message label: 'Private Message' -description: 'Private Message message type.' +description: 'Private Message message template.' text: - "

Private Message -

\r\n" settings: { } diff --git a/config/optional/views.view.message_private.yml b/config/optional/views.view.message_private.yml index 0932c4a..9007cc1 100644 --- a/config/optional/views.view.message_private.yml +++ b/config/optional/views.view.message_private.yml @@ -5,7 +5,7 @@ dependencies: config: - field.storage.message.field_message_private_subject - field.storage.message.field_message_private_to_user - - message.type.private_message + - message.template.private_message module: - message - message_private diff --git a/message_private.module b/message_private.module index 3f6a9f8..42394ed 100755 --- a/message_private.module +++ b/message_private.module @@ -72,7 +72,7 @@ function message_private_help($route_name, RouteMatchInterface $arg) { function message_private_message_access(EntityInterface $message, $operation, AccountInterface $account) { // Customise access check only for private messages. if ($message->bundle() == 'private_message') { - // If checking whether a node of a particular type may be created. + // If checking whether a message of a particular template may be created. if ($account->hasPermission('administer message private') || $account->hasPermission('bypass private message access control')) { return AccessResult::allowed()->cachePerPermissions(); @@ -119,7 +119,7 @@ function message_private_message_access(EntityInterface $message, $operation, Ac */ // @todo: code as Access class & associate service entry to local task/actions. function message_private_access_callback($message) { - if ($message->type == 'private_message') { + if ($message->template == 'private_message') { return \Drupal::currentUser()->hasPermission('bypass private message access control') || \Drupal::currentUser()->hasPermission('view a private_message message instance'); } return FALSE; @@ -181,7 +181,7 @@ function message_private_form_message_private_message_form_validate($form, \Drup // Get total amount of this user's messages since last interval. $query = \Drupal::entityQuery('message'); - $total = $query->condition('type', 'private_message') + $total = $query->condition('template', 'private_message') ->condition('timestamp', $interval_timestamp, '>') ->condition('uid', $user->id()) ->count() @@ -207,7 +207,7 @@ function message_private_message_insert(\Drupal\message\MessageInterface $messag // Prepare message notifications for private messages if notifications are on. // The correct configuration object could not be determined. You'll need to // rewrite this call manually. - if ($message->type == 'private_message' + if ($message->bundle() == 'private_message' && \Drupal::config('message_private.settings')->get('email_notify')) { // Use message load as the $message object has issue with mail function. // It causes duplicate entry, possibly as mid is missing and the mail diff --git a/src/Tests/MessagePrivatePermissions.php b/src/Tests/MessagePrivatePermissions.php index af97888..32df18c 100644 --- a/src/Tests/MessagePrivatePermissions.php +++ b/src/Tests/MessagePrivatePermissions.php @@ -158,10 +158,10 @@ public function testMessagePrivateAccessHook() { 'update' => FALSE, ); - // Get the message type and create an instance. - $message_type = $this->loadMessageType('private_message'); + // Get the message template and create an instance. + $message_template = $this->loadMessageTemplate('private_message'); /* @var $message Message */ - $message = Message::create(array('type' => $message_type->id())); + $message = Message::create(array('template' => $message_template->id())); $message->setOwner($this->account); $message->save();