Skip to content
Snippets Groups Projects

Issue #3390146: GitLan CI

Open Steven Ayers requested to merge issue/comment_delete-3390146:3390146-gitlab-ci into 2.x
Files
7
+ 1
123
@@ -5,134 +5,12 @@ namespace Drupal\comment_delete;
use Drupal\comment\CommentInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides comment delete permissions for each comment field.
*/
class CommentDeleteAccess implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected EntityTypeManagerInterface $entityTypeManager;
/**
* The entity type bundle info.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected EntityTypeBundleInfoInterface $entityTypeBundleInfo;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected EntityFieldManagerInterface $entityFieldManager;
/**
* CommentDeleteAccess constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entityTypeBundleInfo
* The entity type bundle info.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
* The entity field manager.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, EntityTypeBundleInfoInterface $entityTypeBundleInfo, EntityFieldManagerInterface $entityFieldManager) {
$this->entityTypeManager = $entityTypeManager;
$this->entityTypeBundleInfo = $entityTypeBundleInfo;
$this->entityFieldManager = $entityFieldManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager'),
$container->get('entity_type.bundle.info'),
$container->get('entity_field.manager'),
);
}
/**
* Define comment delete user permissions.
*
* @return array
* Returns an associative array of user permissions.
*/
public function permissions(): array {
$permissions = [];
$definitions = $this->entityTypeManager->getDefinitions();
$bundleInfo = $this->entityTypeBundleInfo->getAllBundleInfo();
foreach ($this->entityFieldManager->getFieldMapByFieldType('comment') as $entityTypeId => $fields) {
foreach ($fields as $fieldName => $map) {
foreach ($map['bundles'] as $bundleId) {
$fieldDefinitions = $this->entityFieldManager->getFieldDefinitions($entityTypeId, $bundleId);
/** @var \Drupal\field\FieldConfigInterface $fieldDefinition */
$fieldDefinition = $fieldDefinitions[$fieldName];
$args = [
'@type' => $definitions[$entityTypeId]->getLabel(),
'%bundle' => $bundleInfo[$entityTypeId][$bundleId]['label'],
'%field' => $fieldDefinition->getLabel(),
];
$permissions += [
"delete own $entityTypeId $bundleId $fieldName" => [
'title' => $this->t('@type: Delete own %bundle %field', $args),
],
"delete own $entityTypeId $bundleId $fieldName anytime" => [
'title' => $this->t('@type: Delete own %bundle %field anytime', $args),
],
"delete any $entityTypeId $bundleId $fieldName" => [
'title' => $this->t('@type: Delete any %bundle %field', $args),
],
"delete any $entityTypeId $bundleId $fieldName anytime" => [
'title' => $this->t('@type: Delete any %bundle %field anytime', $args),
],
"delete $entityTypeId $bundleId $fieldName replies" => [
'title' => $this->t('@type: Delete %bundle %field replies', $args),
'description' => $this->t('Delete any immediate reply to own comment.'),
],
"delete $entityTypeId $bundleId $fieldName replies anytime" => [
'title' => $this->t('@type: Delete %bundle %field replies anytime', $args),
'description' => $this->t('Delete any immediate reply to own comment.'),
],
"allow $entityTypeId $bundleId $fieldName hard delete" => [
'title' => $this->t('@type: Allow %bundle %field hard delete', $args),
'description' => $this->t('Use the hard delete operation.'),
],
"allow $entityTypeId $bundleId $fieldName hard_partial delete" => [
'title' => $this->t('@type: Allow %bundle %field partial hard delete', $args),
'description' => $this->t('Use the partial hard delete operation.'),
],
"allow $entityTypeId $bundleId $fieldName soft delete" => [
'title' => $this->t('@type: Allow %bundle %field soft delete', $args),
'description' => $this->t('Use the soft delete operation.'),
],
];
}
}
}
return $permissions;
}
class CommentDeleteAccess {
/**
* Delete operation access callback for comments.
Loading