Score:0

Modifying a view runtime?

um flag

I wanted to remove click sort from a view and couldn't find anything. So I tried to force:

<?php

/**
 * Implements hook_views_pre_view().
 */
function sd8_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
  if ($view->id() === 'content' && str_starts_with($display_id, 'embed') && \Drupal::routeMatch()->getRouteName() === 'entity.user.canonical') {
    $display_data = $view->storage->get('display');
    $info = &$display_data['default']['display_options']['style']['options']['info'];
    foreach ($info as &$column) {
      $column['click sortable'] = FALSE;
    }
    $view->storage->set('display', $display_data);
  }
}
?>

Even for me, that's some spectacularly ugly code. And it doesn't even work. How could this be done?

DiDebru avatar
ng flag
You should be able to control this via views_ui.
Smartsheet eng avatar
um flag
I have indeed built around the problem with the UI but creating a new embed for every use is just not a real solution. This 100% can be done from code it's just so convoluted.
No Sssweat avatar
ua flag
@̷c̷h̷x̷ An alternative is to disable link via [template file](https://github.com/drupal/drupal/blob/9.5.x/core/modules/views/templates/views-view-table.html.twig#L71)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.