diff --git a/src/Plugin/Block/FormsListBlock.php b/src/Plugin/Block/FormsListBlock.php index 9cfed423bdfe517c62151f44d6f6baeb83e7dfbb..f7f74b96b0ba55bd9dcee0d72720fd32626785ab 100644 --- a/src/Plugin/Block/FormsListBlock.php +++ b/src/Plugin/Block/FormsListBlock.php @@ -111,6 +111,35 @@ class FormsListBlock extends BlockBase implements ContainerFactoryPluginInterfac // Render the entity list. $build['entity_list'] = $render; + // Get the total number of results. There was no easy way + // to get this value from the render array, either using the + // translatable markup, of the entity list builder. The only + // way was the get the actual string and pick off up to the + // first space. + if ( + count($build['entity_list']['info']) > 0 && + isset($build['entity_list']['info']['#markup']) + ) { + $total_num_of_results = strtok( + $build['entity_list']['info']['#markup']->__toString(), + ' ' + ); + } + else { + $total_num_of_results = 0; + } + + // If the total number of results is greater than 50, then add + // a link to view all the webforms to the info part of the + // render array. + if ($total_num_of_results > 50) { + $build['entity_list']['info']['#markup'] .= $this->t('<br><a href="../admin/structure/webform">View all webforms</a>'); + $build['entity_list']['more_info']['#markup'] = $this->t('<p class="pager__items"><a href="../admin/structure/webform?page=1">Next ›</a></p>'); + } + + // Remove the pager from the webform list. + unset($build['entity_list']['pager']); + return $build; } diff --git a/uw_dashboard.module b/uw_dashboard.module index 8c17e95d19d313f8adaba3dbfe8c412daa5b5194..d85453f54507a02c56c1271c75649022c8e6ad94 100644 --- a/uw_dashboard.module +++ b/uw_dashboard.module @@ -122,3 +122,35 @@ function uw_dashboard_entity_type_alter(array &$entity_types) { // This should ensure all works as before, except is new function is called. $entity_types['webform']->setHandlerClass('list_builder', UWWebformEntityListBuilder::class); } + +/** + * Implements hook_views_pre_execute(). + */ +function uw_dashboard_views_pre_execute(ViewExecutable $view) { + + // Have a variable that can be used "globally". + static $view_instances_count; + + // If there is no count yet, set it to 0. + if (!isset($view_instances_count)) { + $view_instances_count = 0; + } + + // The views that need the pager id adjusted. + $view_ids = [ + 'uw_view_content_list', + 'uw_view_pub_reference', + 'uw_view_pub_keywords', + 'uw_view_pub_authors', + ]; + + // If a view needs its pager id adjusted, then do it. + if (in_array($view->id(), $view_ids)) { + + // Increment the counter, so we get the correct pager id. + $view_instances_count++; + + // Set the pager id in the view. + $view->pager->options['id'] = $view_instances_count; + } +}