Skip to content

Commit

Permalink
Reworked from "Message Type" to use "Message Template"
Browse files Browse the repository at this point in the history
  • Loading branch information
mccrodp committed Jul 24, 2016
1 parent 94bb28d commit 8d8191c
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- "<p>Private Message -</p>\r\n"
settings: { }
2 changes: 1 addition & 1 deletion config/optional/views.view.message_private.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions message_private.module
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Tests/MessagePrivatePermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 8d8191c

Please sign in to comment.