Skip to content
Snippets Groups Projects
Commit 918cb007 authored by Tamás Pintér's avatar Tamás Pintér Committed by Scott Euser
Browse files

Issue #2994003 by mr.york, nagy.balint, scott_euser: Dynamic permissions for...

Issue #2994003 by mr.york, nagy.balint, scott_euser: Dynamic permissions for site_setting types - Add interface for creating site settings that view access is denied for but create access granted
parent 641d7a69
No related branches found
No related merge requests found
......@@ -35,14 +35,18 @@ class SiteSettingEntityListBuilder extends EntityListBuilder {
/**
* Constructs a new EntityListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator
* @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator
* Link generator.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, LinkGeneratorInterface $link_generator) {
public function __construct(
EntityTypeInterface $entity_type,
EntityStorageInterface $storage,
LinkGeneratorInterface $link_generator
) {
parent::__construct($entity_type, $storage);
$this->linkGeneration = $link_generator;
}
......@@ -50,7 +54,10 @@ class SiteSettingEntityListBuilder extends EntityListBuilder {
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
public static function createInstance(
ContainerInterface $container,
EntityTypeInterface $entity_type
) {
return new static(
$entity_type,
$container->get('entity_type.manager')->getStorage($entity_type->id()),
......@@ -130,13 +137,17 @@ class SiteSettingEntityListBuilder extends EntityListBuilder {
'#header' => $this->buildHeader(),
'#title' => $this->getTitle(),
'#rows' => [],
'#empty' => $this->t('There is no @label yet.', ['@label' => $this->entityType->getLabel()]),
'#empty' => $this->t('There is no @label yet.',
['@label' => $this->entityType->getLabel()]),
'#cache' => [
'contexts' => $this->entityType->getListCacheContexts(),
'tags' => $this->entityType->getListCacheTags(),
],
];
// Storage for entities the user is allowed to create but is not allowed
// to update. Used when site_settings_type_permissions submodule is enabled.
$creatable_non_viewable_entities = [];
$last_fieldset = FALSE;
foreach ($this->load() as $entity) {
// Get bundle type.
......@@ -169,6 +180,51 @@ class SiteSettingEntityListBuilder extends EntityListBuilder {
$build['table']['#rows'][$entity->id()] = $row;
}
}
elseif ($entity->access('create')) {
// User is allowed to create this site setting type but cannot view.
$creatable_non_viewable_entities[$bundle_type] = $entity;
}
}
// If we have site settings the user can create but not update.
if ($creatable_non_viewable_entities) {
// Add site settings that can be created.
foreach ($creatable_non_viewable_entities as $bundle => $entity) {
$url = new Url('entity.site_setting_entity.add_form', [
'site_setting_entity_type' => $bundle,
]);
if ($url->access()) {
// Add link if user has access.
$link = [
'#type' => 'link',
'#title' => $this->t('Create setting'),
'#url' => $url,
'#attributes' => ['class' => ['button']],
];
array_unshift($build['table']['#rows'], [
'name' => $this->linkGeneration->generate($entity->label(), $url),
'fieldset' => $entity->fieldset->value,
'value' => '',
'operations' => \Drupal::service('renderer')->render($link),
]);
}
}
// Add heading.
$heading = [
'#markup' => '<strong>' . $this->t('Settings where more can be created') . '</strong>',
];
array_unshift($build['table']['#rows'], [
'name' => \Drupal::service('renderer')->render($heading),
'fieldset' => '',
'value' => '',
'operations' => '',
]);
}
// If we have site settings not yet created.
......@@ -202,7 +258,8 @@ class SiteSettingEntityListBuilder extends EntityListBuilder {
'#attributes' => ['class' => ['button']],
];
array_unshift($build['table']['#rows'], [
'name' => $this->linkGeneration->generate($this->bundles[$missing]->label(), $url),
'name' => $this->linkGeneration->generate($this->bundles[$missing]->label(),
$url),
'fieldset' => $this->bundles[$missing]->fieldset,
'value' => '',
'operations' => \Drupal::service('renderer')->render($link),
......@@ -236,10 +293,12 @@ class SiteSettingEntityListBuilder extends EntityListBuilder {
];
$operations = $this->getDefaultOperations($entity);
$operations += $this->moduleHandler()->invokeAll('entity_operation', [$entity]);
$operations += $this->moduleHandler()
->invokeAll('entity_operation', [$entity]);
$this->moduleHandler->alter('entity_operation', $operations, $entity);
uasort($operations, '\Drupal\Component\Utility\SortArray::sortByWeightElement');
uasort($operations,
'\Drupal\Component\Utility\SortArray::sortByWeightElement');
$build['operations'] = [
'#prefix' => '<div class="align-left clearfix">',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment