Loading src/WebformSubmissionListBuilder.php +145 −0 Changes for src/WebformSubmissionListBuilder.php: 145 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -13,8 +13,10 @@ use Drupal\Core\Link; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Drupal\views\Views; use Drupal\webform\Controller\WebformSubmissionController; use Drupal\webform\Plugin\WebformElementManagerInterface; use Drupal\webform\Utility\WebformArrayHelper; use Drupal\webform\Utility\WebformDialogHelper; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; Loading Loading @@ -213,6 +215,20 @@ class WebformSubmissionListBuilder extends EntityListBuilder { */ protected $customize; /** * The name of current submission view. * * @var string */ protected $submissionView; /** * An associative array of submission views. * * @var string */ protected $submissionViews; /** * {@inheritdoc} */ Loading Loading @@ -298,6 +314,21 @@ class WebformSubmissionListBuilder extends EntityListBuilder { break; } // Initialize submission views and view. $this->submissionView = $this->routeMatch->getParameter('submission_view') ?: ''; $this->submissionViews = $this->getSubmissionViews(); if ($this->submissionViews) { if (empty($this->submissionView) && $this->webform->getSetting('submission_views_replace')) { $this->submissionView = WebformArrayHelper::getFirstKey($this->submissionViews); } } // If there is a submission view, we do not need to initialize // the entity list. if ($this->submissionView) { return; } // Set default display settings. $this->direction = 'desc'; $this->limit = 20; Loading Loading @@ -386,6 +417,92 @@ class WebformSubmissionListBuilder extends EntityListBuilder { $this->messageManager->display(WebformMessageManagerInterface::FORM_SAVE_EXCEPTION, 'warning'); } if ($this->submissionView) { $build += $this->buildSubmissionViews(); } else { $build += $this->buildEntityList(); } return $build; } /** * Build the webform submission view. * * @return array * A renderable array containing a submission view. */ protected function buildSubmissionViews() { $settings = $this->submissionViews[$this->submissionView]; // Get view name and display id. list($name, $display_id) = explode(':', $settings['view']); // Load the view and set custom property used to fix the exposed // filter action. // @see webform_form_views_exposed_form_alter() $view = Views::getView($name); $view->webform_submission_view = TRUE; // Get the current displays arguments. $displays = $view->storage->get('display'); if (isset($displays[$display_id]['display_options']['arguments'])) { $display_arguments = $displays['default']['display_options']['arguments']; } else { $display_arguments = $displays['default']['display_options']['arguments']; } // Populate the views arguments. $arguments = []; foreach ($display_arguments as $argument_name => $display_argument) { if ($display_argument['table'] !== 'webform_submission') { $arguments[] = 'all'; } else { switch ($argument_name) { case 'webform_id': $arguments[] = ($this->webform) ? $this->webform->id() : 'all'; break; case 'entity_type': $arguments[] = ($this->sourceEntity) ? $this->sourceEntity->getEntityTypeId() : 'all'; break; case 'entity_id': $arguments[] = ($this->sourceEntity) ? $this->sourceEntity->id() : 'all'; break; case 'uid': $arguments[] = ($this->account) ? $this->account->id() : 'all'; break; default: $arguments[] = 'all'; break; } } } $build = []; $build['view'] = [ '#type' => 'view', '#view' => $view, '#display_id' => $display_id, '#arguments' => $arguments, ]; return $build; } /** * Build the webform submission entity list. * * @return array * A renderable array containing the entity list. */ protected function buildEntityList() { $build = []; // Filter form. if (empty($this->account)) { $build['filter_form'] = $this->buildFilterForm(); Loading Loading @@ -938,6 +1055,34 @@ class WebformSubmissionListBuilder extends EntityListBuilder { return $route_parameters; } /****************************************************************************/ // Submission views functions. /****************************************************************************/ protected function getSubmissionViews() { if (!isset($this->webform)) { return []; } $submission_views = $this->webform->getSetting('submission_views', []); $route_name = $this->routeMatch->getRouteName(); foreach ($submission_views as $name => $submission_view) { if (!in_array($route_name, $submission_view['routes'])) { unset($submission_view[$name]); continue; } list($view_name, $view_display_id) = explode(':', $submission_view['view']); $view = Views::getView($view_name); if (!$view && !$view->access($view_display_id)) { unset($submission_view[$name]); continue; } } return $submission_views; } /****************************************************************************/ // Query functions. /****************************************************************************/ Loading webform.module +14 −0 Changes for webform.module: 14 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -322,6 +322,20 @@ function webform_form_update_manager_update_form_alter(&$form, FormStateInterfac ]; } /** * Implements hook_form_FORM_ID_alter(). */ function webform_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) { /** @var \Drupal\views\ViewExecutable $view */ $view = $form_state->get('view'); // Check if this a is webform submission view. // @see \Drupal\webform\WebformSubmissionListBuilder::buildSubmissionViews if (isset($view->webform_submission_view)) { $form['#action'] = Url::fromRoute(\Drupal::routeMatch()->getRouteName(), \Drupal::routeMatch()->getRawParameters()->all())->toString(); } } /** * Implements hook_system_breadcrumb_alter(). */ Loading Loading
src/WebformSubmissionListBuilder.php +145 −0 Changes for src/WebformSubmissionListBuilder.php: 145 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -13,8 +13,10 @@ use Drupal\Core\Link; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Drupal\views\Views; use Drupal\webform\Controller\WebformSubmissionController; use Drupal\webform\Plugin\WebformElementManagerInterface; use Drupal\webform\Utility\WebformArrayHelper; use Drupal\webform\Utility\WebformDialogHelper; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; Loading Loading @@ -213,6 +215,20 @@ class WebformSubmissionListBuilder extends EntityListBuilder { */ protected $customize; /** * The name of current submission view. * * @var string */ protected $submissionView; /** * An associative array of submission views. * * @var string */ protected $submissionViews; /** * {@inheritdoc} */ Loading Loading @@ -298,6 +314,21 @@ class WebformSubmissionListBuilder extends EntityListBuilder { break; } // Initialize submission views and view. $this->submissionView = $this->routeMatch->getParameter('submission_view') ?: ''; $this->submissionViews = $this->getSubmissionViews(); if ($this->submissionViews) { if (empty($this->submissionView) && $this->webform->getSetting('submission_views_replace')) { $this->submissionView = WebformArrayHelper::getFirstKey($this->submissionViews); } } // If there is a submission view, we do not need to initialize // the entity list. if ($this->submissionView) { return; } // Set default display settings. $this->direction = 'desc'; $this->limit = 20; Loading Loading @@ -386,6 +417,92 @@ class WebformSubmissionListBuilder extends EntityListBuilder { $this->messageManager->display(WebformMessageManagerInterface::FORM_SAVE_EXCEPTION, 'warning'); } if ($this->submissionView) { $build += $this->buildSubmissionViews(); } else { $build += $this->buildEntityList(); } return $build; } /** * Build the webform submission view. * * @return array * A renderable array containing a submission view. */ protected function buildSubmissionViews() { $settings = $this->submissionViews[$this->submissionView]; // Get view name and display id. list($name, $display_id) = explode(':', $settings['view']); // Load the view and set custom property used to fix the exposed // filter action. // @see webform_form_views_exposed_form_alter() $view = Views::getView($name); $view->webform_submission_view = TRUE; // Get the current displays arguments. $displays = $view->storage->get('display'); if (isset($displays[$display_id]['display_options']['arguments'])) { $display_arguments = $displays['default']['display_options']['arguments']; } else { $display_arguments = $displays['default']['display_options']['arguments']; } // Populate the views arguments. $arguments = []; foreach ($display_arguments as $argument_name => $display_argument) { if ($display_argument['table'] !== 'webform_submission') { $arguments[] = 'all'; } else { switch ($argument_name) { case 'webform_id': $arguments[] = ($this->webform) ? $this->webform->id() : 'all'; break; case 'entity_type': $arguments[] = ($this->sourceEntity) ? $this->sourceEntity->getEntityTypeId() : 'all'; break; case 'entity_id': $arguments[] = ($this->sourceEntity) ? $this->sourceEntity->id() : 'all'; break; case 'uid': $arguments[] = ($this->account) ? $this->account->id() : 'all'; break; default: $arguments[] = 'all'; break; } } } $build = []; $build['view'] = [ '#type' => 'view', '#view' => $view, '#display_id' => $display_id, '#arguments' => $arguments, ]; return $build; } /** * Build the webform submission entity list. * * @return array * A renderable array containing the entity list. */ protected function buildEntityList() { $build = []; // Filter form. if (empty($this->account)) { $build['filter_form'] = $this->buildFilterForm(); Loading Loading @@ -938,6 +1055,34 @@ class WebformSubmissionListBuilder extends EntityListBuilder { return $route_parameters; } /****************************************************************************/ // Submission views functions. /****************************************************************************/ protected function getSubmissionViews() { if (!isset($this->webform)) { return []; } $submission_views = $this->webform->getSetting('submission_views', []); $route_name = $this->routeMatch->getRouteName(); foreach ($submission_views as $name => $submission_view) { if (!in_array($route_name, $submission_view['routes'])) { unset($submission_view[$name]); continue; } list($view_name, $view_display_id) = explode(':', $submission_view['view']); $view = Views::getView($view_name); if (!$view && !$view->access($view_display_id)) { unset($submission_view[$name]); continue; } } return $submission_views; } /****************************************************************************/ // Query functions. /****************************************************************************/ Loading
webform.module +14 −0 Changes for webform.module: 14 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -322,6 +322,20 @@ function webform_form_update_manager_update_form_alter(&$form, FormStateInterfac ]; } /** * Implements hook_form_FORM_ID_alter(). */ function webform_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) { /** @var \Drupal\views\ViewExecutable $view */ $view = $form_state->get('view'); // Check if this a is webform submission view. // @see \Drupal\webform\WebformSubmissionListBuilder::buildSubmissionViews if (isset($view->webform_submission_view)) { $form['#action'] = Url::fromRoute(\Drupal::routeMatch()->getRouteName(), \Drupal::routeMatch()->getRawParameters()->all())->toString(); } } /** * Implements hook_system_breadcrumb_alter(). */ Loading