Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added webform autocomplete element #827

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/sync/user.role.coder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ permissions:
- 'use text format html_code'
- 'use text format webform_email'
- 'view the administration theme'
- 'access webform options'
1 change: 0 additions & 1 deletion config/sync/webform.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ element:
view: view
webform_actions: webform_actions
webform_audio_file: webform_audio_file
webform_autocomplete: webform_autocomplete
webform_codemirror: webform_codemirror
webform_computed_token: webform_computed_token
webform_computed_twig: webform_computed_twig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ permissions:
- 'use text format html_code'
- 'use text format webform_email'
- 'view the administration theme'
- 'access webform options'
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ dependencies:
- 'webform:webform'
- 'webform:webform_node'
- 'webform:webform_submission_log'
version: 1.5.4
version: 1.5.5
package: Herbie
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ element:
view: view
webform_actions: webform_actions
webform_audio_file: webform_audio_file
webform_autocomplete: webform_autocomplete
webform_codemirror: webform_codemirror
webform_computed_token: webform_computed_token
webform_computed_twig: webform_computed_twig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ dependencies:
- 'linkit:linkit'
- 'pathauto:pathauto'
- 'webform:webform'
version: 1.3.2
version: 1.3.3
package: Herbie
21 changes: 18 additions & 3 deletions web/modules/custom/unl_webform/src/Routing/RouteSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,34 @@
/**
* Listens to the dynamic route events.
*/
class RouteSubscriber extends RouteSubscriberBase {
class RouteSubscriber extends RouteSubscriberBase
{

/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
protected function alterRoutes(RouteCollection $collection)
{
// Make Help pages inaccessible.
if ($route = $collection->get('webform.help')) {
$route->setRequirements(['_access' => 'FALSE']);
}
if ($route = $collection->get('webform.help.video')) {
$route->setRequirements(['_access' => 'FALSE']);
}
if ($route = $collection->get('entity.webform_options.collection')) {
// Override the Webform module's permission with a custom permission to restrict access to Options configurations only.
$route->setRequirement('_permission', 'access webform options');
}
if ($route = $collection->get('entity.webform_options.source_form')) {
$requirements = $route->getRequirements();
// Remove the Webform module's _custom_access to allow the addition of a YAML source for predefined lists, restricted to users with 'access webform options' permission.
if (isset($requirements['_custom_access'])) {
unset($requirements['_custom_access']);
$route->setRequirements($requirements);
}
// Override the permission with a custom permission to restrict access to Options configurations only.
$route->setRequirement('_permission', 'access webform options');
}
}

}
49 changes: 49 additions & 0 deletions web/modules/custom/unl_webform/unl_webform.module
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use Drupal\Component\Utility\Bytes;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\WebformInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Session\AccountInterface;

/**
* Implements hook_entity_create().
Expand Down Expand Up @@ -374,3 +376,50 @@ function unl_webform_upload_file_extension_whitelist(string $element_type, array

return $return;
}

/**
* Implements hook_entity_access().
*/
function unl_webform_entity_access(EntityInterface $entity, $operation, AccountInterface $account)
{
$restricted_webform_options = array(
"days",
"months",
"time_zones",
"titles",
"yes_no",
"country_codes",
"country_names",
"state_province_codes",
"state_province_names",
"state_codes",
"state_names",
"languages",
"likert_agreement",
"likert_comparison",
"likert_importance",
"likert_quality",
"likert_satisfaction",
"likert_ten_scale",
"likert_would_you"
);
// Allow addition and deletion operations for webform options, restricted to user-created predefined webform options lists.
if ($entity->getEntityTypeId() === 'webform_options' && !in_array($entity->id(), $restricted_webform_options)) {
return AccessResult::allowedIfHasPermission($account, 'access webform options');
}
return AccessResult::neutral();
}

/**
* Implements hook_entity_create_access().
*/
function unl_webform_entity_create_access(AccountInterface $account, array $context, $entity_bundle)
{
// Only check for 'webform_options' entity type.
if ($context['entity_type_id'] === 'webform_options') {
// Allow entity creation if the user has the custom 'access webform options'.
return AccessResult::allowedIfHasPermission($account, 'access webform options');
}
// For other entities, return neutral.
return AccessResult::neutral();
}
4 changes: 4 additions & 0 deletions web/modules/custom/unl_webform/unl_webform.permissions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
administer unl webform download settings:
title: 'Administer UNL Webform download settings'
description: 'Allows a user to configure UNL Webform download key settings.'

access webform options:
title: 'Access UNL Webform Options'
description: 'Access Webform Options. Restricted to users with the Developer role only.'