diff --git a/src/Handler/UWWebformEntityListBuilder.php b/src/Handler/UWWebformEntityListBuilder.php new file mode 100644 index 0000000000000000000000000000000000000000..d8d4286de1f0ed044052880a66c4370a126823b9 --- /dev/null +++ b/src/Handler/UWWebformEntityListBuilder.php @@ -0,0 +1,29 @@ +<?php + +namespace Drupal\uw_dashboard\Handler; + +use Drupal\webform\WebformEntityListBuilder; + +/** + * Class UWWebformEntityListBuilder. + * + * Extends functionality by updating one method. + */ +class UWWebformEntityListBuilder extends WebformEntityListBuilder { + + /** + * New function that modifies output of parent render. + * + * Only usage is on uw_dashboard, when webform filter autocomplete + * matches one webform. This update will remove webform id, and + * use filter to display one result, which creates redirect otherwise. + */ + public function uwRender() { + if ($this->keys && preg_match('#\(([^)]+)\)$#', $this->keys, $match) && !empty($match[0])) { + $this->keys = trim(preg_replace('#\(([^)]+)\)$#', '', $this->keys)); + } + + return $this->render(); + } + +} diff --git a/src/Plugin/Block/FormsListBlock.php b/src/Plugin/Block/FormsListBlock.php index ea68f66c1f620e2d9cb6d01f59b9991082d44619..9cfed423bdfe517c62151f44d6f6baeb83e7dfbb 100644 --- a/src/Plugin/Block/FormsListBlock.php +++ b/src/Plugin/Block/FormsListBlock.php @@ -99,13 +99,13 @@ class FormsListBlock extends BlockBase implements ContainerFactoryPluginInterfac } // Get the render array from the entity list. - $render = $entity_type_list->render(); + $render = $entity_type_list->uwRender(); // Remove the category filer. unset($render['filter_form']['filter']['category']); } else { - $render = $entity_type_list->render(); + $render = $entity_type_list->uwRender(); } // Render the entity list. diff --git a/uw_dashboard.module b/uw_dashboard.module index 7c37e86bb1f314b8e58c099d46c69e15247fc224..cc9b49f2a9b6c56f3e081a747395f9552bd5c25b 100644 --- a/uw_dashboard.module +++ b/uw_dashboard.module @@ -7,6 +7,7 @@ use Drupal\Core\Url; use Drupal\user\Entity\User; +use Drupal\uw_dashboard\Handler\UWWebformEntityListBuilder; use Drupal\views\ViewExecutable; /** @@ -112,3 +113,12 @@ function uw_dashboard_preprocess_block(&$variables) { } } } + +/** + * Implements hook_entity_type_alter(). + */ +function uw_dashboard_entity_type_alter(array &$entity_types) { + // Replacing webform's default entity list builder with new child class. + // This should ensure all works as before, except is new function is called. + $entity_types['webform']->setHandlerClass('list_builder', UWWebformEntityListBuilder::class); +}