Commit bc395df3 authored by New Zeal's avatar New Zeal

create tabs and improve workflow

parent ec1baba4
......@@ -25,4 +25,7 @@ Add cache context to breadcrumbs
Add message history functionality
8.x-1.0-alpha9
Fix thread delete function
\ No newline at end of file
Fix thread delete function
8.x-1.0-alpha10
Make the threads control area tidier adding tabs and improving workflow
\ No newline at end of file
uuid: 0de98e51-c4df-42a7-89ba-754ec06dd8bb
langcode: en
status: true
dependencies:
config:
- field.storage.message_thread.field_thread_participants
- message_thread.template.conversation
_core:
default_config_hash: t_dV_y17DnRHyNwlueXJMi7T1cHvcCvVHwyEs-6wDjs
id: message_thread.conversation.field_thread_participants
field_name: field_thread_participants
entity_type: message_thread
bundle: conversation
label: Participants
description: ''
required: false
required: true
translatable: false
default_value: { }
default_value_callback: ''
......
uuid: 16ab6995-bb35-4142-8ecd-cfc929c19d21
langcode: en
status: true
dependencies:
config:
- field.storage.message_thread.field_thread_title
- message_thread.template.conversation
_core:
default_config_hash: xTQTQtfQ7g24lXlcZGO3u6B4FjjXVf0PM7zv9iuUqHk
id: message_thread.conversation.field_thread_title
field_name: field_thread_title
entity_type: message_thread
bundle: conversation
label: Title
description: 'A title to give this conversation'
required: false
required: true
translatable: false
default_value: { }
default_value_callback: ''
......
uuid: ad109b3f-5d82-44c3-b803-8a11a077b523
langcode: en
status: true
dependencies:
module:
- message_thread
- user
_core:
default_config_hash: MC0s-7agSyiBQAjqJWOmRm490W1whtpovjURVdaQ4N8
id: message_thread.field_thread_participants
field_name: field_thread_participants
entity_type: message_thread
......
uuid: ac9b814d-5eda-424d-82d2-352d4eddb13e
langcode: en
status: true
dependencies:
module:
- message_thread
_core:
default_config_hash: L_o3YUa1iSamaRLlqZ_sHEv8nZZWH8j-DQE-ErS4GiI
id: message_thread.field_thread_title
field_name: field_thread_title
entity_type: message_thread
......@@ -17,4 +20,4 @@ cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
\ No newline at end of file
custom_storage: false
......@@ -8,6 +8,7 @@ dependencies:
module:
- message_private
- message_thread
- user
_core:
default_config_hash: UqAY1HdOAH7JtNrXnK5OGCxXSIJ6uZhbgRMT488UMSw
id: conversations
......@@ -236,20 +237,7 @@ display:
plugin_id: bundle
sorts: { }
title: Messages
header:
area:
id: area
table: views
field: area
relationship: none
group_type: group
admin_label: ''
empty: true
tokenize: false
content:
value: '<a href="/message-thread/add/conversation">Start a new conversation</a>'
format: basic_html
plugin_id: text
header: { }
footer: { }
empty: { }
relationships: { }
......@@ -301,6 +289,112 @@ display:
tags:
- 'config:field.storage.message_thread.field_thread_participants'
- 'config:field.storage.message_thread.field_thread_title'
block_1:
display_plugin: block
id: block_1
display_title: Inbox
position: 2
display_options:
display_extenders: { }
display_description: ''
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- user.permissions
tags:
- 'config:field.storage.message_thread.field_thread_participants'
- 'config:field.storage.message_thread.field_thread_title'
block_2:
display_plugin: block
id: block_2
display_title: Sent
position: 3
display_options:
display_extenders: { }
display_description: ''
filters:
template:
id: template
table: message_thread_field_data
field: template
value:
conversation: conversation
entity_type: message_thread
entity_field: template
plugin_id: bundle
uid_current:
id: uid_current
table: users
field: uid_current
relationship: uid
group_type: group
admin_label: ''
operator: '='
value: '1'
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: user
plugin_id: user_current
defaults:
filters: false
filter_groups: false
relationships: false
filter_groups:
operator: AND
groups:
1: AND
relationships:
uid:
id: uid
table: message_thread_field_data
field: uid
relationship: none
group_type: group
admin_label: User
required: true
entity_type: message_thread
entity_field: uid
plugin_id: standard
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- user
- user.permissions
tags:
- 'config:field.storage.message_thread.field_thread_participants'
- 'config:field.storage.message_thread.field_thread_title'
page_1:
display_plugin: page
id: page_1
......
......@@ -52,26 +52,9 @@ display:
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: full
type: none
options:
items_per_page: 25
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
style:
type: table
options:
......@@ -440,7 +423,7 @@ display:
group_type: group
admin_label: ''
label: ''
exclude: true
exclude: false
alter:
alter_text: false
text: ''
......@@ -485,59 +468,6 @@ display:
absolute: false
entity_type: message
plugin_id: entity_link_edit
view_message:
id: view_message
table: message
field: view_message
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: false
alter:
alter_text: true
text: "{{ view_message }}\n{{ edit_message }}"
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: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
text: view
output_url_as_text: false
absolute: false
entity_type: message
plugin_id: entity_link
filters: { }
sorts:
created:
......
entity.message_thread.edit_form:
route_name: entity.message_thread.edit_form
base_route: entity.message_thread.canonical
title: Edit
# Message thread tabs
task.message_thread.threads:
route_name: message_thread.threads
base_route: message_thread.threads
title: Inbox
task.message_thread.threads.sent:
route_name: message_thread.threads.sent
base_route: message_thread.threads
title: Sent
task.message_thread.threads:
route_name: message_thread.threads
base_route: message_thread.threads
title: Inbox
entity.message_thread.canonical:
task.message_thread.add:
route_name: message_thread.add_page
base_route: message_thread.threads
title: Add new Message
task.message_thread.canonical:
route_name: entity.message_thread.canonical
base_route: entity.message_thread.canonical
base_route: message_thread.threads
title: View
# Tabs for message management
task.message_thread.edit_form:
route_name: entity.message_thread.edit_form
base_route: message_thread.threads
title: Edit
task.message_thread.delete_form:
route_name: entity.message_thread.delete_form
base_route: message_thread.threads
title: Delete
## Provide dynamic local tasks.
message_thread.dynamic_tasks:
......
......@@ -19,6 +19,7 @@ use Drupal\Core\Access\AccessResult;
use Drupal\message_thread\MessageThreadAccessControlHandler;
use Drupal\message_private\MessagePrivateAccessControlHandler;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Utility\LinkGenerator;
/**
* Implements hook_installed.
......@@ -107,12 +108,32 @@ function message_thread_submit_message(array &$form, FormStateInterface $form_st
)->execute();
}
/*
* Implements hook_form_FORM_ID_alter().
*/
function message_thread_form_message_private_message_edit_form_alter(array &$form, FormStateInterface $form_state) {
// Redirect to the thread not the message
$mid = $form_state->getFormObject()->getEntity()->id();
$params = array(
'message_thread' => message_thread_relationship($mid)
);
$url = Url::fromRoute('entity.message_thread.canonical', $params);
$form_state->setRedirectUrl($url);
$link = [
'#type' => 'link',
'#url' => $url,
'#title' => t('Cancel')
];
$form['actions']['cancel'] = $link;
}
/*
* Implements hook_form_FORM_ID_alter().
*/
function message_thread_form_message_thread_conversation_edit_form_alter(array &$form, FormStateInterface $form_state) {
$form['field_thread_participants']['widget']['add_more']['#value'] = new TranslatableMarkup('Add another user');
$form['owner']['#access'] = \Drupal::currentUser()->hasPermission('bypass private message access control');
$form['advanced']['#access'] = \Drupal::currentUser()->hasPermission('bypass private message access control');
}
/*
......@@ -121,6 +142,7 @@ function message_thread_form_message_thread_conversation_edit_form_alter(array &
function message_thread_form_message_thread_conversation_form_alter(array &$form, FormStateInterface $form_state) {
$form['field_thread_participants']['widget']['add_more']['#value'] = new TranslatableMarkup('Add another user');
$form['owner']['#access'] = \Drupal::currentUser()->hasPermission('bypass private message access control');
$form['advanced']['#access'] = \Drupal::currentUser()->hasPermission('bypass private message access control');
}
/**
* Implements hook_preprocess_links().
......@@ -291,7 +313,7 @@ function message_thread_reply_link($entity, $component) {
);
$options = [
'query' => [
'destination' => '/message-thread/' . $entity->id()
'destination' => '/message/thread/' . $entity->id()
]
];
$url = Url::fromRoute('message_thread.reply', $params, $options);
......@@ -336,8 +358,6 @@ function message_thread_message_count($entity) {
function message_thread_add_message_form_submit(&$form, FormStateInterface &$form_state) {
$values = $form_state->getValues();
return;
}
/**
......@@ -405,3 +425,62 @@ function message_thread_tab_access_check() {
return AccessResult::allowedIfHasPermission($account, 'bypass private message access control');
}
/*
* Helper function to relate a message to its thread
*/
function message_thread_relationship($mid) {
$thread_id = db_select('message_thread_index', 'mdi')
->condition('mdi.mid', $mid)
->fields('mdi', ['thread_id'])
->execute()
->fetchField();
return $thread_id;
}
/*
* Helper function to get all message ids in a thread
*/
function message_thread_get_messages($thread_id) {
$result = db_select('message_thread_index', 'mdi')
->condition('mdi.thread_id', $thread_id)
->fields('mdi', ['mid'])
->execute()
->fetchAll();
$messages = [];
foreach ($result as $record) {
$messages[] = $record->mid;
}
return $messages;
}
/**
* Implements hook_ENTITY_TYPE_view_alter() for message thread entities.
*/
function message_history_message_thread_view_alter(array &$build, EntityInterface $message_thread,
EntityViewDisplayInterface
$display) {
// Update the message_history table, stating that this user viewed all messages in this thread.
if (!\Drupal::service('module_handler')->moduleExists('message_history')) {
return;
}
if (!in_array($display->getOriginalMode(), ['default', 'full'])) {
return;
}
$build['#cache']['contexts'][] = 'user.roles:authenticated';
if (!\Drupal::currentUser()->isAuthenticated()) {
return;
}
// Find all messages in this thread and mark them read
$messages = message_thread_get_messages($message_thread->id());
foreach ($messages as $mid) {
$build['#attached']['drupalSettings']['message_history']['itemsToMarkAsRead'][$mid] = TRUE;
}
$build['#attached']['library'][] = 'message_history/mark-as-read';
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ message_thread.overview_templates:
#message_thread.thread_add:
# path: '/message-thread/add'
# path: '/message/thread/add'
# defaults:
# _entity_form: 'message_thread.add'
# _title: 'Add message thread'
......@@ -49,7 +49,7 @@ entity.message_thread_template.delete_form:
_permission: 'administer message templates'
message_thread.add_page:
path: '/message-thread/add'
path: '/message/thread/add'
defaults:
_title: 'Add Message Thread'
_controller: '\Drupal\message_thread\Controller\MessageThreadController::addPage'
......@@ -58,7 +58,7 @@ message_thread.add_page:
_entity_create_access: 'message_thread'
message_thread.add:
path: '/message-thread/add/{message_thread_template}'
path: '/message/thread/add/{message_thread_template}'
defaults:
# Calls the form.add controller, defined in the message entity alter hook.
_controller: '\Drupal\message_thread\Controller\MessageThreadController::add'
......@@ -71,7 +71,7 @@ message_thread.add:
with_config_overrides: FALSE
entity.message_thread.edit_form:
path: '/message-thread/{message_thread}/edit'
path: '/message/thread/{message_thread}/edit'
defaults:
# Calls the form.edit controller, defined in the message entity alter hook.
_entity_form: message_thread.edit
......@@ -80,7 +80,7 @@ entity.message_thread.edit_form:
_entity_access: 'message_thread.edit'
entity.message_thread.delete_form:
path: '/message-thread/{message_thread}/delete'
path: '/message/thread/{message_thread}/delete'
defaults:
# Calls the form.delete controller, defined in the message entity alter hook.
_entity_form: message_thread.delete
......@@ -89,7 +89,7 @@ entity.message_thread.delete_form:
_entity_access: 'message_thread.delete'
message_thread.threads:
path: '/user/{user}/threads'
path: '/message/threads'
defaults:
_controller: '\Drupal\message_thread\Controller\MessageThreadController::inbox'
_title: 'Message Threads'
......@@ -98,7 +98,7 @@ message_thread.threads:
_permission: 'overview message threads'
message_thread.threads.inbox:
path: '/user/{user}/threads/inbox'
path: '/message/threads/inbox'
defaults:
_controller: '\Drupal\message_thread\Controller\MessageThreadController::inbox'
_title: 'Inbox'
......@@ -107,16 +107,16 @@ message_thread.threads.inbox:
_permission: 'overview message threads'
message_thread.threads.sent:
path: '/user/{user}/threads/sent'
path: '/message/threads/sent'
defaults:
_controller: '\Drupal\message_thread\Controller\MessageThreadController::sent'
_title: 'Sent'
description: 'Message Thread Sent'
requirements:
_permission: 'overview messages'
_permission: 'overview message threads'
#entity.message_thread.canonical:
# path: '/message-thread/{message_thread}'
# path: '/message/thread/{message_thread}'
# defaults:
# # Calls the view controller, defined the message entity alter hook.
# _entity_view: 'message_thread'
......@@ -137,13 +137,5 @@ message_thread.reply:
message_template:
with_config_overrides: FALSE
# The default View that comes with this module
#message_thread.conversations:
# path: '/user/{user}/conversations'
# defaults:
# _controller: '\Drupal\message_thread\Controller\MessageThreadController::inBox'
# requirements:
# _custom_access: '_message_thread_tab_access_check'
route_callbacks:
- 'Drupal\message_thread\Routing\MessageThreadRoutes::routes'
\ No newline at end of file
......@@ -10,6 +10,7 @@ use Drupal\message_thread\MessageThreadTemplateInterface;
use Drupal\message_thread\MessageThreadInterface;
use Drupal\message\Entity\Message;
use Drupal\Component\Utility\Xss;
use Drupal\views\Views;
/**
* Controller for adding messages.
......@@ -49,7 +50,6 @@ class MessageThreadController extends ControllerBase implements ContainerInjecti
*/
public function addPage() {
$content = [];
//dpm('here we are');
// Only use message templates the user has access to.
foreach ($this->entityManager()->getStorage('message_thread_template')->loadMultiple() as $template) {
$access = $this->entityManager()
......@@ -144,18 +144,59 @@ class MessageThreadController extends ControllerBase implements ContainerInjecti
* @return
* A render array for a list of the messages;
*/
public function inBox($user) {
$message_threads = array();
public function inBox() {
// Get threads that the current user belongs to
// Return build array.
if (!empty($messages)) {
$view_name = 'conversations';
$display_id = 'block_1';
$argument = \Drupal::currentUser()->id();
$view = Views::getView($view_name);
// Someone may have deleted the View.
if (!is_object($view)) {
return array(
'#markup' => t('The View for message thread inbox has been deleted.')
);
}
// No access.
if (!$view->access($display_id)) {
return array(
'#theme' => 'message_thread__inbox',
'#messages' => $message_threads
'#markup' => t('You do not have access to this resource.')
);
}
$view->setDisplay($display_id);
if ($argument) {
$arguments = [$argument];
if (preg_match('/\//', $argument)) {
$arguments = explode('/', $argument);
}
$view->setArguments($arguments);
}
$view->preExecute();
$view->execute($display_id);
// if ($title) {
// $title = $view->getTitle();
// $title_render_array = [
// '#theme' => $view->buildThemeFunctions('viewsreference__view_title'),
// '#title' => $title,
// '#view' => $view,
// ];
// }
// if ($this->getSetting('plugin_types')) {
// if ($title) {
// $elements[$delta]['title'] = $title_render_array;
// }
// }
$message_threads = $view->buildRenderable($display_id);
// Return build array.
if (!empty($message_threads)) {
return $message_threads;
}
else {
$url = Url::fromRoute('message.template_add');
return array(
......@@ -181,14 +222,58 @@ class MessageThreadController extends ControllerBase implements ContainerInjecti
* @return array
* An array as expected by drupal_render().
*/
public function sent($user) {
// Return build array.
if (!empty($messages)) {
public function sent() {
$view_name = 'conversations';
$display_id = 'block_2';
$argument = \Drupal::currentUser()->id();
$view = Views::getView($view_name);
// Someone may have deleted the View.
if (!is_object($view)) {
return array(
'#markup' => t('The View for message thread sent has been deleted.')
);
}
// No access.
if (!$view->access($display_id)) {
return array(
'#theme' => 'message_private__inbox',
'#messages' => $messages
'#markup' => t('You do not have access to this resource.')
);
}
$view->setDisplay($display_id);
if ($argument) {
$arguments = [$argument];
if (preg_match('/\//', $argument)) {
$arguments = explode('/', $argument);
}
$view->setArguments($arguments);
}
$view->preExecute();
$view->execute($display_id);
// if ($title) {
// $title = $view->getTitle();
// $title_render_array = [
// '#theme' => $view->buildThemeFunctions('viewsreference__view_title'),
// '#title' => $title,
// '#view' => $view,
// ];
// }
// if ($this->getSetting('plugin_types')) {
// if ($title) {
// $elements[$delta]['title'] = $title_render_array;
// }
// }
$message_threads = $view->buildRenderable($display_id);
// Return build array.
if (!empty($message_threads)) {