Skip to content
Snippets Groups Projects

Draft: Issue #3457119 by kksandr: added support for remembering sorting in view tables

Open Draft: Issue #3457119 by kksandr: added support for remembering sorting in view tables
5 unresolved threads
Open kksandr requested to merge issue/drupal-3457119:3457119-remembering-sorting into 11.x
5 unresolved threads

Closes #3457119

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
121 121 caption:
122 122 type: label
123 123 label: 'Caption for the table'
124 remember:
  • 121 121 caption:
    122 122 type: label
    123 123 label: 'Caption for the table'
    124 remember:
    125 type: boolean
    126 label: 'Remember the last selection'
    127 remember_roles:
  • 62 66 */
    63 67 public $order;
    64 68
    69 /**
    70 * The current user.
    71 */
    72 protected AccountInterface $currentUser;
    73
    74 /**
    75 * {@inheritdoc}
    76 */
    77 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    78 $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
    79 $instance->currentUser = $container->get('current_user');
  • 75 93 $options['summary'] = ['default' => ''];
    76 94 $options['description'] = ['default' => ''];
    77 95 $options['empty_table'] = ['default' => FALSE];
    96 $options['remember'] = ['default' => FALSE];
  • 101 121 * Add our actual sort criteria.
    102 122 */
    103 123 public function buildSortPost() {
    104 $query = $this->view->getRequest()->query;
    124 $request = $this->view->getRequest();
    125 $query = $request->query;
    105 126 $order = $query->get('order');
    106 if (!isset($order)) {
    107 // check for a 'default' clickSort. If there isn't one, exit gracefully.
    108 if (empty($this->options['default'])) {
    109 return;
    127 // Try to get the remembered sort selection from the session.
    128 if ($this->options['remember']) {
    129 $allowed_rids = array_filter($this->options['remember_roles']);
    130 if ($allowed_rids && array_intersect(array_keys($allowed_rids), $this->currentUser->getRoles())) {
    131 $display_id = ($this->view->display_handler->isDefaulted('filters')) ? 'default' : $this->view->current_display;
    Please register or sign in to reply
    Loading