Skip to content

Commit bbdbba2

Browse files
committed
OS-94 adding os2forms_webform_list back
1 parent efba9e2 commit bbdbba2

File tree

5 files changed

+110
-1
lines changed

5 files changed

+110
-1
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ before starting to add changes. Use example [placed in the end of the page](#exa
1515

1616
- Obsolete module removing - os2forms_consent
1717
- Obsolete module removing - webform_embed
18-
- Obsolete module removing - os2forms_webform_list
1918
- Obsolete module removing - field_color
2019
- Obsolete patch removing - dynamic_entity_reference
2120
- Obsolete patch removing - user_default_page
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: OS2forms webform list
2+
type: module
3+
description: Alters display of webform list and maestro template list
4+
package: OS2Web
5+
core: 8.x
6+
core_version_requirement: ^8 || ^9 || ^10
7+
dependencies:
8+
- 'drupal:webform'
9+
- 'drupal:maestro'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Contains hooks related to OS2Forms webform list module.
6+
*/
7+
8+
/**
9+
* Implements hook_entity_type_alter().
10+
*
11+
* Change entitytypes.
12+
*/
13+
function os2forms_webform_list_entity_type_alter(array &$entity_types) {
14+
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
15+
// Define a new list builder classes.
16+
$entity_types['webform']->setListBuilderClass('Drupal\os2forms_webform_list\CustomWebformEntityListBuilder');
17+
$entity_types['maestro_template']->setListBuilderClass('Drupal\os2forms_webform_list\CustomMaestroTemplateEntityListBuilder');
18+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Drupal\os2forms_webform_list;
4+
5+
use Drupal\maestro\Controller\MaestroTemplateListBuilder;
6+
7+
/**
8+
* Defines a class to build a listing of maestro template entities.
9+
*
10+
* @see \Drupal\maestro\Entity\MaestroTemplate
11+
*/
12+
class CustomMaestroTemplateEntityListBuilder extends MaestroTemplateListBuilder {
13+
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
public function load() {
18+
$entity_ids = $this->getEntityIds();
19+
// @phpstan-ignore-next-line
20+
$entities = $this->storage->loadMultipleOverrideFree($entity_ids);
21+
22+
uasort($entities, [$this->entityType->getClass(), 'sort']);
23+
foreach ($entities as $entity_name => $entity) {
24+
$access = $entity->access('update');
25+
if (!$access) {
26+
unset($entities[$entity_name]);
27+
}
28+
}
29+
return $entities;
30+
}
31+
32+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Drupal\os2forms_webform_list;
4+
5+
use Drupal\Core\Entity\Query\QueryInterface;
6+
use Drupal\webform\WebformEntityListBuilder;
7+
8+
/**
9+
* Defines a class to build a listing of webform entities.
10+
*
11+
* @see \Drupal\webform\Entity\Webform
12+
*/
13+
class CustomWebformEntityListBuilder extends WebformEntityListBuilder {
14+
15+
/**
16+
* Alter the webform entity list builder query method.
17+
*
18+
* Force the list builder query to respect webform access and properly hide
19+
* inaccessible webforms from the list.
20+
*
21+
* @param string $keys
22+
* (optional) Search key.
23+
* @param string $category
24+
* (optional) Category.
25+
* @param string $state
26+
* (optional) Webform state. Can be 'open' or 'closed'.
27+
*
28+
* @return \Drupal\Core\Entity\Query\QueryInterface
29+
* An entity query.
30+
*/
31+
protected function getQuery($keys = '', $category = '', $state = ''): QueryInterface {
32+
$query = parent::getQuery($keys, $category, $state);
33+
34+
// Setup a required condition for the list builder to respect webform update
35+
// access.
36+
$allowedForms = [];
37+
/** @var \Drupal\webform\WebformInterface[] $webforms */
38+
$webforms = $this->getStorage()->loadMultiple();
39+
foreach ($webforms as $webform) {
40+
$access = $webform->access('update');
41+
if ($access) {
42+
$allowedForms[] = $webform->id();
43+
}
44+
}
45+
46+
$query->condition('id', $allowedForms, 'IN');
47+
48+
return $query;
49+
}
50+
51+
}

0 commit comments

Comments
 (0)