New answers tagged

1

I have created a patch for @4k4's answer that also uses dependency injection. To apply this patch: Take the code snippet below and paste it into a new file e.g test.patch. Then run git apply /path-to-file/test.patch. For a UI only solution, see my other answer. diff --git a/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php b/core/...


0

Just download a newer version of views and replace in your project. https://www.drupal.org/project/views/releases If you're using composer just require a newer version. Then, you should be able to install your drupal. Best regards :)


4

Comparing TermSelection::getReferenceableEntities and ViewsSelection::getReferenceableEntities it seems like the Views entity reference selection plugin doesn't translate the entity before returning the entity labels. It should work with a core patch adding one line: /core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php: public ...


1

OK, I figured it out. I simply added a duplicate of my "Content type" filter, except this filter is not exposed. Same settings as above ("Is one of", Article/Post/Story, etc.), just an extra restriction on the results to always filter by all of the desired content types, with the exposed filter being an additional option to further narrow down the results.


1

I found a way to do this in the UI. You'll need to use the translation_views module. Here's a screenshot of the needed filter configuration: The logic is simple, if the node has no translations then show the original language, otherwise show the translation language. I use the translation_views module to get the Translation counter filter.


0

This is what I have, however, I feel there must be a better way to do this. Some notes: $view->render(); is critical, without it, it doesn't work 'nothing' is the default name of custom field, adding additional fields will result 'nothing_1', 'nothing_2', etc. You can see the name when hovering over the field (in the link) or in the replacement patterns. ...


0

I tried many different complicated approaches, before I found a much easier solution that suits my needs so I am posting this as a solution. I setup my prints View this way: Category is added as an exposed filter No contextual filter, no relationship Set the view path to prints/% Use AJAX: Yes I created a module and used hook_views_pre_build() to get the ...


0

I've found a solution with a different approach With form_alter I've targeted the form and edited the filter labels, by adding a custom query and counting items from the search_index table with a left join to the node_field_data table in order to get the node type


0

Here's how I solved my problem: Added an ID field (the ID from the source I'm pulling/validating player names) to my variation. On creation of a variation, I store the ID in the field when the user selects the player name during product creation, e.g. "Barry Bonds" is ID 35456 in my source. I'm using a regular autocomplete route in my form instead of an ...


1

There are many ways to solve this, you can take different approaches to the filtering part, the URL part, and the contextual part, and how they play together to get you to your goal. Here's one of the possibilities, probably the easiest route: This is solved by adding a Relationship for the category field, and then adding a Term "Name" Contextual filter (...


0

The described scenario doesn't need custom coding as it is shipped with Drupal 7 Views module. The approach to use a views block in a views page that shares the same filter can be done using the "Attachment" view. You can find more about views attachment here Also, there is an answer to place the attachment in a different page region here Hope this ...


2

Yes that should be easy enough. In your view with the 100 projects you need to: 1)Add a relationship to the entity queue but DON'T make it required 2)That will make a filter called "Content In Queue" be available for you to add 3) Set that filter to "No" And that's it any entities that are in the queue won't come out in that view now


0

Using the following code to target the file name image source, I could hide one of the two images in the Views showing the current Node which had Image fields in. In this case, one .SVG filename exported from Inkscape was called "sales_discount_alt_mobile_2019" with 'mobile' the alt field from the Desktop graphic image. So in my Desktop @media CSS rule I ...


4

I don't think hook_preprocess_views_view() or hook_preprocess_page_title() is good ways in your case. You can use hook_views_pre_render /** * Implements hook_views_pre_render(). */ function MYMODULE_views_pre_render(ViewExecutable $view) { if ($view->id() == 'VIEW_ID') { $arg = $view->args; // Argument from view. $default_title = $view-&...


0

Finally got it to work! Here is how you do it. Assuming your field is called field_category. My template is called views-view-unformatted--my_view_id_name.html.twig. {% set my_category_id = row.content['#row']._entity.field_category.0.target_id %} It does seem pretty silly to me that it has to be that long. It would be very cool if it was something ...


1

Easiest to preprocess the page title is MYTHEME_preprocess_page_title(&$variables) and then use $variables['title'] = 'New Title'; to set a new page title. Inside there you can load your view by its ID and do whatever you need to do to have the title manipulation fired. use Drupal\views\Views; /** * Implements hook_preprocess_HOOK(). */ function ...


0

The way to list nodes that reference the one you're currenty viewing is by adding a Contextual filter for the Entity reference field that connects them. You have one more connection in between - the Paragraph. You already added the Relationship to it so you're half way there. Now that you have the 'my_field' available you need to add the Contextual ...


0

One way to create a filtering system that counts the results per category is by creating a Contextual filter for the type with the Summary option. This will list all the types as links, and show the number of results next to each type name. When you click through those links you will see the results for that one filtered type under the Format you set in ...


1

Sounds like you want to use search facets. Facets are ways of showing various search 'tag' information for the current results with/without counts. Note that this is slightly different from a filter which will show all values even if there is no result with the specified search criteria. That said, there is a defunct facets core search module. As the ...


0

Do I have to pass a token (such as [node:nid]) as an argument to the view in the entity-reference field configuration? Yes. Is there a module for that? No, but this will work in core with a patch from Dynamic Views Arguments via Tokens. If you'd like the depending field to update automatically whenever the dependent field changes, see Add AJAX support ...


0

The core issue for this is Add AJAX support to fields using Dynamic Views Arguments via Tokens, but at the time of this writing the only option available without custom coding is Business Rules' dependent field functionality. However, there are still unresolved problems with multi-valued fields. See Multi-valued dependent child fields are not saved for ...


0

I found the solution to my problem. In addition to setting "Exposed form in block: Yes", I had to check the "Expose this filter to visitors, to allow them to change it" option for my "Search: Fulltext search" filter. The search form was properly displayed once that option was set.


0

Because of the problems with no default value, we decided to re-utilize the 'sticky' field on our content type. A default value of '0' already exists for that field. If you are in a situation where you can't use that, look at hook_post_update_NAME as gapple answers. Edit We just learned, the hard way (bug report), that the use of the sticky fields requires ...


0

Exposed filters on blocks will only work if you've enabled ajax on the view. Try enabling that and your filters should appear


0

This will take a few steps. Define an extra view mode, say 'short title'. Refer to How do I add additional view modes for a node?. Format the short title view mode for the related decision so as to just show the short title field. Suppress the regular title on that view mode by making sure the Display Suite Extras module is enabled then using the hide title ...


0

I compared the views on the newly installed site. In the "Is not one of" operator, no options were selected. After setting up the workflow, I realized that I needed to check it. Thank you.


0

If the field has a default value configured, you may be able to cause the "Pinned" field to be populated by bulk editing the nodes from the content overview page, and toggling a different value like 'Published', 'Sticky', or 'Promoted to front page'. For a programmatic solution, implement hook_post_update_NAME to load the necessary entities and update the ...


0

FWIW, I found a work around that doesn't involve modifying core, though its much less elegant and only really applicable if you only have a few terms. It also requires the twig_tweak module. Basically I created a view block for each Related Products block filtered by one of the terms. Then in the twig template for the product view I created a bunch of ...


1

If the data about a product are not available when processing a "line item", you can make them available. To do so, use a technique similar to what is explained in my answer to "How to access commerce_product field of line-items using Rules to flag the Commerce Product?", which includes a Rules Component that looks like so: { "...


1

There is the Expose items per page option under Pager options, so this might help a bit. This allows users to change how many results they want to see per page. Why do you want to show different pagers for the same set of results? Pagers can add to the performance strain. There are some contributed modules that add to the Views pager, try searching for ...


0

Block-plugins that inherit from BlockBase can have their context values directly set via ContextAwarePluginBase::setContextValue($key, $value). This method can be used by a preprocess function to inject context that isn't otherwise available from the route or environment. In my case I have a block that needs a group entity in its context: <?php ...


0

Try looking into Permissions by Term and similar modules that override how access is handled. That module can take care of hiding the nodes from users based on taxonomy terms. You can create a Vocabulary with access terms and assign nodes with them, and allow different user roles to view nodes based on that taxonomy. Then in the Views listing all the nodes ...


1

$view->field['request_access']->options['exclude'] = TRUE; Exclude will always exclude the field for every single row. What you need to do is set it to null or empty '' $result->field_request_access = null; // hide request A possible downfall is that a user could guess, or have someone tell them the direct link, and still be able to see /node/...


0

There are a lot of answers you can search for "sibling taxonomy" or some other wording. Here's one answer you can follow: Filter taxonomy term attached to user field The only difference is you always want your views to show the current user's matches, and not create, for example, profile pages for everyone separately as it is in that answer. To make ...


1

Using the PHP filter in the fields should require you to use <?php ?> tags as part of the content. The views data (unless its been exported with features) will sit inside the cache_views table in your DB, so you should be able to reliably find views using PHP filter by searching like so: SELECT * FROM cache_views WHERE data LIKE '%<?php%'; There ...


1

There are a couple of solutions to do this. First one is to convert your data into nodes (content) and then easily show them in Views as a table. (You might achieve this using the Feeds module. Export your table data as CSV and use Feeds to import it as a new content type.) Second solution is to use the Views Custom Table module. About View custom ...


0

There is a module for this - check this out: https://www.drupal.org/project/views_extras


0

Eventually I realised that it was only tokens containing hyphens that weren't working, and sure enough, it turns out that hyphens are not allowed in Twig tokens. Or, to be more accurate, they are interpreted as minus signs (https://www.drupal.org/project/drupal/issues/2371633). That was why the {{ access-url }} token was returning zero: access minus url ...


0

I guess Filebrowser module is what you looking for : This module provides an interface for administrators to expose directories on the file system to users through a file listing as in a FTP application. You will create one node (node type dir_listing) for each each Directory Listing (DL). Node settings are used to control access and other features of the ...


0

I'd do it like this. Example below is used for node templates: use \Drupal\views\Views; function MYTHEME_preprocess_node(&$variables) { // make the result count available as a variable for a certain content type if($node->getType() == 'news') { $view = Views::getView('related_news'); $view->setDisplay('default'); // contextual ...


2

Both of the modules mentioned (Taxonomy display and TVI) that make Taxonomy term pages easier to configure rely on Views, so you do need to have the Views sorted out before you can assign different Views to different Vocabularies. These modules don't replace the "Views magic". If you don't use these modules that override how term pages are displayed the "...


Top 50 recent answers are included