diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5624220..8ff2c0a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,11 +4,22 @@ All notable changes to this project should be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
-See ["how do I make a good changelog record?"](https://keepachangelog.com/en/1.0.0/#how)
+See ["how do I make a good changelog record?"](https://keepachangelog.com/en/1.0.0/#how)
before starting to add changes.
## [Unreleased]
+## [1.13.0] - 25.09.2023
+
+- Fixed missing icons on administration menu
+- Removed dependency to config_entity_revisions
+
+## [1.12.0] - 13.06.2023
+
+### Removed
+ - modules/os2forms_permissions_by_term moved to os2forms/os2forms repo
+ - modules/os2forms_webform_list moved to os2forms/os2forms repo
+
## [1.11.0] - 10.03.2023
- Added github action for checking changelog changes when creating pull requests
- Updated readme
@@ -24,7 +35,7 @@ before starting to add changes.
## [1.10.0]
-### Added
+### Added
- Feature/user permissions
- Feature/user management
diff --git a/composer.json b/composer.json
index 18973a1..c80dec7 100644
--- a/composer.json
+++ b/composer.json
@@ -20,8 +20,7 @@
"drupal/gin": "^3.0-rc",
"drupal/core": "^9",
"drush/drush": "^11.4",
- "os2forms/os2forms": "^3.3",
- "os2forms/os2forms_forloeb": "^2.5",
+ "os2forms/os2forms": "^3.6",
"os2web/os2web_simplesaml": "8.x-dev"
},
"require-dev": {
diff --git a/modules/os2forms_permissions_by_term/README.md b/modules/os2forms_permissions_by_term/README.md
deleted file mode 100644
index 6d305f7..0000000
--- a/modules/os2forms_permissions_by_term/README.md
+++ /dev/null
@@ -1,28 +0,0 @@
-# OS2Forms permission by term module
-This module implements permission by term access restrictions
-on several lists and entity displays related to webform and maestro.
-
-## Setup configuration
-Add to your settings.php or local.settings.php
-```
-$config['permissions_by_term.settings'] = [
- 'permissions_mode' => FALSE,
- 'require_all_terms_granted' => FALSE,
- 'disable_node_access_records' => FALSE
- 'target_bundles' => ['user_affiliation']
-]
-```
-Alternative change your site configuration on admin/permissions-by-term/settings to match the above.
-
-!note This is the recommended configuration of the permissions_by_term module. Using different values for
-'require_all_terms_granted', 'permissions_mode' or 'disable_node_access_records' may cause unexpected results and should
-be thoroughly tested.
-
-## Usage
-- The user affiliation taxonomy is added to webform config form, nodes (of type webform) and Maestro workflow forms.
-- The Permissions by Term module adds a form element to the user form.
-- When a user visits an entity of the above mentioned this module checks for match between the entity and the users
- affiliation. If no match is found access is denied.
-- The first taxonomy term in the user_affiliation taxonomy should be "Anonymous" with Taxonomy term permissions allowed
- for "Anonymous users"-role. This allows editors to make nodes accessible to anonymous users while removing it in backend
- from views and dropdowns.
diff --git a/modules/os2forms_permissions_by_term/config/install/taxonomy.vocabulary.user_affiliation.yml b/modules/os2forms_permissions_by_term/config/install/taxonomy.vocabulary.user_affiliation.yml
deleted file mode 100644
index 48dc2c3..0000000
--- a/modules/os2forms_permissions_by_term/config/install/taxonomy.vocabulary.user_affiliation.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-langcode: da
-status: true
-dependencies: { }
-name: Affiliation
-vid: user_affiliation
-description: ''
-weight: 0
diff --git a/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.info.yml b/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.info.yml
deleted file mode 100644
index 50ffef5..0000000
--- a/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.info.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-name: OS2Forms permissions by term
-type: module
-description: Adds taxonomy to webform configuration
-package: OS2Web
-core: 8.x
-core_version_requirement: ^8 || ^9
-dependencies:
- - 'drupal:webform'
- - 'drupal:permissions_by_term'
diff --git a/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.module b/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.module
deleted file mode 100644
index d63be5f..0000000
--- a/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.module
+++ /dev/null
@@ -1,140 +0,0 @@
-webformAlter($form, $form_state, 'add');
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- *
- * Alter the webform settings form.
- */
-function os2forms_permissions_by_term_form_webform_settings_form_alter(array &$form, FormStateInterface $form_state) {
- \Drupal::service('os2forms_permissions_by_term.helper')->webformAlter($form, $form_state, 'settings');
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- *
- * Alter the node add/edit form.
- */
-function os2forms_permissions_by_term_form_node_form_alter(array &$form, FormStateInterface $form_state) {
- \Drupal::service('os2forms_permissions_by_term.helper')->nodeFormAlter($form, $form_state);
-}
-
-/**
- * Implements hook_ENTITY_TYPE_access() for webform entities.
- *
- * Deny access to webforms based on permissions_by_term.
- */
-function os2forms_permissions_by_term_webform_access(WebformInterface $webform, $operation, AccountInterface $account) {
- return \Drupal::service('os2forms_permissions_by_term.helper')->webformAccess($webform, $operation, $account);
-}
-
-/**
- * Implements hook_ENTITY_TYPE_access() for node entities.
- *
- * Allow/deny access to node.
- */
-function os2forms_permissions_by_term_node_access(NodeInterface $node, $operation, AccountInterface $account) {
- return \Drupal::service('os2forms_permissions_by_term.helper')->nodeAccess($node, $operation, $account);
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- *
- * Alter maestro template add form.
- */
-function os2forms_permissions_by_term_form_maestro_template_add_form_alter(array &$form, FormStateInterface $form_state) {
- \Drupal::service('os2forms_permissions_by_term.maestro_template_helper')->maestroTemplateFormAlter($form, $form_state, 'add');
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- *
- * Alter maestro template edit form.
- */
-function os2forms_permissions_by_term_form_maestro_template_edit_form_alter(array &$form, FormStateInterface $form_state) {
- \Drupal::service('os2forms_permissions_by_term.maestro_template_helper')->maestroTemplateFormAlter($form, $form_state, 'settings');
-}
-
-/**
- * Implements hook_ENTITY_TYPE_access() for webform entities.
- *
- * Deny access to Maestro templates based on permissions_by_term.
- */
-function os2forms_permissions_by_term_maestro_template_access(ConfigEntityInterface $maestroTemplate, $operation, AccountInterface $account) {
- return \Drupal::service('os2forms_permissions_by_term.maestro_template_helper')->maestroTemplateAccess($maestroTemplate, $operation, $account);
-}
-
-/**
- * Implements hook_field_widget_multivalue_WIDGET_TYPE_form_alter().
- *
- * Alter the field webform_entity_reference widget.
- */
-function os2forms_permissions_by_term_field_widget_multivalue_webform_entity_reference_select_form_alter(array &$elements) {
- \Drupal::service('os2forms_permissions_by_term.helper')->fieldWidgetWebformEntityReferenceFormAlter($elements);
-}
-
-/**
- * Implements hook_form_alter().
- *
- * Alter maestro related forms.
- */
-function os2forms_permissions_by_term_form_alter(array &$form, FormStateInterface $form_state, string $form_id) {
- \Drupal::service('os2forms_permissions_by_term.maestro_template_helper')->maestroFormAlter($form, $form_state, $form_id);
-}
-
-/**
- * Implements hook_options_list_alter().
- *
- * Change options list field for node.field_os2forms_permissions.
- */
-function os2forms_permissions_by_term_options_list_alter(array &$options, array $context) {
- \Drupal::service('os2forms_permissions_by_term.helper')->optionsListAlter($options, $context);
-}
-
-/**
- * Implements hook_views_query_alter().
- *
- * Change views queries to account for permissions_by_term.
- */
-function os2forms_permissions_by_term_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
- \Drupal::service('os2forms_permissions_by_term.maestro_template_helper')->viewsQueryAlter($view, $query);
-}
diff --git a/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.services.yml b/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.services.yml
deleted file mode 100644
index 7f7bd48..0000000
--- a/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.services.yml
+++ /dev/null
@@ -1,22 +0,0 @@
-services:
- os2forms_permissions_by_term.helper:
- class: Drupal\os2forms_permissions_by_term\Helper\Helper
- arguments:
- - '@permissions_by_term.access_storage'
- - '@entity_type.manager'
- - '@current_user'
- - '@config.factory'
-
- os2forms_permissions_by_term.maestro_template_helper:
- class: Drupal\os2forms_permissions_by_term\Helper\MaestroTemplateHelper
- arguments:
- - '@permissions_by_term.access_storage'
- - '@entity_type.manager'
- - '@current_user'
- - '@config.factory'
- - '@os2forms_permissions_by_term.helper'
-
- os2forms_permissions_by_term.route_subscriber:
- class: Drupal\os2forms_permissions_by_term\Routing\RouteSubscriber
- tags:
- - { name: event_subscriber }
diff --git a/modules/os2forms_permissions_by_term/src/Helper/Helper.php b/modules/os2forms_permissions_by_term/src/Helper/Helper.php
deleted file mode 100644
index 06a916d..0000000
--- a/modules/os2forms_permissions_by_term/src/Helper/Helper.php
+++ /dev/null
@@ -1,432 +0,0 @@
-accessStorage = $accessStorage;
- $this->entityTypeManager = $entity_type_manager;
- $this->account = $account;
- $this->configFactory = $configFactory;
- }
-
- /**
- * Implementation of hook_form_FORM_ID_alter().
- *
- * Add permission by term selection to webform "add" and "settings".
- *
- * @param array $form
- * The form being altered.
- * @param \Drupal\Core\Form\FormStateInterface $form_state
- * The state of the form.
- * @param string $hook
- * The type of webform hook calling this method.
- *
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
- */
- public function webformAlter(array &$form, FormStateInterface $form_state, $hook) {
- /** @var \Drupal\Core\Entity\EntityForm $formObject */
- $formObject = $form_state->getFormObject();
- $node = $formObject->getEntity();
- if ('webform' !== $node->bundle()) {
- return;
- }
- $term_data = [];
- $user = $this->entityTypeManager->getStorage('user')->load($this->account->id());
- if (1 === (int) $this->account->id()) {
- $userTerms = [];
- $permissionsByTermBundles = $this->configFactory->get('permissions_by_term.settings')->get('target_bundles');
- foreach ($permissionsByTermBundles as $bundle) {
- $terms = $this->entityTypeManager->getStorage('taxonomy_term')->loadTree($bundle);
- foreach ($terms as $term) {
- $userTerms[] = $term->tid;
- }
- }
- }
- else {
- $userTerms = $this->accessStorage->getPermittedTids($user->id(), $user->getRoles());
- }
- $terms = $this->entityTypeManager->getStorage('taxonomy_term')->loadMultiple($userTerms);
- foreach ($terms as $term) {
- $term_data[$term->id()] = $term->label();
- }
-
- // Remove any options that allow anonymous access to the webform.
- $anonymousTerms = $this->accessStorage->getPermittedTids(0, ['anonymous']);
- foreach ($anonymousTerms as $termId) {
- unset($term_data[$termId]);
- }
-
- // Make sure title is first when creating a new webform.
- if ('add' === $hook) {
- $form['title']['#weight'] = -100;
- }
-
- // Get default settings for webform.
- if ('settings' === $hook) {
- /** @var \Drupal\Core\Entity\EntityForm $webform_settings_form */
- $webform_settings_form = $form_state->getFormObject();
- /** @var \Drupal\webform\WebformInterface $webform */
- $webform = $webform_settings_form->getEntity();
- $defaultSettings = $webform->getThirdPartySetting('os2forms_permissions_by_term', 'settings');
- }
-
- $form['os2forms_permissions_by_term'] = [
- '#type' => 'details',
- '#open' => TRUE,
- '#title' => $this->t('Webform access'),
- '#tree' => TRUE,
- '#weight' => -99,
- ];
-
- $form['os2forms_permissions_by_term']['os2forms_access'] = [
- '#type' => 'checkboxes',
- '#required' => TRUE,
- '#title' => $this->t('Access'),
- '#default_value' => $defaultSettings ?? [],
- '#options' => $term_data,
- '#description' => $this->t('Limit access to this webform.'),
- ];
-
- // Set access value automatically if user only has one term option.
- if ('add' === $hook && 1 === count($term_data)) {
- $form['os2forms_permissions_by_term']['os2forms_access']['#disabled'] = TRUE;
- $form['os2forms_permissions_by_term']['os2forms_access']['#value'] = [array_key_first($term_data) => array_key_first($term_data)];
- }
-
- $form['actions']['submit']['#submit'][] = [$this, 'webformSubmit'];
- }
-
- /**
- * Implementation of hook_ENTITY_TYPE_access().
- *
- * Check access on webform related operations.
- *
- * @param \Drupal\webform\WebformInterface $webform
- * The webform we check access for.
- * @param string $operation
- * The operation being performed on the webform.
- * @param \Drupal\Core\Session\AccountInterface $account
- * The current user.
- *
- * @return \Drupal\Core\Access\AccessResult
- * The resulting access permission.
- *
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
- */
- public function webformAccess(WebformInterface $webform, $operation, AccountInterface $account) {
- if (1 == $account->id()) {
- return AccessResult::neutral();
- }
- $user = $this->entityTypeManager->getStorage('user')->load($account->id());
- $userTerms = $this->accessStorage->getPermittedTids($user->id(), $user->getRoles());
- $webformPermissionsByTerm = $webform->getThirdPartySetting('os2forms_permissions_by_term', 'settings');
- switch ($operation) {
- case 'view':
- // We don't use permission by term to determine access to the actual
- // webform.
- // This could probably be removed, but is left in to show we are aware
- // of this operation.
- return AccessResult::neutral();
-
- case 'update':
- case 'delete':
- case 'duplicate':
- case 'test':
- case 'submission_page':
- case 'submission_view_any':
- case 'submission_view_own':
- case 'submission_purge_any':
- // Allow access if no term is set for the form or a webform term match
- // the users term.
- return empty($webformPermissionsByTerm) || !empty(array_intersect($webformPermissionsByTerm, $userTerms))
- ? AccessResult::neutral()
- : AccessResult::forbidden();
- }
-
- return AccessResult::neutral();
- }
-
- /**
- * Implementation of hook_ENTITY_TYPE_access().
- *
- * Check access on node related operations.
- *
- * @param \Drupal\node\NodeInterface $node
- * The node entity.
- * @param string $operation
- * The operation being performed on the node.
- * @param \Drupal\Core\Session\AccountInterface $account
- * The current user.
- *
- * @return mixed
- * The resulting access permission.
- */
- public function nodeAccess(NodeInterface $node, $operation, AccountInterface $account) {
- if ('webform' === $node->bundle()) {
- switch ($operation) {
- case 'view':
- // Deny access to node view if no permission by term is set.
- $nodePermissionsByTerm = $node->field_os2forms_permissions->getValue();
- return empty($nodePermissionsByTerm)
- ? AccessResult::forbidden()
- : AccessResult::neutral();
- }
- }
- }
-
- /**
- * Custom submit handler for webform add/edit form.
- *
- * Set permission by term as a thirdPartySetting of the webform.
- *
- * @param array $form
- * The webform add/edit form.
- * @param \Drupal\Core\Form\FormStateInterface $form_state
- * The state of the form.
- */
- public function webformSubmit(array $form, FormStateInterface $form_state) {
- // Get the settings from the webform config entity.
- /** @var \Drupal\Core\Entity\EntityForm $webform_settings_form */
- $webform_settings_form = $form_state->getFormObject();
- /** @var \Drupal\webform\WebformInterface $webform */
- $webform = $webform_settings_form->getEntity();
- $webform->setThirdPartySetting(
- 'os2forms_permissions_by_term',
- 'settings',
- $form_state->getValue([
- 'os2forms_permissions_by_term',
- 'os2forms_access',
- ]));
- $webform->save();
- }
-
- /**
- * Implementation of hook_form_FORM_ID_alter().
- *
- * Add permission by term selection to node "add" and "edit".
- *
- * @param array $form
- * The form being altered.
- * @param \Drupal\Core\Form\FormStateInterface $form_state
- * The state of the form.
- *
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
- */
- public function nodeFormAlter(array &$form, FormStateInterface $form_state) {
- /** @var \Drupal\Core\Entity\EntityForm $formObject */
- $formObject = $form_state->getFormObject();
- $nodeBundle = $formObject->getEntity()->bundle();
- if (1 === (int) $this->account->id() || 'webform' !== $nodeBundle) {
- return;
- }
-
- // Run custom submit handler before default node submission.
- array_unshift(
- $form['actions']['submit']['#submit'],
- [$this, 'nodeWebformPermisisonsByTermSubmit']
- );
- $user = $this->entityTypeManager->getStorage('user')->load($this->account->id());
- $userTerms = $this->accessStorage->getPermittedTids($user->id(), $user->getRoles());
- $anonymousTerms = $this->accessStorage->getPermittedTids(0, ['anonymous']);
- $webformReference = $form['webform']['widget'][0]['target_id']['#default_value'];
- // If a webform is referenced from the node add message.
- if ($webformReference) {
- $url = URL::fromRoute('entity.webform.settings_access', ['webform' => $webformReference])->toString();
- $form['field_os2forms_permissions']['widget'][0]['#prefix'] =
- '
';
- }
- // Disable anonymous terms. They should always be fetched from webform.
- foreach ($anonymousTerms as $termId) {
- $form['field_os2forms_permissions']['widget'][$termId]['#disabled'] = TRUE;
- }
-
- // Set access value automatically if user only has one term option.
- if (1 === count($userTerms)) {
- $form['field_os2forms_permissions']['widget']['#disabled'] = TRUE;
- $form['field_os2forms_permissions']['widget']['#default_value'][] = $userTerms[0];
- }
- }
-
- /**
- * Implements hook_field_widget_multivalue_WIDGET_TYPE_form_alter().
- *
- * Alter the field webform_entity_reference widget.
- * Hide options if user is not allowed to access the webform.
- *
- * @param array $elements
- * The form element.
- *
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
- */
- public function fieldWidgetWebformEntityReferenceFormAlter(array &$elements) {
- $options = $elements[0]['target_id']['#options'];
- $result = [];
- $this->filterWebformSelectOptions($options, $result);
- $elements[0]['target_id']['#options'] = $result;
- }
-
- /**
- * Implements hook_options_list_alter().
- *
- * Change options list field for node.field_os2forms_permissions.
- * Add anonymous option to allow the form to be displayed for anonymous users.
- *
- * @param array $options
- * The options of the list.
- * @param array $context
- * The context of the options list.
- *
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
- */
- public function optionsListAlter(array &$options, array $context) {
- // Alter the field_os2forms_permissions options list.
- if ('node.field_os2forms_permissions' !== $context['fieldDefinition']->getFieldStorageDefinition()->id()) {
- return;
- }
- // Limit options to those available on user profile.
- $options = [];
- $user = $this->entityTypeManager->getStorage('user')->load($this->account->id());
- $userTerms = $this->accessStorage->getPermittedTids($user->id(), $user->getRoles());
- foreach ($userTerms as $userTerm) {
- $term = $this->entityTypeManager->getStorage('taxonomy_term')->load($userTerm);
- $options[$userTerm] = $term->label();
- }
- $anonymousTerms = $this->accessStorage->getPermittedTids(0, ['anonymous']);
- foreach ($anonymousTerms as $termId) {
- $term = $this->entityTypeManager->getStorage('taxonomy_term')->load($termId);
- $label = $this->t('@term_label (Note: View permission only. This setting depends on the related webform.)', ['@term_label' => $term->label()]);
- $options = [$termId => $label] + $options;
- }
- }
-
- /**
- * Custom submit handler for setting permissions by term on node.
- *
- * @param array $form
- * The form that is being submitted.
- * @param \Drupal\Core\Form\FormStateInterface $form_state
- * The state of the form being submitted.
- */
- public function nodeWebformPermisisonsByTermSubmit(array $form, FormStateInterface $form_state) {
- $webformReference = $form_state->getValue('webform');
- $webformTarget = $webformReference['0']['target_id'] ?? NULL;
- if (!$webformTarget) {
- return;
- }
- $existingValues = $form_state->getValue('field_os2forms_permissions');
- $anonymousTerms = $this->accessStorage->getPermittedTids(0, ['anonymous']);
- $anonymousUser = User::getAnonymousUser();
- $referencedWebform = $this->entityTypeManager->getStorage('webform')->load($webformTarget);
- foreach ($anonymousTerms as $termId) {
- if ($referencedWebform->access('submission_create', $anonymousUser)) {
- $existingValues[] = ['target_id' => $termId];
- }
- }
- $form_state->setValue('field_os2forms_permissions', $existingValues);
- }
-
- /**
- * Add to the private variable webformSelectOptions.
- *
- * @param array $options
- * The options to to pick from.
- * @param array $result
- * The result.
- * @param string|null $parent
- * A parent key if the option is a child.
- *
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
- */
- private function filterWebformSelectOptions(array $options, array &$result = [], string $parent = NULL) {
- foreach ($options as $key => $option) {
- if ($option instanceof FieldFilteredMarkup) {
- $webform = $this->entityTypeManager->getStorage('webform')->load($key);
- /** @var \Drupal\webform\WebformInterface $webform */
- $accessResult = $this->webformAccess($webform, 'update', $this->account);
- if (!$accessResult instanceof AccessResultForbidden) {
- if ($parent) {
- // Webform module only allows for one level of grouping, so we can
- // safely assume only one level nesting.
- $result[$parent][$key] = $option;
- }
- else {
- $result[$key] = $option;
- }
- }
- }
- else {
- if (is_array($option)) {
- $this->filterWebformSelectOptions($option, $result, $key);
- }
- }
- }
- }
-
-}
diff --git a/modules/os2forms_permissions_by_term/src/Helper/MaestroTemplateHelper.php b/modules/os2forms_permissions_by_term/src/Helper/MaestroTemplateHelper.php
deleted file mode 100644
index 1b72a4e..0000000
--- a/modules/os2forms_permissions_by_term/src/Helper/MaestroTemplateHelper.php
+++ /dev/null
@@ -1,402 +0,0 @@
-accessStorage = $accessStorage;
- $this->entityTypeManager = $entity_type_manager;
- $this->account = $account;
- $this->configFactory = $configFactory;
- $this->helper = $helper;
- }
-
- /**
- * Implements hook_form_FORM_ID_alter().
- *
- * Add permission by term selection to webform "add" and "settings".
- *
- * @param array $form
- * The form being altered.
- * @param \Drupal\Core\Form\FormStateInterface $form_state
- * The state of the form.
- * @param string $hook
- * The type of webform hook calling this method.
- *
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
- */
- public function maestroTemplateFormAlter(array &$form, FormStateInterface $form_state, $hook) {
- $term_data = [];
- $user = $this->entityTypeManager->getStorage('user')->load($this->account->id());
- if (1 === (int) $this->account->id()) {
- $userTerms = [];
- $permissionsByTermBundles = $this->configFactory->get('permissions_by_term.settings')->get('target_bundles');
- foreach ($permissionsByTermBundles as $bundle) {
- $terms = $this->entityTypeManager->getStorage('taxonomy_term')->loadTree($bundle);
- foreach ($terms as $term) {
- $userTerms[] = $term->tid;
- }
- }
- }
- else {
- $userTerms = $this->accessStorage->getPermittedTids($user->id(), $user->getRoles());
- }
- $terms = $this->entityTypeManager->getStorage('taxonomy_term')->loadMultiple($userTerms);
- foreach ($terms as $term) {
- $term_data[$term->id()] = $term->label();
- }
-
- // Remove any options that allow anonymous access to the maestro template.
- $anonymousTerms = $this->accessStorage->getPermittedTids(0, ['anonymous']);
- foreach ($anonymousTerms as $termId) {
- unset($term_data[$termId]);
- }
-
- if ('settings' === $hook) {
- /** @var \Drupal\Core\Entity\EntityForm $meastroSettingsForm */
- $meastroSettingsForm = $form_state->getFormObject();
- /** @var \Drupal\Core\Config\Entity\ThirdPartySettingsInterface $mastroTemplate */
- $mastroTemplate = $meastroSettingsForm->getEntity();
- $defaultSettings = $mastroTemplate->getThirdPartySetting('os2forms_permissions_by_term', 'maestro_template_permissions_by_term_settings');
- }
-
- $form['maestro_template_permissions_by_term'] = [
- '#type' => 'details',
- '#open' => TRUE,
- '#title' => $this->t('Meastro template access'),
- '#tree' => TRUE,
- '#weight' => -99,
- ];
-
- $form['maestro_template_permissions_by_term']['os2forms_access'] = [
- '#type' => 'checkboxes',
- '#required' => TRUE,
- '#title' => $this->t('Access'),
- '#default_value' => $defaultSettings ?? [],
- '#options' => $term_data,
- '#description' => $this->t('Limit access to this template.'),
- ];
-
- // Set access value automatically if user only has one term option.
- if ('add' === $hook && 1 === count($term_data)) {
- $form['maestro_template_permissions_by_term']['os2forms_access']['#disabled'] = TRUE;
- $form['maestro_template_permissions_by_term']['os2forms_access']['#value'] = [array_key_first($term_data) => array_key_first($term_data)];
- }
-
- $form['actions']['submit']['#submit'][] = [$this, 'maestroTemplateSubmit'];
- }
-
- /**
- * Implementation of hook_ENTITY_TYPE_access().
- *
- * Change access on maestro templates related operations.
- *
- * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $maestroTemplate
- * The entity to set access for.
- * @param string $operation
- * The operation being performed on the webform.
- * @param \Drupal\Core\Session\AccountInterface $account
- * The current user.
- *
- * @return \Drupal\Core\Access\AccessResult
- * The resulting access permission.
- *
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
- */
- public function maestroTemplateAccess(ConfigEntityInterface $maestroTemplate, $operation, AccountInterface $account) {
- if (1 === (int) $account->id()) {
- return AccessResult::neutral();
- }
- $user = $this->entityTypeManager->getStorage('user')->load($account->id());
- $userTerms = $this->accessStorage->getPermittedTids($user->id(), $user->getRoles());
- $maestroTemplatePermissionsByTerm = $maestroTemplate->getThirdPartySetting('os2forms_permissions_by_term', 'maestro_template_permissions_by_term_settings');
-
- switch ($operation) {
- case 'view':
- case 'update':
- case 'delete':
- // Allow access if no term is set for the template or a maestro template
- // term match the users term.
- return empty($maestroTemplatePermissionsByTerm) || !empty(array_intersect($maestroTemplatePermissionsByTerm, $userTerms))
- ? AccessResult::neutral()
- : AccessResult::forbidden();
- }
-
- return AccessResult::neutral();
- }
-
- /**
- * Custom submit handler for maestro template add/edit form.
- *
- * Set permission by term as a thirdPartySetting of the maestro template.
- *
- * @param array $form
- * The maestro template add/edit form.
- * @param \Drupal\Core\Form\FormStateInterface $form_state
- * The state of the form.
- */
- public function maestroTemplateSubmit(array $form, FormStateInterface $form_state) {
- // Get the settings from the maestro templates config entity.
- /** @var \Drupal\Core\Entity\EntityForm $maestroTemplateSettingsForm */
- $maestroTemplateSettingsForm = $form_state->getFormObject();
- /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $maestroTemplate */
- $maestroTemplate = $maestroTemplateSettingsForm->getEntity();
- $maestroTemplate->setThirdPartySetting(
- 'os2forms_permissions_by_term',
- 'maestro_template_permissions_by_term_settings',
- $form_state->getValue([
- 'maestro_template_permissions_by_term',
- 'os2forms_access',
- ])
- );
- $maestroTemplate->save();
- }
-
- /**
- * Implements hook_field_widget_multivalue_WIDGET_TYPE_form_alter().
- *
- * Alter the field webform_entity_reference widget.
- * Hide webform options from maestro templates if user is not allowed to
- * update the webform.
- *
- * @param array $form
- * The form element.
- * @param \Drupal\Core\Form\FormStateInterface $form_state
- * The state of the form.
- * @param string $form_id
- * The id of the form.
- *
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
- */
- public function maestroFormAlter(array &$form, FormStateInterface $form_state, string $form_id) {
- switch ($form_id) {
- // Alter maestro task edit form.
- case 'template_edit_task':
- // Limit webform options.
- if (array_key_exists('webform_machine_name', $form)) {
- foreach ($form['webform_machine_name']['#options'] as $key => $option) {
- if (!$option instanceof TranslatableMarkup) {
- $webform = $this->entityTypeManager->getStorage('webform')->load($key);
- /** @var \Drupal\webform\WebformInterface $webform */
- $accessResult = $this->helper->webformAccess($webform, 'update', $this->account);
- if ($accessResult instanceof AccessResultForbidden) {
- unset($form['webform_machine_name']['#options'][$key]);
- }
- }
- }
- }
- break;
-
- case 'views_exposed_form':
- // Alter maestro views exposed filters.
- switch ($form['#id']) {
- case 'views-exposed-form-maestro-all-flows-all-flows-full':
- $form['template_id_filter']['#options'] = $this->limitOptions($this->getUserTerms($this->account), $form['template_id_filter']['#options']);
- break;
- }
- break;
-
- case 'webform_handler_form':
- // Alter webform handler list select list.
- switch ($form['#webform_handler_id']) {
- case 'opret_forloeb_fra_flow':
- $form['settings']['maestro_template']['#options'] = $this->limitOptions($this->getUserTerms($this->account), $form['settings']['maestro_template']['#options']);
- break;
- }
- break;
- }
- }
-
- /**
- * Implement hook_views_query_alter().
- *
- * Change views queries to account for permissions_by_term.
- *
- * @param \Drupal\views\ViewExecutable $view
- * The view.
- * @param \Drupal\views\Plugin\views\query\QueryPluginBase $query
- * The query.
- *
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
- */
- public function viewsQueryAlter(ViewExecutable $view, QueryPluginBase $query) {
- $viewId = $view->id();
- $displayId = $view->getDisplay()->display['id'];
- /** @var \Drupal\Core\Session\AccountInterface $user */
- $user = $this->entityTypeManager->getStorage('user')->load($this->account->id());
- $maestroTemplates = $this->entityTypeManager->getStorage('maestro_template')->getQuery()->execute();
- $allowedList = [];
- foreach ($maestroTemplates as $template) {
- /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $templateEntity */
- $templateEntity = $this->entityTypeManager->getStorage('maestro_template')->load($template);
- $accessResult = $this->maestroTemplateAccess($templateEntity, 'view', $user);
- if (!$accessResult instanceof AccessResultForbidden) {
- $allowedList[] = $template;
- }
- }
- switch ($viewId) {
- case 'maestro_outstanding_tasks':
- switch ($displayId) {
- case 'maestro_outstanding_tasks':
- case 'taskconsole_display':
- // @phpstan-ignore-next-line
- $query->where[1]['conditions'][] = [
- 'field' => 'maestro_process_maestro_queue.template_id',
- 'value' => $allowedList,
- 'operator' => 'in',
- ];
- break;
- }
- break;
-
- case 'maestro_all_flows':
- switch ($displayId) {
- case 'all_flows_full':
- // @phpstan-ignore-next-line
- $query->where[1]['conditions'][] = [
- 'field' => 'maestro_process.template_id',
- 'value' => $allowedList,
- 'operator' => 'in',
- ];
-
- break;
- }
- break;
-
- case 'maestro_all_in_production_tasks':
- switch ($displayId) {
- case 'maestro_all_active_tasks_full':
- case 'maestro_all_active_tasks_lean':
- // @phpstan-ignore-next-line
- $query->where[1]['conditions'][] = [
- 'field' => 'maestro_process_maestro_queue.template_id',
- 'value' => $allowedList,
- 'operator' => 'in',
- ];
-
- break;
- }
- break;
- }
- }
-
- /**
- * Limit select field options based on permissions by term.
- *
- * @param array $userTerms
- * The users terms.
- * @param array $options
- * The original options.
- *
- * @return array
- * The modified options.
- *
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
- */
- private function limitOptions(array $userTerms, array $options) {
- $maestroTemplates = $this->entityTypeManager->getStorage('maestro_template')->loadMultiple(array_keys($options));
- /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $maestroTemplate */
- foreach ($maestroTemplates as $key => $maestroTemplate) {
- $maestroTemplatePermissionsByTerm = $maestroTemplate->getThirdPartySetting('os2forms_permissions_by_term', 'maestro_template_permissions_by_term_settings');
- if (isset($maestroTemplatePermissionsByTerm) && empty(array_intersect($maestroTemplatePermissionsByTerm, $userTerms))) {
- unset($options[$key]);
- }
- }
-
- return $options;
- }
-
- /**
- * Get all user terms.
- *
- * Given a user account provide the users permssions according to
- * permissions by term.
- *
- * @param \Drupal\Core\Session\AccountProxyInterface $account
- * The user account.
- *
- * @return array
- * The users permissions.
- *
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
- */
- private function getUserTerms(AccountProxyInterface $account) {
- $user = $this->entityTypeManager->getStorage('user')->load($account->id());
- return $this->accessStorage->getPermittedTids($user->id(), $user->getRoles());
- }
-
-}
diff --git a/modules/os2forms_permissions_by_term/src/Routing/RouteSubscriber.php b/modules/os2forms_permissions_by_term/src/Routing/RouteSubscriber.php
deleted file mode 100644
index 629d144..0000000
--- a/modules/os2forms_permissions_by_term/src/Routing/RouteSubscriber.php
+++ /dev/null
@@ -1,26 +0,0 @@
-get('entity.webform_submission.collection');
- if ($route) {
- $route->setRequirement('_access', 'FALSE');
- }
- }
-
-}
diff --git a/modules/os2forms_webform_list/os2forms_webform_list.info.yml b/modules/os2forms_webform_list/os2forms_webform_list.info.yml
deleted file mode 100644
index c8d4536..0000000
--- a/modules/os2forms_webform_list/os2forms_webform_list.info.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-name: OS2forms webform list
-type: module
-description: Alters display of webform list and maestro template list
-package: OS2Web
-core: 8.x
-core_version_requirement: ^8 || ^9
-dependencies:
- - 'drupal:webform'
- - 'drupal:maestro'
diff --git a/modules/os2forms_webform_list/os2forms_webform_list.module b/modules/os2forms_webform_list/os2forms_webform_list.module
deleted file mode 100644
index 958ff0c..0000000
--- a/modules/os2forms_webform_list/os2forms_webform_list.module
+++ /dev/null
@@ -1,18 +0,0 @@
-setListBuilderClass('Drupal\os2forms_webform_list\CustomWebformEntityListBuilder');
- $entity_types['maestro_template']->setListBuilderClass('Drupal\os2forms_webform_list\CustomMaestroTemplateEntityListBuilder');
-}
diff --git a/modules/os2forms_webform_list/src/CustomMaestroTemplateEntityListBuilder.php b/modules/os2forms_webform_list/src/CustomMaestroTemplateEntityListBuilder.php
deleted file mode 100644
index f4d46ce..0000000
--- a/modules/os2forms_webform_list/src/CustomMaestroTemplateEntityListBuilder.php
+++ /dev/null
@@ -1,32 +0,0 @@
-getEntityIds();
- // @phpstan-ignore-next-line
- $entities = $this->storage->loadMultipleOverrideFree($entity_ids);
-
- uasort($entities, [$this->entityType->getClass(), 'sort']);
- foreach ($entities as $entity_name => $entity) {
- $access = $entity->access('update');
- if (!$access) {
- unset($entities[$entity_name]);
- }
- }
- return $entities;
- }
-
-}
diff --git a/modules/os2forms_webform_list/src/CustomWebformEntityListBuilder.php b/modules/os2forms_webform_list/src/CustomWebformEntityListBuilder.php
deleted file mode 100644
index 94e64fb..0000000
--- a/modules/os2forms_webform_list/src/CustomWebformEntityListBuilder.php
+++ /dev/null
@@ -1,50 +0,0 @@
-getStorage()->loadMultiple();
- foreach ($webforms as $webform) {
- $access = $webform->access('update');
- if ($access) {
- $allowedForms[] = $webform->id();
- }
- }
-
- $query->condition('id', $allowedForms, 'IN');
-
- return $query;
- }
-
-}
diff --git a/os2forms_forloeb_profile.info.yml b/os2forms_forloeb_profile.info.yml
index 78c9530..6154e15 100644
--- a/os2forms_forloeb_profile.info.yml
+++ b/os2forms_forloeb_profile.info.yml
@@ -97,7 +97,6 @@ install:
# OS2forms_forloeb
- admin_toolbar_tools
- coc_forms_auto_export
- - config_entity_revisions
- events_logging
- gin_toolbar
- maestro
diff --git a/os2forms_forloeb_profile.links.menu.yml b/os2forms_forloeb_profile.links.menu.yml
index 5555688..247e5b0 100644
--- a/os2forms_forloeb_profile.links.menu.yml
+++ b/os2forms_forloeb_profile.links.menu.yml
@@ -5,6 +5,8 @@ system.admin.os2forms_forloeb.task_console:
parent: system.admin
route_name: maestro_taskconsole.taskconsole
weight: 10
+ attributes:
+ class: 'toolbar-icon-content-tasks'
system.admin.os2forms_forloeb.task_console.outstanding_tasks:
title: 'Mine selvbetjeningsforløb'
menu_name: admin
@@ -32,6 +34,8 @@ system.admin.os2forms_forloeb.content:
parent: system.admin
route_name: system.admin_content
weight: 11
+ attributes:
+ class: 'toolbar-icon-content-self-service'
system.admin.os2forms_forloeb.content.new_webform:
title: 'Tilføj formular'
menu_name: admin
@@ -59,6 +63,8 @@ system.admin.os2forms_forloeb.webforms:
parent: system.admin
route_name: entity.webform.collection
weight: 12
+ attributes:
+ class: 'toolbar-icon-content-form'
system.admin.os2forms_forloeb.webforms.templates:
title: 'Skabeloner'
menu_name: admin
@@ -79,6 +85,8 @@ system.admin.os2forms_forloeb.flows:
parent: system.admin
route_name: entity.maestro_template.list
weight: 13
+ attributes:
+ class: 'toolbar-icon-content-flows'
system.admin.os2forms_forloeb.flows.add_flow:
title: 'Tilføj flow'
menu_name: admin
@@ -110,6 +118,8 @@ system.admin.os2forms_forloeb.config_import_export:
parent: system.admin
route_name: config.import_single
weight: 14
+ attributes:
+ class: 'toolbar-icon-content-import-export'
# Oversættelser
system.admin.os2forms_forloeb.translation:
@@ -118,3 +128,5 @@ system.admin.os2forms_forloeb.translation:
parent: system.admin
route_name: locale.translate_page
weight: 15
+ attributes:
+ class: 'toolbar-icon-content-translations'