Commit 723e772d authored by New Zeal's avatar New Zeal

Issue #2902903 by zenimagine: Error with installation

parent ec45df25
8.x-1.0-alpha2
Hide private messages tab
Disable to field in message
\ No newline at end of file
......@@ -3,23 +3,30 @@
This module enables messages to be grouped into threads or conversations. For instance,
it is used with the message_private module to create conversations between individuals and groups of individuals.
#### Features
The module keeps track of who is (and was) in the conversation
The module enables you to add fields such as title to a conversation
The module enables an individual to have simultaneous conversations with different people and keep the conversations
separate in the inbox
- Keep track of who is (and was) in the conversation
- Create different types of conversations
- Have simultaneous conversations with different people and keep the conversations separate
#### Requirements
Message stack modules including:
Message
Message Private
#### Installation
#### Installation
Install module as normal or using composer or drush
#### Configuration
When installed, along with the Private Message module, no further installation should be required
#### Configuration
When installed, along with the Private Message module:
The module creates a default message thread bundle called Conversation
On the /user page there should be a tab called Conversations
Click on that and you can start creating a conversation
Once the conversation is created, send a message
All messages sent within that conversation are shown on the conversation page
Set permissions to allow roles to create message threads and private messages
......@@ -18,19 +18,12 @@ content:
label: inline
settings: { }
third_party_settings: { }
field_thread_title:
weight: 0
label: hidden
settings:
link_to_entity: false
third_party_settings: { }
type: string
message_thread_messages:
weight: 3
weight: 2
settings: { }
third_party_settings: { }
message_thread_reply:
weight: 2
weight: 0
settings: { }
third_party_settings: { }
messages:
......@@ -41,4 +34,5 @@ hidden:
entity_print_view_epub: true
entity_print_view_pdf: true
entity_print_view_word_docx: true
field_thread_title: true
reply: true
......@@ -80,7 +80,7 @@ display:
relationship: none
group_type: group
admin_label: ''
label: ''
label: Date
exclude: false
alter:
alter_text: false
......@@ -140,6 +140,71 @@ display:
entity_type: message
entity_field: created
plugin_id: field
uid:
id: uid
table: message_field_data
field: uid
relationship: none
group_type: group
admin_label: ''
label: Sender
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: target_id
type: entity_reference_label
settings:
link: true
group_column: target_id
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
entity_type: message
entity_field: uid
plugin_id: field
field_message_private_body:
id: field_message_private_body
table: message__field_message_private_body
......@@ -147,7 +212,7 @@ display:
relationship: none
group_type: group
admin_label: ''
label: ''
label: Message
exclude: false
alter:
alter_text: false
......@@ -212,7 +277,22 @@ display:
entity_type: message
entity_field: template
plugin_id: bundle
sorts: { }
sorts:
created:
id: created
table: message_field_data
field: created
relationship: none
group_type: group
admin_label: ''
order: DESC
exposed: false
expose:
label: ''
granularity: second
entity_type: message
entity_field: created
plugin_id: date
title: Inbox
header: { }
footer: { }
......
......@@ -6,6 +6,4 @@ type: module
configure: message_thread.admin_settings
dependencies:
- views
- message
- message_notify
- message_ui
- message_private
......@@ -6,29 +6,9 @@
/**
* Implements hook_uninstall.
*
* Remove the field_message_private_usr_notify field.
* Remove the index table
*/
function message_thread_uninstallx() {
$properties = array(
'entity_type' => 'user',
'bundle' => 'user',
'include_deleted' => TRUE,
);
// Get the fields based on the above properties.
$fields = \Drupal::entityManager()->getStorage('field_config')->loadByProperties($properties);
// Cycle through user fields looking for our user notify field.
foreach ($fields as $field) {
/* @var \Drupal\Core\Field\FieldConfigBase $field */
// If we have the user notify field, purge the data and remove.
if(!empty($field->getName() == 'field_message_private_usr_notify')) {
// Purge previously deleted field tables for entity type.
Drupal::entityManager()->getStorage($field->getTargetEntityTypeId())->purgeFieldData($field, 100);
field_cron();
$field->delete();
}
}
function message_thread_uninstall() {
db_drop_table('message_thread_index');
}
......@@ -59,6 +59,8 @@ function message_thread_form_alter(array &$form, FormStateInterface $form_state,
$form['field_message_private_to_user']['widget'][$key] = $widget_base;
$form['field_message_private_to_user']['widget'][$key]['target_id']['#default_value'] = User::load($participant['target_id']);
}
// We also should disable the to field because this is controlled from the thread
$form['field_message_private_to_user']['#disabled'] = TRUE;
foreach (array_keys($form['actions']) as $action) {
......@@ -90,6 +92,7 @@ function message_thread_submit_message(array &$form, FormStateInterface $form_st
)
)->execute();
}
/**
* Implements hook_entity_extra_field_info().
*/
......@@ -131,17 +134,6 @@ function message_thread_entity_extra_field_info() {
return $extra_fields;
}
/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function message_thread_form_entity_view_display_edit_form_alter($form, $form_state) {
// ksm($form['fields']['message_thread_messages']['plugin']['type']);
// $form['fields']['messages']['settings_edit'] = array(
//
// );
}
/**
* Implements hook_entity_view_alter().
*/
......@@ -282,4 +274,12 @@ function message_thread_message_thread_access_control($params) {
return AccessResult::allowed();
}
}
}
/*
* Implements hook_local_tasks_alter().
*/
function message_thread_local_tasks_alter(&$local_tasks) {
//We no longer need the private message local task on the user page
unset($local_tasks['message_private.messages']);
}
\ No newline at end of file
......@@ -9,3 +9,6 @@ overview message threads:
bypass message thread access control:
title: 'Bypass message thread access control'
description: 'Bypass message thread access control'
permission_callbacks:
- Drupal\message_thread\MessageThreadPermissions::permissions
......@@ -119,7 +119,6 @@ class MessageThreadController extends ControllerBase implements ContainerInjecti
}
unset( $form['#submit']);
//ksm($form);
return $form;
}
......
......@@ -279,7 +279,7 @@ class MessageThreadForm extends ContentEntityForm {
drupal_set_message(t('@type %title has been updated.', $t_args));
}
// Redirect to message view display if user has access.
// Redirect to message thread view display if user has access.
if ($message_thread->id()) {
$form_state->setValue('thread_id', $message_thread->id());
$form_state->set('thread_id', $message_thread->id());
......
......@@ -123,17 +123,19 @@ class MessageThreadTemplateForm extends EntityForm {
];
/*
* Message Views
*/
$form['settings']['view_id'] = [
'#title' => $this->t('Message View'),
* Message thread views
*/
$options = ['_none' => 'None'];
$options += $this->getMessageViews('message_thread_field_data');
$form['settings']['thread_view_id'] = [
'#title' => $this->t('Message Thread View'),
'#type' => 'select',
'#options' => $this->getMessageViews(),
'#default_value' => isset($settings['view_id']) ? $settings['view_id'] : '',
'#description' => $this->t('Select the View you wish to use to display messages of this type.'),
'#options' => $options,
'#default_value' => isset($settings['thread_view_id']) ? $settings['thread_view_id'] : '',
'#description' => $this->t('Select the View you wish to use to display threads messages of this type in the tab on the User page.'),
'#target_type' => 'view',
'#ajax' => array(
'callback' => array($this, 'getDisplayIds'),
'callback' => array($this, 'getThreadDisplayIds'),
'event' => 'change',
'progress' => array(
'type' => 'throbber',
......@@ -142,47 +144,45 @@ class MessageThreadTemplateForm extends EntityForm {
)
];
$default_value = isset($settings['view_id']) ? $settings['view_id'] : '';
$default_value = isset($settings['thread_view_id']) ? $settings['thread_view_id'] : '';
if ($default_value == '') {
$options = $this->getAllViewsDisplayIds();
}
else {
$options = $this->getViewDisplayIds($settings['view_id']);
$options = $this->getViewDisplayIds($settings['thread_view_id']);
}
$form['settings']['view_display_id'] = [
'#title' => $this->t('Message View Display'),
$form['settings']['thread_view_display_id'] = [
'#title' => $this->t('Message Thread View Display'),
'#type' => 'select',
'#options' => $options,
'#default_value' => isset($settings['view_display_id']) ? $settings['view_display_id'] : '',
'#default_value' => isset($settings['thread_view_display_id']) ? $settings['thread_view_display_id'] : '',
'#description' => $this->t('Select the Display from the View you selected above.'),
'#attributes' => array(
'class' => array(
'message-view-display-id',
'message-thread-view-display-id',
),
),
'#states' => array(
'visible' => array(
':input[name="settings[view_id]"]' => array('!value' => '_none'),
':input[name="settings[thread_view_id]"]' => array('!value' => '_none'),
),
),
];
/*
* Message thread views
* Message Views
*/
$options = ['_none' => 'None'];
$options += $this->getMessageViews('message_thread_field_data');
$form['settings']['thread_view_id'] = [
'#title' => $this->t('Message Thread View'),
$form['settings']['view_id'] = [
'#title' => $this->t('Message View'),
'#type' => 'select',
'#options' => $options,
'#default_value' => isset($settings['thread_view_id']) ? $settings['thread_view_id'] : '',
'#description' => $this->t('Select the View you wish to use to display messages of this type.'),
'#options' => $this->getMessageViews(),
'#default_value' => isset($settings['view_id']) ? $settings['view_id'] : '',
'#description' => $this->t('Select the View you wish to use to display messages of this type when viewing a thread.'),
'#target_type' => 'view',
'#ajax' => array(
'callback' => array($this, 'getThreadDisplayIds'),
'callback' => array($this, 'getDisplayIds'),
'event' => 'change',
'progress' => array(
'type' => 'throbber',
......@@ -191,33 +191,34 @@ class MessageThreadTemplateForm extends EntityForm {
)
];
$default_value = isset($settings['thread_view_id']) ? $settings['thread_view_id'] : '';
$default_value = isset($settings['view_id']) ? $settings['view_id'] : '';
if ($default_value == '') {
$options = $this->getAllViewsDisplayIds();
}
else {
$options = $this->getViewDisplayIds($settings['thread_view_id']);
$options = $this->getViewDisplayIds($settings['view_id']);
}
$form['settings']['thread_view_display_id'] = [
'#title' => $this->t('Message Thread View Display'),
$form['settings']['view_display_id'] = [
'#title' => $this->t('Message View Display'),
'#type' => 'select',
'#options' => $options,
'#default_value' => isset($settings['thread_view_display_id']) ? $settings['thread_view_display_id'] : '',
'#default_value' => isset($settings['view_display_id']) ? $settings['view_display_id'] : '',
'#description' => $this->t('Select the Display from the View you selected above.'),
'#attributes' => array(
'class' => array(
'message-thread-view-display-id',
'message-view-display-id',
),
),
'#states' => array(
'visible' => array(
':input[name="settings[thread_view_id]"]' => array('!value' => '_none'),
':input[name="settings[view_id]"]' => array('!value' => '_none'),
),
),
];
$form['description'] = [
'#title' => $this->t('Description'),
'#type' => 'textfield',
......
......@@ -85,11 +85,13 @@ class MessageThreadListBuilder extends EntityListBuilder {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/** @var Message $entity */
return [
'changed' => $this->dateService->format($entity->getCreatedTime(), 'short'),
// 'title' => $this->get('field_thread_title')->getValue()[0]['value'],
'text' => $entity->getText(),
'tread' => $entity->getThread()->label(),
'template' => $entity->getTemplate()->label(),
'author' => $entity->getOwner()->label(),
];
}
......
<?php
/**
* @file
* Contains \Drupal\message_thread\MessageThreadPermissions.
*/
namespace Drupal\message_thread;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MessageThreadPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Constructs a TaxonomyViewsIntegratorPermissions instance.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('entity.manager'));
}
/**
* Get permissions for Taxonomy Views Integrator.
*
* @return array
* Permissions array.
*/
public function permissions() {
$permissions = [];
foreach ($this->entityManager->getStorage('message_thread_template')->loadMultiple() as $template) {
$permissions += [
'create and receive ' . $template->id() => [
'title' => $this->t('Able to participate in %thread threads', array('%thread' => $template->label())),
]
];
}
return $permissions;
}
}
......@@ -12,6 +12,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\views\Views;
use Drupal\Core\Routing\RouteProviderInterface;
/**
......@@ -26,15 +27,18 @@ class DynamicLocalTasks extends DeriverBase implements ContainerDeriverInterface
protected $entityTypeManager;
protected $routeProvider;
/**
* Constructs the message thread template form.
*
* @param \Drupal\message\MessagePurgePluginManager $purge_manager
* The message purge plugin manager service.
*/
public function __construct($base_plugin_id, EntityStorageInterface $template_storage, EntityTypeManager $entity_type_manager) {
public function __construct($base_plugin_id, EntityStorageInterface $template_storage, EntityTypeManager $entity_type_manager, RouteProviderInterface $route_provider) {
$this->templateStorage = $template_storage;
$this->entityTypeManager = $entity_type_manager;
$this->routeProvider = $route_provider;
}
/**
......@@ -44,7 +48,8 @@ class DynamicLocalTasks extends DeriverBase implements ContainerDeriverInterface
return new static(
$base_plugin_id,
$container->get('entity_type.manager')->getStorage('message_template'),
$container->get('entity_type.manager')
$container->get('entity_type.manager'),
$container->get('router.route_provider')
);
}
......@@ -65,9 +70,13 @@ class DynamicLocalTasks extends DeriverBase implements ContainerDeriverInterface
foreach ($thread_templates as $name => $template) {
$settings = $template->getSettings();
// Thread page tabs\
// Thread page tabs
$view_route = 'view.' . $settings['thread_view_id'] . '.' . $settings['thread_view_display_id'];
$exists = count($this->routeProvider->getRoutesByNames([$view_route])) === 1;
if (!$exists) {
continue;
}
// User page tab
$view = Views::getView($settings['thread_view_id']);
$view->setDisplay($settings['thread_view_display_id']);
......@@ -91,7 +100,6 @@ class DynamicLocalTasks extends DeriverBase implements ContainerDeriverInterface
}
return $this->derivatives;
}
}
......@@ -11,7 +11,7 @@ use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Entity\EntityStorageInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\Core\Routing\RouteSubscriberBase;
use Drupal\Core\Routing\RoutingEvents;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\views\Views;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
......@@ -32,15 +32,18 @@ class MessageThreadRoutes implements ContainerInjectionInterface {
protected $entityTypeManager;
protected $routeProvider;
/**
* Constructs the message thread template form.
*
* @param \Drupal\message\MessagePurgePluginManager $purge_manager
* The message purge plugin manager service.
*/
public function __construct(EntityTypeManager $entity_type_manager, $template_storage) {
public function __construct(EntityTypeManager $entity_type_manager, $template_storage, RouteProviderInterface $route_provider) {
$this->templateStorage = $template_storage;
$this->entityTypeManager = $entity_type_manager;
$this->routeProvider = $route_provider;
}
/**
......@@ -49,7 +52,8 @@ class MessageThreadRoutes implements ContainerInjectionInterface {
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager'),
$container->get('entity_type.manager')->getStorage('message_template')
$container->get('entity_type.manager')->getStorage('message_template'),
$container->get('router.route_provider')
);
}
......@@ -58,6 +62,7 @@ class MessageThreadRoutes implements ContainerInjectionInterface {
*/
public function routes() {
$route_collection = new RouteCollection();
// Create a route for each template
$thread_templates = $this->entityTypeManager->getListBuilder('message_thread_template')->load();
......@@ -65,12 +70,21 @@ class MessageThreadRoutes implements ContainerInjectionInterface {
foreach ($thread_templates as $name => $template) {
$settings = $template->getSettings();
// This is being called before the view route is being registered when the module is first installed
// @todo is there are better way of handling this?
$view_route = 'view.' . $settings['thread_view_id'] . '.' . $settings['thread_view_display_id'];
$exists = count($this->routeProvider->getRoutesByNames([$view_route])) === 1;
if (!$exists) {
continue;
}
$view = Views::getView($settings['thread_view_id']);
$view->setDisplay($settings['thread_view_display_id']);
$url = $view->getUrl()->toString();
// This is not going to work if the View is not placed in the User page
$url = str_replace('%2A', '{user}', $url);
$route = new Route(
$url,
[
......@@ -78,7 +92,7 @@ class MessageThreadRoutes implements ContainerInjectionInterface {
'_title' => $template->label(),
],
[
'_permission' => 'access content'
'_permission' => 'create and receive ' . $template->id()
]
);
$route_collection->add('message_thread.' . $name, $route);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment