Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename messageType to messageTemplate #112

Merged
merged 1 commit into from Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Expand Up @@ -18,7 +18,7 @@ A general logging utility that can be used as activity module.
Tokens
======
* "Dynamic" tokens
When defining a message type, it is possible to use Drupal tokens in any of the
When defining a message template, it is possible to use Drupal tokens in any of the
message fields, in order to inject certain content into the field on the fly.
E.g. Entering the string "[current-date:short]" to the message text will
display the current request time instead of the token.
Expand All @@ -29,7 +29,7 @@ Tokens
(For instance: [message:field_node_ref:title]).
This relies on "Entity token" module that ships with Entity API.
Enabling "Token" module is also recommened, as it provides more tokens
and shows a token browser in the message type creation page.
and shows a token browser in the message template creation page.

* "Single use" tokens
The single-use tokens are similiar to the dynamic tokens, excepet they're
Expand Down Expand Up @@ -62,7 +62,7 @@ Partials
The message body has multiple cardinallity, allowing to separate html markup
from the actual message content, and also, allowing to only render a selected
part of the message.
The partials are reflected in the "Manage display" page of every message type,
The partials are reflected in the "Manage display" page of every message template,
allowing the administrator to re-order and hide them per view mode.
Furthermore, if Views and Panels module are enabled, it is possible to render
the message "partials" using the views module's "Panel fields" format.
Expand All @@ -72,7 +72,7 @@ View modes
==========
Message module exposes the "message-text" field(s) and allows an
administrator to set visibility and order via "Manage display" page, e.g.
admin/structure/messages/manage/[YOUR-MESSAGE-TYPE]/display
admin/structure/messages/manage/[YOUR-MESSAGE-TEMPLATE]/display

Auto-purging
============
Expand All @@ -83,11 +83,11 @@ definition.
Under admin/config/message it is possible to set purging definition by
maximal quota or maximal message age in days.

* Message type purging definition
Each message type my override the global purging settings. Under
admin/structure/messages/manage/[YOUR-MESSAGE-TYPE], clicking the
* Message template purging definition
Each message template my override the global purging settings. Under
admin/structure/messages/manage/[YOUR-MESSAGE-TEMPLATE], clicking the
"Override global settings" checkbox will make the global settings ignore the
current message type and will allow to set purging definitions for the current
type.
current message template and will allow to set purging definitions for the current
template.


30 changes: 15 additions & 15 deletions config/optional/views.view.message.yml
Expand Up @@ -83,7 +83,7 @@ display:
columns:
message_bulk_form_1: message_bulk_form_1
mid: mid
type: type
template: template
get_text: get_text
uid: uid
created: created
Expand All @@ -100,7 +100,7 @@ display:
separator: ''
empty_column: false
responsive: ''
type:
template:
sortable: true
default_sort_order: asc
align: ''
Expand Down Expand Up @@ -253,14 +253,14 @@ display:
entity_type: null
entity_field: mid
plugin_id: field
type:
id: type
template:
id: template
table: message_field_data
field: type
field: template
relationship: none
group_type: group
admin_label: ''
label: 'Message type'
label: 'Message template'
exclude: false
alter:
alter_text: false
Expand Down Expand Up @@ -316,7 +316,7 @@ display:
separator: ', '
field_api_classes: false
entity_type: message
entity_field: type
entity_field: template
plugin_id: field
get_text:
id: get_text
Expand Down Expand Up @@ -488,10 +488,10 @@ display:
entity_field: created
plugin_id: date
filters:
type:
id: type
template:
id: template
table: message_field_data
field: type
field: template
relationship: none
group_type: group
admin_label: ''
Expand All @@ -500,12 +500,12 @@ display:
group: 1
exposed: true
expose:
operator_id: type_op
label: Type
operator_id: template_op
label: Template
description: ''
use_operator: false
operator: type_op
identifier: type
operator: template_op
identifier: template
required: false
remember: false
multiple: false
Expand All @@ -527,7 +527,7 @@ display:
default_group_multiple: { }
group_items: { }
entity_type: message
entity_field: type
entity_field: template
plugin_id: bundle
sorts: { }
title: Message
Expand Down
6 changes: 3 additions & 3 deletions config/schema/message.schema.yml
Expand Up @@ -18,11 +18,11 @@ message.settings:
purge_quota:
type: integer

message.type.*:
message.template.*:
type: config_entity
label: 'Message type'
label: 'Message template'
mapping:
type:
template:
type: string
label: 'Machine-readable name'
label:
Expand Down
137 changes: 137 additions & 0 deletions message.api.php
@@ -0,0 +1,137 @@
<?php

/**
* @file
* Hooks provided by the Message module.
*/

use Drupal\message\Entity\Message;

/**
* @addtogroup hooks
* @{
*/

/**
* Act on a message that is being assembled before rendering.
*
* The module may add elements to $message->content prior to rendering. The
* structure of $message->content is a renderable array as expected by
* drupal_render().
*
* @param \Drupal\message\Entity\Message $message
* The message entity.
* @param string $view_mode
* The view mode the message is rendered in.
* @param string $langcode
* The language code used for rendering.
*
* @see hook_entity_prepare_view()
* @see hook_entity_view()
*/
function hook_message_view(Message $message, $view_mode, $langcode) {
$message->content['my_additional_field'] = [
'#markup' => 'foo',
'#weight' => 10,
'#theme' => 'mymodule_my_additional_field',
];
}

/**
* Alter the results of entity_view() for messages.
*
* This hook is called after the content has been assembled in a structured
* array and may be used for doing processing which requires that the complete
* message content structure has been built.
*
* If the module wishes to act on the rendered HTML of the message rather than
* the structured content array, it may use this hook to add a #post_render
* callback. Alternatively, it could also implement hook_preprocess_message().
* See drupal_render() and theme() documentation respectively for details.
*
* @param array $build
* A renderable array representing the message content.
*
* @see hook_entity_view_alter()
*/
function hook_message_view_alter(array &$build) {
if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
// Change its weight.
$build['an_additional_field']['#weight'] = -10;

// Add a #post_render callback to act on the rendered HTML of the entity.
$build['#post_render'][] = 'my_module_post_render';
}
}

/**
* Define default message template configurations.
*
* @return array
* An array of default message templates, keyed by machine names.
*
* @see hook_default_message_template_alter()
*/
function hook_default_message_template() {
$defaults['main'] = entity_create('message_template', []);
return $defaults;
}

/**
* Alter default message template configurations.
*
* @param array $defaults
* An array of default message templates, keyed by machine names.
*
* @see hook_default_message_template()
*/
function hook_default_message_template_alter(array &$defaults) {
$defaults['main']->name = 'custom name';
}

/**
* Alter message template forms.
*
* Modules may alter the message template entity form by making use of this hook or
* the entity bundle specific hook_form_message_template_edit_BUNDLE_form_alter().
* #entity_builders may be used in order to copy the values of added form
* elements to the entity, just as documented for
* entity_form_submit_build_entity().
*
* @param array $form
* Nested array of form elements that comprise the form.
* @param array $form_state
* A keyed array containing the current state of the form.
*/
function hook_form_message_template_form_alter(array &$form, array &$form_state) {
// Your alterations.
}

/**
* Define default message template category configurations.
*
* @return array
* An array of default message template categories, keyed by machine names.
*
* @see hook_default_message_category_alter()
*/
function hook_default_message_category() {
$defaults['main'] = entity_create('message_category', []);
return $defaults;
}

/**
* Alter default message template category configurations.
*
* @param array $defaults
* An array of default message template categories, keyed by machine names.
*
* @see hook_default_message_category()
*/
function hook_default_message_category_alter(array &$defaults) {
$defaults['main']->name = 'custom name';
}

/**
* @} End of "addtogroup hooks".
*/
8 changes: 4 additions & 4 deletions message.links.action.yml
@@ -1,5 +1,5 @@
message.type_add:
route_name: message.type_add
title: 'Add message type'
message.template_add:
route_name: message.template_add
title: 'Add message template'
appears_on:
- message.overview_types
- message.overview_templates
8 changes: 4 additions & 4 deletions message.links.menu.yml
@@ -1,8 +1,8 @@
message.overview_types:
title: 'Message types'
message.overview_templates:
title: 'Message templates'
parent: system.admin_structure
description: 'Manage message types.'
route_name: message.overview_types
description: 'Manage message templates.'
route_name: message.overview_templates

message.main_settings:
title: 'Message'
Expand Down
8 changes: 4 additions & 4 deletions message.links.task.yml
@@ -1,9 +1,9 @@
message.type_add:
route_name: message.type_add
base_route: message.type_add
message.template_add:
route_name: message.template_add
base_route: message.template_add
title: 'View'

messages.admin:
title: Messages
route_name: message.messages
base_route: node.content_overview
base_route: node.content_overview