Created
August 10, 2017 21:33
-
-
Save NewZeal/ca87d169b9c0e879a7bc1a1260c1d12e to your computer and use it in GitHub Desktop.
message thread - message private patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/.gitignore b/.gitignore | |
new file mode 100644 | |
index 0000000..496ee2c | |
--- /dev/null | |
+++ b/.gitignore | |
@@ -0,0 +1 @@ | |
+.DS_Store | |
\ No newline at end of file | |
diff --git a/config/optional/core.entity_view_mode.message.inbox.yml b/config/optional/core.entity_view_mode.message.inbox.yml | |
new file mode 100644 | |
index 0000000..0982f4c | |
--- /dev/null | |
+++ b/config/optional/core.entity_view_mode.message.inbox.yml | |
@@ -0,0 +1,9 @@ | |
+langcode: en | |
+status: true | |
+dependencies: | |
+ module: | |
+ - message | |
+id: message.inbox | |
+label: Inbox | |
+targetEntityType: message | |
+cache: true | |
diff --git a/config/optional/core.entity_view_mode.message.sent.yml b/config/optional/core.entity_view_mode.message.sent.yml | |
new file mode 100644 | |
index 0000000..952b217 | |
--- /dev/null | |
+++ b/config/optional/core.entity_view_mode.message.sent.yml | |
@@ -0,0 +1,9 @@ | |
+langcode: en | |
+status: true | |
+dependencies: | |
+ module: | |
+ - message | |
+id: message.sent | |
+label: Sent | |
+targetEntityType: message | |
+cache: true | |
\ No newline at end of file | |
diff --git a/config/optional/views.view.message_private_inbox.yml b/config/optional/views.view.message_private_inbox.yml | |
new file mode 100644 | |
index 0000000..3ca8567 | |
--- /dev/null | |
+++ b/config/optional/views.view.message_private_inbox.yml | |
@@ -0,0 +1,255 @@ | |
+langcode: en | |
+status: true | |
+dependencies: | |
+ config: | |
+ - core.entity_view_mode.message.inbox | |
+ - message.template.private_message | |
+ module: | |
+ - message | |
+ - user | |
+id: message_private_inbox | |
+label: 'Message Private Inbox' | |
+module: views | |
+description: 'List of messages in the user inbox' | |
+tag: '' | |
+base_table: message_field_data | |
+base_field: mid | |
+core: 8.x | |
+display: | |
+ default: | |
+ display_plugin: default | |
+ id: default | |
+ display_title: Master | |
+ position: 0 | |
+ display_options: | |
+ access: | |
+ type: none | |
+ options: { } | |
+ cache: | |
+ type: tag | |
+ options: { } | |
+ query: | |
+ type: views_query | |
+ options: | |
+ disable_sql_rewrite: false | |
+ distinct: false | |
+ replica: false | |
+ query_comment: '' | |
+ query_tags: { } | |
+ exposed_form: | |
+ type: basic | |
+ options: | |
+ submit_button: Apply | |
+ reset_button: false | |
+ reset_button_label: Reset | |
+ exposed_sorts_label: 'Sort by' | |
+ expose_sort_order: true | |
+ sort_asc_label: Asc | |
+ sort_desc_label: Desc | |
+ pager: | |
+ type: mini | |
+ options: | |
+ items_per_page: 10 | |
+ offset: 0 | |
+ id: 0 | |
+ total_pages: null | |
+ expose: | |
+ items_per_page: false | |
+ items_per_page_label: 'Items per page' | |
+ items_per_page_options: '5, 10, 25, 50' | |
+ items_per_page_options_all: false | |
+ items_per_page_options_all_label: '- All -' | |
+ offset: false | |
+ offset_label: Offset | |
+ tags: | |
+ previous: ‹‹ | |
+ next: ›› | |
+ style: | |
+ type: default | |
+ row: | |
+ type: 'entity:message' | |
+ options: | |
+ relationship: none | |
+ view_mode: inbox | |
+ fields: | |
+ mid: | |
+ table: message_field_data | |
+ field: mid | |
+ id: mid | |
+ entity_type: null | |
+ entity_field: mid | |
+ plugin_id: field | |
+ relationship: none | |
+ group_type: group | |
+ admin_label: '' | |
+ label: '' | |
+ exclude: false | |
+ alter: | |
+ alter_text: false | |
+ text: '' | |
+ make_link: false | |
+ path: '' | |
+ absolute: false | |
+ external: false | |
+ replace_spaces: false | |
+ path_case: none | |
+ trim_whitespace: false | |
+ alt: '' | |
+ rel: '' | |
+ link_class: '' | |
+ prefix: '' | |
+ suffix: '' | |
+ target: '' | |
+ nl2br: false | |
+ max_length: 0 | |
+ word_boundary: true | |
+ ellipsis: true | |
+ more_link: false | |
+ more_link_text: '' | |
+ more_link_path: '' | |
+ strip_tags: false | |
+ trim: false | |
+ preserve_tags: '' | |
+ html: false | |
+ element_type: '' | |
+ element_class: '' | |
+ element_label_type: '' | |
+ element_label_class: '' | |
+ element_label_colon: true | |
+ element_wrapper_type: '' | |
+ element_wrapper_class: '' | |
+ element_default_classes: true | |
+ empty: '' | |
+ hide_empty: false | |
+ empty_zero: false | |
+ hide_alter_empty: true | |
+ click_sort_column: value | |
+ type: number_integer | |
+ settings: { } | |
+ group_column: value | |
+ group_columns: { } | |
+ group_rows: true | |
+ delta_limit: 0 | |
+ delta_offset: 0 | |
+ delta_reversed: false | |
+ delta_first_last: false | |
+ multi_type: separator | |
+ separator: ', ' | |
+ field_api_classes: false | |
+ filters: | |
+ template: | |
+ id: template | |
+ table: message_field_data | |
+ field: template | |
+ value: | |
+ private_message: private_message | |
+ entity_type: message | |
+ entity_field: template | |
+ plugin_id: bundle | |
+ sorts: { } | |
+ title: Inbox | |
+ header: { } | |
+ footer: { } | |
+ empty: { } | |
+ relationships: | |
+ field_message_private_to_user: | |
+ id: field_message_private_to_user | |
+ table: message__field_message_private_to_user | |
+ field: field_message_private_to_user | |
+ relationship: none | |
+ group_type: group | |
+ admin_label: 'field_message_private_to_user: User' | |
+ required: true | |
+ plugin_id: standard | |
+ arguments: | |
+ uid: | |
+ id: uid | |
+ table: users_field_data | |
+ field: uid | |
+ entity_type: user | |
+ entity_field: uid | |
+ plugin_id: user_uid | |
+ relationship: field_message_private_to_user | |
+ display_extenders: { } | |
+ cache_metadata: | |
+ max-age: -1 | |
+ contexts: | |
+ - 'languages:language_content' | |
+ - 'languages:language_interface' | |
+ - url | |
+ - url.query_args | |
+ tags: { } | |
+ block_1: | |
+ display_plugin: block | |
+ id: block_1 | |
+ display_title: Block | |
+ position: 2 | |
+ display_options: | |
+ display_extenders: { } | |
+ style: | |
+ type: default | |
+ defaults: | |
+ style: false | |
+ row: false | |
+ pager: false | |
+ row: | |
+ type: 'entity:message' | |
+ pager: | |
+ type: full | |
+ options: | |
+ items_per_page: 10 | |
+ offset: 0 | |
+ id: 0 | |
+ total_pages: null | |
+ expose: | |
+ items_per_page: false | |
+ items_per_page_label: 'Items per page' | |
+ items_per_page_options: '5, 10, 25, 50' | |
+ items_per_page_options_all: false | |
+ items_per_page_options_all_label: '- All -' | |
+ offset: false | |
+ offset_label: Offset | |
+ tags: | |
+ previous: '‹ Previous' | |
+ next: 'Next ›' | |
+ first: '« First' | |
+ last: 'Last »' | |
+ quantity: 9 | |
+ cache_metadata: | |
+ max-age: -1 | |
+ contexts: | |
+ - 'languages:language_content' | |
+ - 'languages:language_interface' | |
+ - url | |
+ - url.query_args | |
+ tags: { } | |
+ page_1: | |
+ display_plugin: page | |
+ id: page_1 | |
+ display_title: Page | |
+ position: 1 | |
+ display_options: | |
+ display_extenders: { } | |
+ path: user/%/message-private | |
+ menu: | |
+ type: 'default tab' | |
+ title: Inbox | |
+ description: '' | |
+ expanded: false | |
+ parent: '' | |
+ weight: 0 | |
+ context: '0' | |
+ menu_name: main | |
+ tab_options: | |
+ type: none | |
+ title: '' | |
+ description: '' | |
+ weight: 0 | |
+ cache_metadata: | |
+ max-age: -1 | |
+ contexts: | |
+ - 'languages:language_content' | |
+ - 'languages:language_interface' | |
+ - url | |
+ - url.query_args | |
+ tags: { } | |
diff --git a/config/optional/views.view.message_private_sent.yml b/config/optional/views.view.message_private_sent.yml | |
new file mode 100644 | |
index 0000000..d12c9d0 | |
--- /dev/null | |
+++ b/config/optional/views.view.message_private_sent.yml | |
@@ -0,0 +1,281 @@ | |
+langcode: en | |
+status: true | |
+dependencies: | |
+ config: | |
+ - core.entity_view_mode.message.sent | |
+ - message.template.private_message | |
+ module: | |
+ - message | |
+ - user | |
+id: message_private_sent | |
+label: 'Message Private Sent' | |
+module: views | |
+description: 'Messages sent by the user' | |
+tag: '' | |
+base_table: message_field_data | |
+base_field: mid | |
+core: 8.x | |
+display: | |
+ default: | |
+ display_plugin: default | |
+ id: default | |
+ display_title: Master | |
+ position: 0 | |
+ display_options: | |
+ access: | |
+ type: none | |
+ options: { } | |
+ cache: | |
+ type: tag | |
+ options: { } | |
+ query: | |
+ type: views_query | |
+ options: | |
+ disable_sql_rewrite: false | |
+ distinct: false | |
+ replica: false | |
+ query_comment: '' | |
+ query_tags: { } | |
+ exposed_form: | |
+ type: basic | |
+ options: | |
+ submit_button: Apply | |
+ reset_button: false | |
+ reset_button_label: Reset | |
+ exposed_sorts_label: 'Sort by' | |
+ expose_sort_order: true | |
+ sort_asc_label: Asc | |
+ sort_desc_label: Desc | |
+ pager: | |
+ type: mini | |
+ options: | |
+ items_per_page: 20 | |
+ offset: 0 | |
+ id: 0 | |
+ total_pages: null | |
+ expose: | |
+ items_per_page: false | |
+ items_per_page_label: 'Items per page' | |
+ items_per_page_options: '5, 10, 25, 50' | |
+ items_per_page_options_all: false | |
+ items_per_page_options_all_label: '- All -' | |
+ offset: false | |
+ offset_label: Offset | |
+ tags: | |
+ previous: ‹‹ | |
+ next: ›› | |
+ style: | |
+ type: default | |
+ row: | |
+ type: 'entity:message' | |
+ options: | |
+ relationship: none | |
+ view_mode: sent | |
+ fields: | |
+ mid: | |
+ table: message_field_data | |
+ field: mid | |
+ id: mid | |
+ entity_type: null | |
+ entity_field: mid | |
+ plugin_id: field | |
+ relationship: none | |
+ group_type: group | |
+ admin_label: '' | |
+ label: '' | |
+ exclude: false | |
+ alter: | |
+ alter_text: false | |
+ text: '' | |
+ make_link: false | |
+ path: '' | |
+ absolute: false | |
+ external: false | |
+ replace_spaces: false | |
+ path_case: none | |
+ trim_whitespace: false | |
+ alt: '' | |
+ rel: '' | |
+ link_class: '' | |
+ prefix: '' | |
+ suffix: '' | |
+ target: '' | |
+ nl2br: false | |
+ max_length: 0 | |
+ word_boundary: true | |
+ ellipsis: true | |
+ more_link: false | |
+ more_link_text: '' | |
+ more_link_path: '' | |
+ strip_tags: false | |
+ trim: false | |
+ preserve_tags: '' | |
+ html: false | |
+ element_type: '' | |
+ element_class: '' | |
+ element_label_type: '' | |
+ element_label_class: '' | |
+ element_label_colon: true | |
+ element_wrapper_type: '' | |
+ element_wrapper_class: '' | |
+ element_default_classes: true | |
+ empty: '' | |
+ hide_empty: false | |
+ empty_zero: false | |
+ hide_alter_empty: true | |
+ click_sort_column: value | |
+ type: number_integer | |
+ settings: { } | |
+ group_column: value | |
+ group_columns: { } | |
+ group_rows: true | |
+ delta_limit: 0 | |
+ delta_offset: 0 | |
+ delta_reversed: false | |
+ delta_first_last: false | |
+ multi_type: separator | |
+ separator: ', ' | |
+ field_api_classes: false | |
+ filters: | |
+ template: | |
+ id: template | |
+ table: message_field_data | |
+ field: template | |
+ value: | |
+ private_message: private_message | |
+ entity_type: message | |
+ entity_field: template | |
+ plugin_id: bundle | |
+ sorts: { } | |
+ title: 'Message Private Sent' | |
+ header: { } | |
+ footer: { } | |
+ empty: { } | |
+ relationships: | |
+ uid: | |
+ id: uid | |
+ table: message_field_data | |
+ field: uid | |
+ relationship: none | |
+ group_type: group | |
+ admin_label: User | |
+ required: true | |
+ entity_type: message | |
+ entity_field: uid | |
+ plugin_id: standard | |
+ arguments: | |
+ uid: | |
+ id: uid | |
+ table: users_field_data | |
+ field: uid | |
+ relationship: uid | |
+ group_type: group | |
+ admin_label: '' | |
+ default_action: empty | |
+ exception: | |
+ value: all | |
+ title_enable: false | |
+ title: All | |
+ title_enable: false | |
+ title: '' | |
+ default_argument_type: fixed | |
+ default_argument_options: | |
+ argument: '' | |
+ default_argument_skip_url: false | |
+ summary_options: | |
+ base_path: '' | |
+ count: true | |
+ items_per_page: 25 | |
+ override: false | |
+ summary: | |
+ sort_order: asc | |
+ number_of_records: 0 | |
+ format: default_summary | |
+ specify_validation: false | |
+ validate: | |
+ type: none | |
+ fail: 'not found' | |
+ validate_options: { } | |
+ break_phrase: false | |
+ not: false | |
+ entity_type: user | |
+ entity_field: uid | |
+ plugin_id: user_uid | |
+ display_extenders: { } | |
+ cache_metadata: | |
+ max-age: -1 | |
+ contexts: | |
+ - 'languages:language_content' | |
+ - 'languages:language_interface' | |
+ - url | |
+ - url.query_args | |
+ tags: { } | |
+ block_1: | |
+ display_plugin: block | |
+ id: block_1 | |
+ display_title: Block | |
+ position: 2 | |
+ display_options: | |
+ display_extenders: { } | |
+ style: | |
+ type: default | |
+ defaults: | |
+ style: false | |
+ row: false | |
+ pager: false | |
+ row: | |
+ type: 'ds_entity:message' | |
+ pager: | |
+ type: full | |
+ options: | |
+ items_per_page: 20 | |
+ offset: 0 | |
+ id: 0 | |
+ total_pages: null | |
+ expose: | |
+ items_per_page: false | |
+ items_per_page_label: 'Items per page' | |
+ items_per_page_options: '5, 10, 25, 50' | |
+ items_per_page_options_all: false | |
+ items_per_page_options_all_label: '- All -' | |
+ offset: false | |
+ offset_label: Offset | |
+ tags: | |
+ previous: '‹ Previous' | |
+ next: 'Next ›' | |
+ first: '« First' | |
+ last: 'Last »' | |
+ quantity: 9 | |
+ cache_metadata: | |
+ max-age: -1 | |
+ contexts: | |
+ - 'languages:language_content' | |
+ - 'languages:language_interface' | |
+ - url | |
+ - url.query_args | |
+ tags: { } | |
+ page_1: | |
+ display_plugin: page | |
+ id: page_1 | |
+ display_title: Page | |
+ position: 1 | |
+ display_options: | |
+ display_extenders: { } | |
+ path: user/%/message-private/sent | |
+ menu: | |
+ type: tab | |
+ title: Sent | |
+ description: '' | |
+ expanded: false | |
+ parent: user.page | |
+ weight: 0 | |
+ context: '0' | |
+ menu_name: account | |
+ cache_metadata: | |
+ max-age: -1 | |
+ contexts: | |
+ - 'languages:language_content' | |
+ - 'languages:language_interface' | |
+ - url | |
+ - url.query_args | |
+ tags: { } | |
diff --git a/message_private.info.yml b/message_private.info.yml | |
index 0511853..d44d6d1 100644 | |
--- a/message_private.info.yml | |
+++ b/message_private.info.yml | |
@@ -9,3 +9,4 @@ dependencies: | |
- message | |
- message_notify | |
- message_ui | |
+ - message_thread | |
diff --git a/message_private.module b/message_private.module | |
index 4c64156..728eb2c 100644 | |
--- a/message_private.module | |
+++ b/message_private.module | |
@@ -10,6 +10,9 @@ use Drupal\Core\Routing\RouteMatchInterface; | |
use Drupal\Core\Session\AccountInterface; | |
use Drupal\message\Entity\Message; | |
use Drupal\user\Entity\Role; | |
+use Drupal\user\Entity\User; | |
+use Drupal\Core\Form\FormStateInterface; | |
+ | |
/** | |
@@ -64,7 +67,7 @@ function message_private_message_access(EntityInterface $message, $operation, Ac | |
} | |
// Verify that the user can apply the op. | |
if ($account->hasPermission($operation . ' any message instance') | |
- || $account->hasPermission($operation . ' private_message message', $account) | |
+ || $account->hasPermission($operation . ' a private_message message instance', $account) | |
) { | |
if ($operation != 'create') { | |
// Check if the user is message author. | |
@@ -72,19 +75,14 @@ function message_private_message_access(EntityInterface $message, $operation, Ac | |
if ($message->getOwnerId() == $account->id()) { | |
return AccessResult::allowed()->cachePerPermissions(); | |
} | |
- // Grant view access for recipients of the private message. | |
- if ($operation == 'view') { | |
- $users = $message->get('field_message_private_to_user')->getValue(); | |
- if ($users && is_array($users)) { | |
- foreach ($users as $user_ref) { | |
- if ($user_ref['target_id'] == $account->id()) { | |
- return AccessResult::allowed()->cachePerPermissions(); | |
- } | |
+ $users = $message->get('field_message_private_to_user')->getValue(); | |
+ if ($users && is_array($users)) { | |
+ foreach ($users as $user_ref) { | |
+ if ($user_ref['target_id'] == $account->id()) { | |
+ return AccessResult::allowed()->cachePerPermissions(); | |
} | |
} | |
} | |
- // Deny if user is not message author or viewing recipient. | |
- return AccessResult::forbidden()->cachePerPermissions(); | |
} | |
else { | |
return AccessResult::allowed()->cachePerPermissions(); | |
@@ -123,7 +121,7 @@ function message_private_access_callback($message) { | |
* the message_text on the edit and create form, and adds custom validation. | |
*/ | |
// @todo - check form ID is matching D8 form id. | |
-function message_private_form_message_private_message_form_alter($form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { | |
+function message_private_form_message_private_message_form_alter($form, FormStateInterface $form_state, $form_id) { | |
$entity = $form_state->getFormObject()->getEntity(); | |
if ($entity->bundle() == 'private_message') { | |
if (isset($form['text']['#type'])) { | |
@@ -145,7 +143,7 @@ function message_private_form_message_private_message_form_alter($form, \Drupal\ | |
* The form state including values submitted. | |
*/ | |
// @todo - test this is called and if form should be passed by reference. | |
-function message_private_form_message_private_message_form_validate($form, \Drupal\Core\Form\FormStateInterface $form_state) { | |
+function message_private_form_message_private_message_form_validate($form, FormStateInterface $form_state) { | |
// If there is an imposed message limit set in the admin settings interface. | |
// The correct configuration object could not be determined. You'll need to | |
// rewrite this call manually. | |
@@ -172,10 +170,10 @@ 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('template', 'private_message') | |
- ->condition('timestamp', $interval_timestamp, '>') | |
- ->condition('uid', $user->id()) | |
- ->count() | |
- ->execute(); | |
+ ->condition('timestamp', $interval_timestamp, '>') | |
+ ->condition('uid', $user->id()) | |
+ ->count() | |
+ ->execute(); | |
// Display error preventing message create when total messages over limit. | |
if ($total >= $limit) { | |
@@ -198,7 +196,7 @@ function message_private_message_insert(\Drupal\message\MessageInterface $messag | |
// The correct configuration object could not be determined. You'll need to | |
// rewrite this call manually. | |
if ($message->bundle() == 'private_message' | |
- && \Drupal::config('message_private.settings')->get('email_notify')) { | |
+ && \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 | |
// function message_notify_send_message tries to re-save as a new message. | |
@@ -238,7 +236,7 @@ function message_private_message_insert(\Drupal\message\MessageInterface $messag | |
* profiles, unless the user is in role with bypass access control permission. | |
*/ | |
// @todo - check form ID matches D8 form id & add config for user notify field. | |
-function message_private_form_user_profile_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { | |
+function message_private_form_user_profile_form_alter(&$form, FormStateInterface $form_state, $form_id) { | |
// The correct configuration object could not be determined. You'll need to | |
// rewrite this call manually. | |
if (!\Drupal::currentUser()->hasPermission('bypass private message access control') | |
@@ -252,15 +250,23 @@ function message_private_form_user_profile_form_alter(&$form, \Drupal\Core\Form\ | |
*/ | |
// @todo - Is this still required in D8 to make twig template discoverable? | |
function message_private_theme() { | |
- $info['message_private'] = array( | |
- 'render element' => 'elements', | |
- 'template' => 'message--private_message', | |
- 'base hook' => 'message_private', | |
+ return array( | |
+ 'message_private' => array( | |
+ 'render element' => 'elements', | |
+ 'template' => 'message--private_message', | |
+ 'base hook' => 'message_private', | |
+ ), | |
+ // Template is discoverable if the theme name is the same as the template with '_' instead of '-' | |
+ 'message_private__inbox' => array( | |
+ 'variables' => array('messages' => array()), | |
+ ), | |
+ 'message_private__sent' => array( | |
+ 'variables' => array('messages' => array()), | |
+ ), | |
); | |
- | |
- return $info; | |
} | |
+ | |
/** | |
* Implements hook_message_view_alter(). | |
*/ | |
@@ -299,8 +305,8 @@ function template_preprocess_message_private(&$variables) { | |
// $variables['name'] = theme('username', array('account' => user_load($uid))); | |
$variables['submitted'] = t('Sent by !username on !datetime', array( | |
- '!username' => $variables['name'], | |
- '!datetime' => $variables['date'], | |
+ '!username' => $variables['name'], | |
+ '!datetime' => $variables['date'], | |
)); | |
} | |
} | |
@@ -376,3 +382,103 @@ function _message_private_inbox_access() { | |
// Allow if the user has the bypass permission | |
return AccessResult::allowedIfHasPermission($account, 'bypass private message access control'); | |
} | |
+ | |
+/** | |
+ * Implements hook_form_FORM_ID_alter(). | |
+ */ | |
+function message_private_form_entity_view_display_edit_form_alter(&$form, FormStateInterface $form_state) { | |
+ $display = $form_state->getFormObject()->getEntity(); | |
+// $form['fields']['author'] = [ | |
+// '#type' => 'textfield', | |
+// '#title' => '', | |
+// '#default_value' => $display->getThirdPartySetting('entity_print', $export_type . '_label', t('View @label', ['@label' => $definition['label']])), | |
+// ]; | |
+ | |
+return; | |
+ $table = &$form['fields']; | |
+ | |
+ | |
+ | |
+ $table['author'] = [ | |
+ '#type' => 'textfield', | |
+ '#attributes' => ['class' => ['draggable', 'field-group'], 'id' => 'indent-id'], | |
+ '#row_type' => 'field', | |
+ '#region_callback' => 'Drupal\field_ui\Form\EntityViewDisplayEditForm::getRowRegion', | |
+ '#js_settings' => ['rowHandler' => 'field'], | |
+ 'human_name' => [ | |
+ '#plain_text' => 'Author', | |
+ ], | |
+ 'weight' => [ | |
+ '#type' => 'textfield', | |
+ '#default_value' => 0, | |
+ '#size' => 3, | |
+ '#attributes' => ['class' => ['field-weight']], | |
+ ], | |
+// 'parent_wrapper' => [ | |
+// 'parent' => [ | |
+// '#type' => 'select', | |
+// '#options' => ['indent' => 'Indent'], | |
+// '#empty_value' => '', | |
+// '#default_value' => '', | |
+// '#attributes' => ['class' => ['field-parent']], | |
+// '#parents' => ['fields', 'indent', 'parent'], | |
+// ], | |
+// | |
+// ], | |
+ ]; | |
+// ksm($form); | |
+// $form['fields']['author'] = array( | |
+// '#title' => 'Author' | |
+// ); | |
+} | |
+ | |
+function message_private_entity_view_alter(array &$build, Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) { | |
+ | |
+ if ($entity->bundle() === 'private_message') { | |
+ if ($build['#view_mode'] == 'inbox') { | |
+ $component = $display->getComponent('author'); | |
+ // Add the author field | |
+// dpm($entity->get('uid')->getValue())[0]['value']; | |
+ $author = User::load($entity->get('uid')->getValue()[0]['target_id']); | |
+ | |
+ $build['author'] = array( | |
+ '#type' => 'link', | |
+ '#url' => $author->toUrl(), | |
+ '#title' => $author->getDisplayName(), | |
+ '#weight' => $component['weight'], | |
+ '#attributes' => array( | |
+ 'class' => array('message-private-author') | |
+ ) | |
+ | |
+ ); | |
+ | |
+ $created = $entity->getCreatedTime(); | |
+ $component = $display->getComponent('created'); | |
+ | |
+ $build['created'] = [ | |
+ '#markup' => '<p>Hello</p>' . \Drupal::service('date.formatter')->format($created, 'date_text'), | |
+ '#weight'=> $component['weight'] | |
+ ]; | |
+ } | |
+ | |
+ } | |
+} | |
+ | |
+/** | |
+ * Implements hook_entity_extra_field_info(). | |
+ */ | |
+function message_private_entity_extra_field_info() { | |
+ $extra_fields['message']['private_message']['display']['author'] = [ | |
+ 'label' => t('Author Link'), | |
+ 'description' => t('Provides a link to view the sender of a private message'), | |
+ 'weight' => 0, | |
+ 'visible' => FALSE, | |
+ ]; | |
+ $extra_fields['message']['private_message']['display']['created'] = [ | |
+ 'label' => t('Created date'), | |
+ 'description' => t('The date the message was created'), | |
+ 'weight' => 0, | |
+ 'visible' => FALSE, | |
+ ]; | |
+ return $extra_fields; | |
+} | |
diff --git a/message_private.permissions.yml b/message_private.permissions.yml | |
index 267fad0..14b70f5 100644 | |
--- a/message_private.permissions.yml | |
+++ b/message_private.permissions.yml | |
@@ -2,6 +2,7 @@ bypass private message access control: | |
title: 'Bypass message private access control' | |
description: 'Grant to the user the permission to apply CRUD option on any private messages.' | |
restrict access: true | |
+ | |
administer message private: | |
title: 'Administer message private' | |
- description: 'Access the message private administration pages.' | |
+ description: 'Access the message private administration pages.' | |
\ No newline at end of file | |
diff --git a/message_private.routing.yml b/message_private.routing.yml | |
index 79a2fc8..17b588d 100644 | |
--- a/message_private.routing.yml | |
+++ b/message_private.routing.yml | |
@@ -12,15 +12,14 @@ message_private.settings: | |
message_private.messages: | |
path: '/user/{user}/messages' | |
defaults: | |
- _title: 'Inbox' | |
- description: 'Message Private Inbox' | |
+ _controller: '\Drupal\message_private\Controller\MessagePrivateController::inBox' | |
requirements: | |
_permission: 'overview messages' | |
message_private.messages.inbox: | |
- path: '/user/{user}/messages' | |
+ path: '/user/{user}/messages/inbox' | |
defaults: | |
- _controller: '\Drupal\message_private\Controller\PrivateMessageController::inBox' | |
+ _controller: '\Drupal\message_private\Controller\MessagePrivateController::inBox' | |
_title: 'Inbox' | |
description: 'Message Private Inbox' | |
requirements: | |
@@ -29,8 +28,9 @@ message_private.messages.inbox: | |
message_private.messages.sent: | |
path: '/user/{user}/messages/sent' | |
defaults: | |
- _controller: '\Drupal\message_private\Controller\PrivateMessageController::sent' | |
+ _controller: '\Drupal\message_private\Controller\MessagePrivateController::sent' | |
_title: 'Sent' | |
description: 'Message Private Sent' | |
requirements: | |
_permission: 'overview messages' | |
+ | |
diff --git a/src/Controller/MessagePrivateController.php b/src/Controller/MessagePrivateController.php | |
new file mode 100644 | |
index 0000000..ef1ba57 | |
--- /dev/null | |
+++ b/src/Controller/MessagePrivateController.php | |
@@ -0,0 +1,93 @@ | |
+<?php | |
+ | |
+namespace Drupal\message_private\Controller; | |
+ | |
+use Drupal\Core\Url; | |
+use Drupal\user\entity\User; | |
+use Drupal\Core\Controller\ControllerBase; | |
+use Drupal\message\Entity\Message; | |
+use Drupal\Core\DependencyInjection\ContainerInjectionInterface; | |
+use Drupal\message\MessageTemplateInterface; | |
+ | |
+/** | |
+ * Controller for viewing private messages. | |
+ */ | |
+class MessagePrivateController extends ControllerBase implements ContainerInjectionInterface { | |
+ | |
+ /** | |
+ * The access handler object. | |
+ * | |
+ * @var \Drupal\Core\Entity\EntityAccessControlHandlerInterface | |
+ */ | |
+ private $accessHandler; | |
+ | |
+ /** | |
+ * The entity manager service. | |
+ * | |
+ * @var \Drupal\Core\Entity\EntityManagerInterface | |
+ */ | |
+ protected $entityManager; | |
+ | |
+ /** | |
+ * Constructs a MessageUiController object. | |
+ */ | |
+ public function __construct() { | |
+ $this->entityManager = \Drupal::entityManager(); | |
+ $this->accessHandler = \Drupal::entityManager()->getAccessControlHandler('message'); | |
+ } | |
+ | |
+ /** | |
+ * Generates output of all messages sent to the current user | |
+ * | |
+ * | |
+ * @return | |
+ * A render array for a list of the messages; | |
+ */ | |
+ public function inBox($user) { | |
+ $messages = array(); | |
+ | |
+ // Get messages sent to the current user | |
+ | |
+ | |
+ // Return build array. | |
+ if (!empty($messages)) { | |
+ return array( | |
+ '#theme' => 'message_private__inbox', | |
+ '#messages' => $messages | |
+ ); | |
+ } | |
+ else { | |
+ $url = Url::fromRoute('message.template_add'); | |
+ return array( | |
+ '#markup' => 'You have no messages in your inbox. Try sending a message to someone <a href="/' . $url->getInternalPath() . '">sending a message to someone</a>.' | |
+ ); | |
+ } | |
+ } | |
+ | |
+ /** | |
+ * Generates form output for adding a new message entity of message_template. | |
+ * | |
+ * @param \Drupal\message\MessageTemplateInterface $message_template | |
+ * The message template object. | |
+ * | |
+ * @return array | |
+ * An array as expected by drupal_render(). | |
+ */ | |
+ public function sent($user) { | |
+ // Return build array. | |
+ if (!empty($messages)) { | |
+ return array( | |
+ '#theme' => 'message_private__inbox', | |
+ '#messages' => $messages | |
+ ); | |
+ } | |
+ else { | |
+ $url = Url::fromRoute('message.template_add'); | |
+ return array( | |
+ '#markup' => 'You have no messages in your inbox. Try sending a message to someone <a href="/' . $url->getInternalPath() . '">sending a message to someone</a>.' | |
+ ); | |
+ } | |
+ } | |
+ | |
+ | |
+} | |
diff --git a/src/Controller/PrivateMessageController.php b/src/Controller/PrivateMessageController.php | |
deleted file mode 100644 | |
index 286489f..0000000 | |
--- a/src/Controller/PrivateMessageController.php | |
+++ /dev/null | |
@@ -1,93 +0,0 @@ | |
-<?php | |
- | |
-namespace Drupal\message_private\Controller; | |
- | |
-use Drupal\Core\Url; | |
-use Drupal\Core\Controller\ControllerBase; | |
-use Drupal\message\Entity\Message; | |
-use Drupal\Core\DependencyInjection\ContainerInjectionInterface; | |
-use Drupal\message\MessageTemplateInterface; | |
- | |
-/** | |
- * Controller for viewing private messages. | |
- */ | |
-class PrivateMessageController extends ControllerBase implements ContainerInjectionInterface { | |
- | |
- /** | |
- * The access handler object. | |
- * | |
- * @var \Drupal\Core\Entity\EntityAccessControlHandlerInterface | |
- */ | |
- private $accessHandler; | |
- | |
- /** | |
- * The entity manager service. | |
- * | |
- * @var \Drupal\Core\Entity\EntityManagerInterface | |
- */ | |
- protected $entityManager; | |
- | |
- /** | |
- * Constructs a MessageUiController object. | |
- */ | |
- public function __construct() { | |
- $this->entityManager = \Drupal::entityManager(); | |
- $this->accessHandler = \Drupal::entityManager()->getAccessControlHandler('message'); | |
- } | |
- | |
- /** | |
- * Generates output of all message template with permission to create. | |
- * | |
- * @return array|\Symfony\Component\HttpFoundation\RedirectResponse | |
- * A render array for a list of the message templates that can be added; | |
- * however, if there is only one message template defined for the site, the | |
- * function will return a RedirectResponse to the message.add page for that | |
- * one message template. | |
- */ | |
- public function inBox() { | |
- $content = []; | |
- | |
- // Only use message templates the user has access to. | |
- foreach ($this->entityManager()->getStorage('message_template')->loadMultiple() as $template) { | |
- $access = $this->entityManager() | |
- ->getAccessControlHandler('message') | |
- ->createAccess($template->id(), NULL, [], TRUE); | |
- if ($access->isAllowed()) { | |
- $content[$template->id()] = $template; | |
- } | |
- } | |
- | |
- // Bypass the message/add listing if only one message template is available. | |
- if (count($content) == 1) { | |
- $template = array_shift($content); | |
- return $this->redirect('message_ui.add', ['message_template' => $template->id()]); | |
- } | |
- | |
- // Return build array. | |
- if (!empty($content)) { | |
- return ['#theme' => 'message_add_list', '#content' => $content]; | |
- } | |
- else { | |
- $url = Url::fromRoute('message.template_add'); | |
- return ['#markup' => 'There are no messages templates. You can create a new message template <a href="/' . $url->getInternalPath() . '">here</a>.']; | |
- } | |
- } | |
- | |
- /** | |
- * Generates form output for adding a new message entity of message_template. | |
- * | |
- * @param \Drupal\message\MessageTemplateInterface $message_template | |
- * The message template object. | |
- * | |
- * @return array | |
- * An array as expected by drupal_render(). | |
- */ | |
- public function sent(MessageTemplateInterface $message_template) { | |
- $message = Message::create(['template' => $message_template->id()]); | |
- $form = $this->entityFormBuilder()->getForm($message); | |
- | |
- return $form; | |
- } | |
- | |
- | |
-} | |
diff --git a/templates/message-private--inbox.html.twig b/templates/message-private--inbox.html.twig | |
new file mode 100644 | |
index 0000000..0cb2460 | |
--- /dev/null | |
+++ b/templates/message-private--inbox.html.twig | |
@@ -0,0 +1,22 @@ | |
+{# | |
+/** | |
+ * @file | |
+ * Default theme implementation for message private inbox. | |
+ * | |
+ * This is displayed at '/user/{user}/messages' | |
+ * | |
+ * Available variables: | |
+ * - messages: An array of messages | |
+ * | |
+ * Other variables: | |
+ * - $classes_array: Array of html class attribute values. It is flattened | |
+ * into a string within the variable $classes. | |
+ * | |
+ * @see template_preprocess() | |
+ * @see template_preprocess_message() | |
+ * @see template_process() | |
+ */ | |
+#} | |
+{% for message in messages %} | |
+ {{ message }} | |
+{% endfor %} | |
\ No newline at end of file | |
diff --git a/templates/message-private--sent.html.twig b/templates/message-private--sent.html.twig | |
new file mode 100644 | |
index 0000000..791c3b9 | |
--- /dev/null | |
+++ b/templates/message-private--sent.html.twig | |
@@ -0,0 +1,22 @@ | |
+{# | |
+/** | |
+ * @file | |
+ * Default theme implementation for message private inbox. | |
+ * | |
+ * This is displayed at '/user/{user}/messages/sent' | |
+ * | |
+ * Available variables: | |
+ * - messages: An array of messages | |
+ * | |
+ * Other variables: | |
+ * - $classes_array: Array of html class attribute values. It is flattened | |
+ * into a string within the variable $classes. | |
+ * | |
+ * @see template_preprocess() | |
+ * @see template_preprocess_message() | |
+ * @see template_process() | |
+ */ | |
+#} | |
+{% for message in messages %} | |
+ {{ message }} | |
+{% endfor %} | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment