clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -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

View File

@@ -0,0 +1,3 @@
farm_comment:
permission_callbacks:
- Drupal\farm_comment\CommentPermissions::permissions

View File

@@ -0,0 +1,129 @@
<?php
/**
* @file
* Contains farm_comment.module.
*/
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
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);
// Disable previews.
$field->setSetting('preview', 0);
// 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' => 450,
]);
// 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_entity_form_display_alter().
*/
function farm_comment_entity_form_display_alter(EntityFormDisplayInterface $form_display, array $context) {
$comment_bundles = ['asset', 'log', 'plan'];
if ($form_display->getTargetEntityTypeId() == 'comment' && in_array($context['bundle'], $comment_bundles) && $form_display->getMode() == 'default' && $form_display->isNew()) {
$form_display->setComponent('author', [
'region' => 'content',
'settings' => [],
'weight' => 0,
]);
$form_display->setComponent('comment_body', [
'type' => 'text_textarea',
'region' => 'content',
'settings' => [
'rows' => 5,
'placeholder' => '',
],
'weight' => 1,
]);
$form_display->removeComponent('subject');
}
}
/**
* Implements hook_entity_view_display_alter().
*/
function farm_comment_entity_view_display_alter(EntityViewDisplayInterface $display, array $context) {
$comment_bundles = ['asset', 'log', 'plan'];
$display_modes = ['default', 'full'];
if ($context['entity_type'] == 'comment' && in_array($context['bundle'], $comment_bundles) && in_array($display->getMode(), $display_modes) && $display->isNew()) {
$display->setComponent('comment_body', [
'type' => 'text_default',
'label' => 'hidden',
'region' => 'content',
'settings' => [],
'weight' => 0,
]);
$display->setComponent('links', [
'region' => 'content',
'settings' => [],
'weight' => 1,
]);
}
}
/**
* Implements hook_farm_ui_theme_region_items().
*/
function farm_comment_farm_ui_theme_region_items(string $entity_type) {
return [
'bottom' => [
'comment',
],
];
}

View File

@@ -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: ''

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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: ''

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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: ''

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;
}
}