Merge be44ea9a73
into c13d8fee32
This commit is contained in:
commit
9bca82fce5
|
@ -60,6 +60,9 @@ function farm_modules() {
|
|||
'farm_import_csv' => t('CSV importer'),
|
||||
'farm_export_kml' => t('KML exporter'),
|
||||
'farm_import_kml' => t('KML asset importer'),
|
||||
'farm_comment_asset' => t('Asset comments'),
|
||||
'farm_comment_log' => t('Log comments'),
|
||||
'farm_comment_plan' => t('Plan comments'),
|
||||
'farm_map_mapbox' => t('Mapbox map layers: Satellite, Outdoors'),
|
||||
'farm_api_default_consumer' => t('Default API Consumer'),
|
||||
'farm_fieldkit' => t('Field Kit integration'),
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
name: farmOS Comment
|
||||
description: Adds support for comments on farmOS entities.
|
||||
type: module
|
||||
package: farmOS
|
||||
core_version_requirement: ^10
|
||||
dependencies:
|
||||
- drupal:comment
|
|
@ -0,0 +1,3 @@
|
|||
farm_comment:
|
||||
permission_callbacks:
|
||||
- Drupal\farm_comment\CommentPermissions::permissions
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains farm_comment.module.
|
||||
*/
|
||||
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\entity\BundleFieldDefinition;
|
||||
|
||||
/**
|
||||
* Helper function for generating a standard comment base field definition.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type.
|
||||
*
|
||||
* @return \Drupal\Core\Field\BaseFieldDefinition
|
||||
* Returns a comment base field definition.
|
||||
*/
|
||||
function farm_comment_base_field_definition(string $entity_type) {
|
||||
|
||||
// Create a new comment field definition.
|
||||
// We use BundleFieldDefinition instead of BaseFieldDefinition to force Drupal
|
||||
// to create a separate database table for this field. Otherwise, if it is
|
||||
// added to the base table then the comment field default value is always 0
|
||||
// (CommentItemInterface::HIDDEN) instead of 2 (CommentItemInterface::OPEN),
|
||||
// because the Drupal\comment\Plugin\Field\FieldType\CommentItem::schema()
|
||||
// default is 0.
|
||||
$field = BundleFieldDefinition::create('comment');
|
||||
|
||||
// Set the field label.
|
||||
$field->setLabel(t('Comments'));
|
||||
|
||||
// We assume that the comment type matches the entity type.
|
||||
$field->setSetting('comment_type', $entity_type);
|
||||
|
||||
// A default value must be set for comment fields.
|
||||
// Enable comments on entities by default.
|
||||
$default_value = [
|
||||
[
|
||||
'status' => CommentItemInterface::OPEN,
|
||||
'cid' => 0,
|
||||
'last_comment_timestamp' => 0,
|
||||
'last_comment_name' => '',
|
||||
'last_comment_uid' => 0,
|
||||
'comment_count' => 0,
|
||||
],
|
||||
];
|
||||
$field->setDefaultValue($default_value);
|
||||
|
||||
// Build form display settings.
|
||||
$field->setDisplayOptions('form', [
|
||||
'type' => 'comment_default',
|
||||
'weight' => 1000,
|
||||
]);
|
||||
|
||||
// Build view display settings.
|
||||
// Display comments on the bottom of entity view displays by default, with the
|
||||
// field label above them.
|
||||
$field->setDisplayOptions('view', [
|
||||
'label' => 'above',
|
||||
'type' => 'comment_default',
|
||||
'weight' => 1000,
|
||||
]);
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_farm_ui_theme_region_items().
|
||||
*/
|
||||
function farm_comment_farm_ui_theme_region_items(string $entity_type) {
|
||||
return [
|
||||
'bottom' => [
|
||||
'comment',
|
||||
],
|
||||
];
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
enforced:
|
||||
module:
|
||||
- farm_comment_asset
|
||||
id: asset
|
||||
label: 'Asset comment'
|
||||
target_entity_type_id: asset
|
||||
description: ''
|
|
@ -0,0 +1,31 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- comment.type.asset
|
||||
- field.field.comment.asset.comment_body
|
||||
enforced:
|
||||
module:
|
||||
- farm_comment_asset
|
||||
module:
|
||||
- text
|
||||
id: comment.asset.default
|
||||
targetEntityType: comment
|
||||
bundle: asset
|
||||
mode: default
|
||||
content:
|
||||
author:
|
||||
weight: 0
|
||||
region: content
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
comment_body:
|
||||
type: text_textarea
|
||||
weight: 1
|
||||
region: content
|
||||
settings:
|
||||
rows: 5
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
hidden:
|
||||
subject: true
|
|
@ -0,0 +1,29 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- comment.type.asset
|
||||
- field.field.comment.asset.comment_body
|
||||
enforced:
|
||||
module:
|
||||
- farm_comment_asset
|
||||
module:
|
||||
- text
|
||||
id: comment.asset.default
|
||||
targetEntityType: comment
|
||||
bundle: asset
|
||||
mode: default
|
||||
content:
|
||||
comment_body:
|
||||
type: text_default
|
||||
label: hidden
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
weight: 0
|
||||
region: content
|
||||
links:
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
weight: 1
|
||||
region: content
|
||||
hidden: { }
|
|
@ -0,0 +1,23 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- comment.type.asset
|
||||
- field.storage.comment.comment_body
|
||||
enforced:
|
||||
module:
|
||||
- farm_comment_asset
|
||||
module:
|
||||
- text
|
||||
id: comment.asset.comment_body
|
||||
field_name: comment_body
|
||||
entity_type: comment
|
||||
bundle: asset
|
||||
label: Comment
|
||||
description: ''
|
||||
required: true
|
||||
translatable: true
|
||||
default_value: { }
|
||||
default_value_callback: ''
|
||||
settings: { }
|
||||
field_type: text_long
|
|
@ -0,0 +1,8 @@
|
|||
name: Asset comments
|
||||
description: Enables comments on farmOS assets.
|
||||
type: module
|
||||
package: farmOS
|
||||
core_version_requirement: ^10
|
||||
dependencies:
|
||||
- farm:asset
|
||||
- farm:farm_comment
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains farm_comment_asset.module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_entity_base_field_info().
|
||||
*/
|
||||
function farm_comment_asset_entity_base_field_info(EntityTypeInterface $entity_type) {
|
||||
$fields = [];
|
||||
|
||||
// Add comment base field to assets.
|
||||
if ($entity_type->id() == 'asset') {
|
||||
$fields['comment'] = farm_comment_base_field_definition('asset');
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
enforced:
|
||||
module:
|
||||
- farm_comment_log
|
||||
id: log
|
||||
label: 'Log comment'
|
||||
target_entity_type_id: log
|
||||
description: ''
|
|
@ -0,0 +1,31 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- comment.type.log
|
||||
- field.field.comment.log.comment_body
|
||||
enforced:
|
||||
module:
|
||||
- farm_comment_log
|
||||
module:
|
||||
- text
|
||||
id: comment.log.default
|
||||
targetEntityType: comment
|
||||
bundle: log
|
||||
mode: default
|
||||
content:
|
||||
author:
|
||||
weight: 0
|
||||
region: content
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
comment_body:
|
||||
type: text_textarea
|
||||
weight: 1
|
||||
region: content
|
||||
settings:
|
||||
rows: 5
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
hidden:
|
||||
subject: true
|
|
@ -0,0 +1,29 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- comment.type.log
|
||||
- field.field.comment.log.comment_body
|
||||
enforced:
|
||||
module:
|
||||
- farm_comment_log
|
||||
module:
|
||||
- text
|
||||
id: comment.log.default
|
||||
targetEntityType: comment
|
||||
bundle: log
|
||||
mode: default
|
||||
content:
|
||||
comment_body:
|
||||
type: text_default
|
||||
label: hidden
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
weight: 0
|
||||
region: content
|
||||
links:
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
weight: 1
|
||||
region: content
|
||||
hidden: { }
|
|
@ -0,0 +1,23 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- comment.type.log
|
||||
- field.storage.comment.comment_body
|
||||
enforced:
|
||||
module:
|
||||
- farm_comment_log
|
||||
module:
|
||||
- text
|
||||
id: comment.log.comment_body
|
||||
field_name: comment_body
|
||||
entity_type: comment
|
||||
bundle: log
|
||||
label: Comment
|
||||
description: ''
|
||||
required: true
|
||||
translatable: true
|
||||
default_value: { }
|
||||
default_value_callback: ''
|
||||
settings: { }
|
||||
field_type: text_long
|
|
@ -0,0 +1,8 @@
|
|||
name: Log comments
|
||||
description: Enables comments on farmOS logs.
|
||||
type: module
|
||||
package: farmOS
|
||||
core_version_requirement: ^10
|
||||
dependencies:
|
||||
- farm:farm_comment
|
||||
- log:log
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains farm_comment_log.module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_entity_base_field_info().
|
||||
*/
|
||||
function farm_comment_log_entity_base_field_info(EntityTypeInterface $entity_type) {
|
||||
$fields = [];
|
||||
|
||||
// Add comment base field to logs.
|
||||
if ($entity_type->id() == 'log') {
|
||||
$fields['comment'] = farm_comment_base_field_definition('log');
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
enforced:
|
||||
module:
|
||||
- farm_comment_plan
|
||||
id: plan
|
||||
label: 'Plan comment'
|
||||
target_entity_type_id: plan
|
||||
description: ''
|
|
@ -0,0 +1,31 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- comment.type.plan
|
||||
- field.field.comment.plan.comment_body
|
||||
enforced:
|
||||
module:
|
||||
- farm_comment_plan
|
||||
module:
|
||||
- text
|
||||
id: comment.plan.default
|
||||
targetEntityType: comment
|
||||
bundle: plan
|
||||
mode: default
|
||||
content:
|
||||
author:
|
||||
weight: 0
|
||||
region: content
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
comment_body:
|
||||
type: text_textarea
|
||||
weight: 1
|
||||
region: content
|
||||
settings:
|
||||
rows: 5
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
hidden:
|
||||
subject: true
|
|
@ -0,0 +1,29 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- comment.type.plan
|
||||
- field.field.comment.plan.comment_body
|
||||
enforced:
|
||||
module:
|
||||
- farm_comment_plan
|
||||
module:
|
||||
- text
|
||||
id: comment.plan.default
|
||||
targetEntityType: comment
|
||||
bundle: plan
|
||||
mode: default
|
||||
content:
|
||||
comment_body:
|
||||
type: text_default
|
||||
label: hidden
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
weight: 0
|
||||
region: content
|
||||
links:
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
weight: 1
|
||||
region: content
|
||||
hidden: { }
|
|
@ -0,0 +1,23 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- comment.type.plan
|
||||
- field.storage.comment.comment_body
|
||||
enforced:
|
||||
module:
|
||||
- farm_comment_plan
|
||||
module:
|
||||
- text
|
||||
id: comment.plan.comment_body
|
||||
field_name: comment_body
|
||||
entity_type: comment
|
||||
bundle: plan
|
||||
label: Comment
|
||||
description: ''
|
||||
required: true
|
||||
translatable: true
|
||||
default_value: { }
|
||||
default_value_callback: ''
|
||||
settings: { }
|
||||
field_type: text_long
|
|
@ -0,0 +1,8 @@
|
|||
name: Plan comments
|
||||
description: Enables comments on farmOS plans.
|
||||
type: module
|
||||
package: farmOS
|
||||
core_version_requirement: ^10
|
||||
dependencies:
|
||||
- farm:farm_comment
|
||||
- farm:plan
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains farm_comment_plan.module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_entity_base_field_info().
|
||||
*/
|
||||
function farm_comment_plan_entity_base_field_info(EntityTypeInterface $entity_type) {
|
||||
$fields = [];
|
||||
|
||||
// Add comment base field to plans.
|
||||
if ($entity_type->id() == 'plan') {
|
||||
$fields['comment'] = farm_comment_base_field_definition('plan');
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_comment;
|
||||
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Add comment permissions to managed farmOS roles.
|
||||
*/
|
||||
class CommentPermissions {
|
||||
|
||||
/**
|
||||
* Add permissions to role.
|
||||
*
|
||||
* @param \Drupal\user\RoleInterface $role
|
||||
* The role to add permissions to.
|
||||
*
|
||||
* @return array
|
||||
* An array of permission strings.
|
||||
*/
|
||||
public function permissions(RoleInterface $role) {
|
||||
$perms = [];
|
||||
|
||||
// Load farm_role access rules from third-party settings. Bail if empty.
|
||||
$access = $role->getThirdPartySetting('farm_role', 'access');
|
||||
if (empty($access)) {
|
||||
return $perms;
|
||||
}
|
||||
|
||||
// If the role has "view all" access, allow viewing comments.
|
||||
if (!empty($access['entity']['view all'])) {
|
||||
$perms[] = 'access comments';
|
||||
}
|
||||
|
||||
// If the role has "edit all" access, allow posting/editing comments.
|
||||
if (!empty($access['entity']['update all'])) {
|
||||
$perms[] = 'post comments';
|
||||
$perms[] = 'skip comment approval';
|
||||
$perms[] = 'edit own comments';
|
||||
}
|
||||
|
||||
return $perms;
|
||||
}
|
||||
|
||||
}
|
|
@ -37,6 +37,13 @@ function farm_ui_theme_theme($existing, $type, $theme, $path) {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme_registry_alter().
|
||||
*/
|
||||
function farm_ui_theme_theme_registry_alter(&$theme_registry) {
|
||||
$theme_registry['comment']['path'] = \Drupal::service('extension.list.module')->getPath('farm_ui_theme') . '/templates';
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
|
@ -143,7 +150,6 @@ function farm_ui_theme_gin_content_form_routes() {
|
|||
* Implements hook_entity_type_build().
|
||||
*/
|
||||
function farm_ui_theme_entity_type_build(array &$entity_types) {
|
||||
|
||||
// Override the default add and edit form class.
|
||||
$target_entity_types = [
|
||||
'asset' => AssetForm::class,
|
||||
|
@ -183,6 +189,15 @@ function farm_ui_theme_preprocess_block(&$variables) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_HOOK().
|
||||
*/
|
||||
function farm_ui_theme_preprocess_field(&$variables) {
|
||||
if ($variables['field_type'] == 'comment') {
|
||||
$variables['attributes']['class'][] = 'gin-layer-wrapper';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_HOOK().
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
{#
|
||||
/**
|
||||
* @file
|
||||
* Theme override for comments.
|
||||
*
|
||||
* Available variables:
|
||||
* - author: (optional) Comment author. Can be a link or plain text.
|
||||
* - content: The content-related items for the comment display. Use
|
||||
* {{ content }} to print them all, or print a subset such as
|
||||
* {{ content.field_example }}. Use the following code to temporarily suppress
|
||||
* the printing of a given child element:
|
||||
* @code
|
||||
* {{ content|without('field_example') }}
|
||||
* @endcode
|
||||
* - created: (optional) Formatted date and time for when the comment was
|
||||
* created. Preprocess functions can reformat it by calling
|
||||
* DateFormatter::format() with the desired parameters on the
|
||||
* 'comment.created' variable.
|
||||
* - changed: (optional) Formatted date and time for when the comment was last
|
||||
* changed. Preprocess functions can reformat it by calling
|
||||
* DateFormatter::format() with the desired parameters on the
|
||||
* 'comment.changed' variable.
|
||||
* - permalink: Comment permalink.
|
||||
* - submitted: (optional) Submission information created from author and
|
||||
* created during template_preprocess_comment().
|
||||
* - user_picture: (optional) The comment author's profile picture.
|
||||
* - status: Comment status. Possible values are:
|
||||
* unpublished, published, or preview.
|
||||
* - title: (optional) Comment title, linked to the comment.
|
||||
* - attributes: HTML attributes for the containing element.
|
||||
* The attributes.class may contain one or more of the following classes:
|
||||
* - comment: The current template type; e.g., 'theming hook'.
|
||||
* - by-anonymous: Comment by an unregistered user.
|
||||
* - by-{entity-type}-author: Comment by the author of the parent entity,
|
||||
* eg. by-node-author.
|
||||
* - preview: When previewing a new or edited comment.
|
||||
* The following applies only to viewers who are registered users:
|
||||
* - unpublished: An unpublished comment visible only to administrators.
|
||||
* - title_prefix: Additional output populated by modules, intended to be
|
||||
* displayed in front of the main title tag that appears in the template.
|
||||
* - title_suffix: Additional output populated by modules, intended to be
|
||||
* displayed after the main title tag that appears in the template.
|
||||
* - content_attributes: List of classes for the styling of the comment content.
|
||||
* - title_attributes: Same as attributes, except applied to the main title
|
||||
* tag that appears in the template.
|
||||
* - threaded: A flag indicating whether the comments are threaded or not.
|
||||
*
|
||||
* These variables are provided to give context about the parent comment (if
|
||||
* any, optional):
|
||||
* - parent_comment: Full parent comment entity (if any).
|
||||
* - parent_author: Equivalent to author for the parent comment.
|
||||
* - parent_created: Equivalent to created for the parent comment.
|
||||
* - parent_changed: Equivalent to changed for the parent comment.
|
||||
* - parent_title: Equivalent to title for the parent comment.
|
||||
* - parent_permalink: Equivalent to permalink for the parent comment.
|
||||
* - parent: A text string of parent comment submission information created from
|
||||
* 'parent_author' and 'parent_created' during template_preprocess_comment().
|
||||
* This information is presented to help screen readers follow lengthy
|
||||
* discussion threads. You can hide this from sighted users using the class
|
||||
* visually-hidden.
|
||||
*
|
||||
* These two variables are provided for context:
|
||||
* - comment: Full comment object.
|
||||
* - commented_entity: Entity the comments are attached to.
|
||||
*
|
||||
* @see template_preprocess_comment()
|
||||
*/
|
||||
#}
|
||||
{% if threaded %}
|
||||
{{ attach_library('claro/classy.indented') }}
|
||||
{% endif %}
|
||||
{%
|
||||
set classes = [
|
||||
'comment',
|
||||
'js-comment',
|
||||
status != 'published' ? status,
|
||||
comment.owner.anonymous ? 'by-anonymous',
|
||||
author_id and author_id == commented_entity.getOwnerId() ? 'by-' ~ commented_entity.getEntityTypeId() ~ '-author',
|
||||
]
|
||||
%}
|
||||
<article{{ attributes.addClass(classes) }}>
|
||||
{#
|
||||
Hide the "new" indicator by default, let a piece of JavaScript ask the
|
||||
server which comments are new for the user. Rendering the final "new"
|
||||
indicator here would break the render cache.
|
||||
#}
|
||||
<mark class="hidden" data-comment-timestamp="{{ new_indicator_timestamp }}"></mark>
|
||||
|
||||
{% if submitted %}
|
||||
<footer class="comment__meta">
|
||||
<p class="comment__submitted">{{ submitted }}</p>
|
||||
|
||||
{#
|
||||
Indicate the semantic relationship between parent and child comments for
|
||||
accessibility. The list is difficult to navigate in a screen reader
|
||||
without this information.
|
||||
#}
|
||||
{% if parent %}
|
||||
<p class="parent visually-hidden">{{ parent }}</p>
|
||||
{% endif %}
|
||||
</footer>
|
||||
{% endif %}
|
||||
|
||||
<div{{ content_attributes.addClass('content') }}>
|
||||
{{ content }}
|
||||
</div>
|
||||
</article>
|
Loading…
Reference in New Issue