New answers tagged

0 votes

Is it possible to populate a field entity reference with query parameters?

For example.com/path?id=55 [current-page:query:id] For example.com/path/55 [current-page:url:args:last] For example.com/path/alias [current-page:url:unaliased:args:last]
user avatar
1 vote

Views SQL query not showing in production

Found it ! I had this written in a production config file $config['views.settings']['ui']['show']['sql_query']['enabled'] = FALSE; $config['views.settings']['ui']['show']['performance_statistics'] = ...
user avatar
  • 51
0 votes

How to show terms with a specific depth as exposed filter

Not possible with Drupal core, you'll need to install the Simple Hierarchical Select contrib module.
user avatar
  • 29.5k
1 vote

Proactively rebuild view cache

You could render the view isolated from the page content so that the cache data of the view doesn't bubble up. For example in a block: public function build() { $view = Views::getView('my_view');...
user avatar
  • 88k
0 votes

How do I override the template file of a view so that it no longer displays links in my view, but only the plain text?

As a workaround, you can use the striptags filter of twig to strip the anchor tags. https://twig.symfony.com/doc/3.x/filters/striptags.html For example: {{ some_html|striptags('<a>') }}
user avatar
2 votes
Accepted

How to render a custom block with variables from another custom block twig template

Variables are passed from PHP/preprocess to Twig, but never vice versa. Instead of preprocessesing the filter of the second block, replace the product type filter in the 2nd views block with a "...
user avatar
  • 4,909
0 votes

How do I print an exposed filter block in a template file?

I almost always use the twig_tweak module, there is 3 ways to render a block. You can see the doc here Twig tweak Block render, you should probably use drush ev "print_r(array_keys(\Drupal::...
user avatar
  • 366
1 vote
Accepted

Persist query string arguments across all links in a particular menu?

I ended up solving this by building the tree and menu render array and injecting it into the view template in a preprocess function (this is fired for both displays on the view). The key point was ...
user avatar
0 votes

How do i change date format in View Exposed Date filter?

I'm expanding on Wasim Khan's response, as it worked well for me. First, the Better Exposed Filters module needs to be enabled, and the exposed form display needs to be set as BEF rather than the ...
user avatar
  • 14.7k
0 votes

Add custom actions

Possibly another, simpler, approach might be to use VBO (views_bulk_operations) and a custom action. VBO will give you checkboxes beside each row of your view and then a button at the top/bottom of ...
user avatar
  • 907
0 votes

How do I filter by year?

I think we should use the regular expression operator because it is easier to change the year:
user avatar
0 votes

Programmatically check the checkbox of an exposed filter

You can use hook_form_alter() by adding view id condition. The use the code below, replacing FILTER_NAME with the name of your filter and set the necessary options. $request = \Drupal::request(); if (!...
user avatar
  • 1
0 votes

CSS in custom module not loading

libraries is not a valid key for a module .info.yml file; that key is for theme info files only. The full list of valid properties is available here. There are a few different ways to attach libraries ...
user avatar
  • 163k
1 vote
Accepted

How to display in a block the media used in a node?

Media images that are embedded with CKEditor into a text field are referenced using <drupal-media> tags. These tags are parsed by an input filter when the node is rendered. So, as far as I ...
user avatar
0 votes

how to change the size of an exposed filter autocomplete form?

There is currently an issue in the Claro theme to reduce the exposed filter size but until then you can use this. Replace MYMODULE, MYVIEWID, and MYBLOCK. Haven't test this but it should work. I know ...
user avatar
  • 629
0 votes

Change weight/order of exposed filters

There are some possibilities to accomplish this. Rearrange the filters via the Views UI Will not work if you added a filter via custom code. Create a hook_form_views_exposed_form_alter hook and set ...
user avatar
  • 183
0 votes

Splitting exposed form filters amongst several blocks

Although not perfect, a possible solution is to modify the exposed form. For me, the file was views-exposed-form--search.html.twig. You can then display your separate form elements using things like: {...
user avatar
  • 323
0 votes

Watchdog table growing out of control

As mentioned by Clive you need to reclaim the diskspace, however when I had a similar issue in the past OPTIMIZE was too slow and crashed the site. According to the MariaDB knowledge base it should be ...
user avatar
0 votes

How do I use hook_preprocess_views_view_unformatted()?

Pass the object into the $variables array, and then in one of the Twig templates issue {{ kint(var) }}. Drupal might be using output buffering there, which would explain why you don't see any output ...
user avatar
0 votes

How to alter output of markup on a specific views field

To anyone experiencing a similar situation, you can have a look at: https://drupal.stackexchange.com/a/264191/106121 For Global Text Fields in Views (nothing) using HOOK_views_pre_render(\Drupal\views\...
user avatar
0 votes

How can I filter multiple node IDs at the same time using exposed filters?

In views context filter settings is a section where you can enable multiple value splitting, e.g.: 1+2+3 (for OR) or 1,2,3 (for AND)
user avatar
  • 131
3 votes

Use path alias as contextual filter

You can for example create a custom ViewsArgumentValidator and transform the given alias to the Node ID. <?php namespace Drupal\my_module\Plugin\views\argument_validator; use Drupal\path_alias\...
user avatar
  • 183
0 votes

Programmatically create result row in views

The short answer is No. Views is only capable of returning Content entities. The approach I recommend is to use Feeds to import your data into custom entities. You can either define your own custom ...
user avatar
  • 870
1 vote

Render a fulltext exposed search bar separate from the rest of the filters

You can render one by one by: {{ exposed.filter_1}} {{ exposed.filter_2}} And group them as your wish. About the render {{ exposed }} twice as your current solution, The items you don't want can be ...
user avatar

Top 50 recent answers are included