New answers tagged

0

Got it to work with the following code. I needed to output the changed value in the $vars['output']. This would override the url in the nothing_1 field so I then had to create a new link and use that to alter the original value. /** * Implements hook_preprocess_views_view_field(). */ function frontview_general_preprocess_views_view_field(&$vars) { $...


0

Figured this out. Have to add the following 2 filters: operator is "Is greater than or equal to" value is today AND operator is "Is less than" value is today +24 hours Notes: Must use "Is greater than or equal to" to include today at midnight and must use "Is less than" to filter out tomorrow at midnight. It does not matter what value type you ...


2

You cannot directly insert values into queries in Drupal. They need to be escaped. You would want something like this: $count_users_premium = db_query('SELECT COUNT(license_id) FROM {commerce_license} WHERE state=:active', [':active' => 'active'])->fetchField();


0

I was also trying to get the url parameters, but the current path was only returning the path without the parameters. The following solution worked for me in a page preprocess function, I haven't tried with views fields but it should work also. function yourtheme_preprocess_views_view_fields(&$variables) { // Retrieve an array which contains the ...


1

Here's the How: {% set headline %} {{ label }} {% endset %} {{ headline|striptags }} as found here


0

When checking the current route match in a Views Ajax request you get the route of the Views Ajax endpoint views/ajax and not the route of the page where the View is placed on. However, Ajax requests contain the original path of the View and ViewAjaxController::ajaxView() puts this path in the global current path stack (for the pager to work correctly). So ...


0

In D8 you need to create custom serializer and encoder to alter the XML tags. Create custom serializer Ref : https://gist.github.com/BERRAMOU/dd21e009eec0e3d98733e78360122892 Write custom encoder - namespace Drupal\custom_serializer; use Drupal\serialization\Encoder\XmlEncoder as SerializationXMLEncoder; use SimpleXMLElement; /** * Encodes xml API data....


0

Writing your own question is always useful. I may have a solution, even if you may have something different, so please share. I have built a Views block with a custom text (my link) as unique field (only show one result, you do not need to repeat the link, of course). I have added a contextual filter based on content type with a default value provided by ...


0

In Drupal 8, Views pages allow you to render your exposed filters as a separate block. In your view, select your Page display, then, under Advanced, toggle on the option Exposed form in block. You can now separately place the exposed filter like any other block. It doesn't even need to be on the same page as the view results.


0

I solved a similar problem a little differently. You can create a computed field in the taxonomy and recalculate it either with a cron job for all terms, or after adding/editing a node for specific terms of this node. In the settings of the calculated field, select "stored in the database". And in the View display the value of this field, stored in database.


0

I needed to convert a contextual filter to be an IS NULL condition. I was able to do this with a query alter. I set my contextual filter to a fixed value of string "null" and then created a custom module with a MYMODULE.views_execution.inc file. // loop over where groups if (is_array($query->where)) { foreach ($query->where as $whereIndex => $...


0

I'm assuming that the paragraphs are attached to your node via field. Let's assume the field is called field_paragraphs. Try the following: $node = \Drupal::routeMatch()->getParameter('node'); $paragraphs = $node->get('field_paragraphs')->getValue(); This works because Drupal's routing system utilizes upcasting to promote the nid to a fully loaded ...


0

In view block, select filter criteria, select title


0

I had to use the cache_control_override module recently because the caching was not working for anonymous users when set from the views_ui or even programmatically. This module just needs to be enabled and has no configuration and my views caching started working. Sounds you might have the same problem. You can give this module a try. The module solves ...


1

To override templates for one view page or block, i guess you should add another suggestions like views-view-fields--VIEW_NAME--DISPLAY_NAME, to do so you should implement hook_theme_suggestions_HOOK_alter. here is an example for views_view_fields hook: /** * Implements hook_theme_suggestions_HOOK_alter(). */ function ...


-1

Hey i think you need to override only one node template, If i am not wrong then,you need to override only node page for eg.you created 'Promotion' node page and in your case your 'Promotion' page node has eg. 101. According to that node '101' will be override. eg. node--101.html.twig or node--promotion.html.twig Note - You don't need to create ...


0

Did you override view ?? If your not override view Please follow below views view suggestion - views-view-fields--(yourviewmachinename).html.twig views-view-unformatted--(yourviewmachinename).html.twig Note - In views-view-fields--(yourviewmachinename).html.twig,file render your fields which are present in that view Eg. If will have field - title follow ...


1

Yes. The pattern will be something like views-view-promotions--display_name.html.twig See https://api.drupal.org/api/drupal/core%21modules%21views%21views.theme.inc/group/views_templates/8.2.x Also, I recommend you activate Twig debugging (https://www.drupal.org/docs/8/theming/twig/debugging-twig-templates) to see actual suggestions.


0

Does it need to be done programmatically? Why not do it within the views UI, you can set the caching to "Time-based" and set a 5min limit. This is in the "Advanced" section and the 3rd from bottom item


0

Views has a cache plugin for no caching which you can configure in UI. Better use this method, setting a cache max-age in a hook might not be enough to disable all caching in a view. Also you can't control traffic from anonymous users by this. If you have dynamic views you want to deliver to anonymous users uninstall the Internal Page Cache and set the Cache-...


2

Click "Add" on "Filter Criteria" on the left column. Then add a filter called Content: Translation language and set it to Content language selected for page


1

Add a relationship in your view using the field you do the entity reference with. That will expose all of that entity's fields to be used in the view


0

It sounds like you have your AJAX callback working fine. But you said that the #ajax wrapper is wrapping the entire form. The elements returned from the ajax callback replace everything in the div provided as a wrapper. Since you are wrapping your whole form with the wrapper, everything inside that div (the whole form) is replaced with the elements from the ...


1

One possible soliton is to simply when declaring your custom tokens in hook_token_info() use $info['tokens']['view'] Ex: $info['tokens'] = [ 'view' => [ 'my-custom-token' => [ 'name' => t('Custom Token'), 'description' => t('A custom token I created.'), ], // 'my-second-custom-token' => [... ...


2

As mentioned before you have to enter a UNIX time into the text field. If you want to use a date picker in the exposed filter in Drupal 8 have a look at this issue (currently there is a patch for that): https://www.drupal.org/project/drupal/issues/2648950


2

I ran into this issue on D7. I enabled the views query and noticed that the values were being passed as human date to the query rather than timestamp. So what I did was use hook_views_query_alter and converted them to timestamp. Example code (D7 code) function mymodule_views_query_alter(&$view, &$query) { if ($view->name == 'list_employers') {...


1

Thanks to all, especially @belltouche and @Jaypan, for taking the time to respond. After all the kind suggestions and lots of reading and trial-and-error, I ended up using the following code in views-view-table.html.twig to display an image URL: {% for i, row in rows %} ... {% if view.field.field_image.value(view.result[i]) %} {{ row.columns....


0

You can easy translate view header and footer text using the {% trans %} Twig tag in Drupal 8 Example: {% trans %} Text for translate {% endtrans %} And after that you will be able find text in user interface translation "admin/config/regional/translate"


0

I just wanted to comment on here about what to do if you're using the D7 version and come across this post (like we did). Here's the two relationships you will need to add in order to have SKU as a filter: Commerce Order: Referenced line items Commerce Line item: Referenced products


0

I believe Views Better Exposed Filters can achieve this: What else can I do with BEF?: Provide instant feedback by updating the View using AJAX whenever an exposed filter is changed


0

To allow nested Facet searches based on referenced entity titles, in our Drupal 8 site we defined a custom-field with a processor (which creates my_titles_field field); Place the MyCustomProcessor.php file in modules/custom/my_module/src/Plugin/search_api/processor/ directory; With contents like below: <?php namespace Drupal\my_module\Plugin\...


0

For a custom Views Field template, you can access entity field values in the row with a dot structured format with something looks something like this: row._entity.field_name.value for the base entity, or row._relationship_entities.field_name_that_brought_in_the_relationship.field_name_on_the_related_entity.value when accessing something you brought in via ...


0

Below code will exclude the autocomplete in Drupal 8. $form['keys']['#attributes'] = ['data-bef-auto-submit-exclude' => ''];


0

You can use the drupal build in file_url twig function for that: {{ file_url( fields.field_notice.content) }} You can find more information about the Drupal build in twig functions here: https://www.drupal.org/docs/8/theming/twig/functions-in-twig-templates


1

You could try a different approach, via the Views UI, adding the same image field 3 times, and assigning each of these different image styles. Add a View result counter field, this will let you know the row number. Then on template/twig file print image field that was assigned x image if counter (this is the twig variable name for View result counter) ...


0

Drupal's Core Serializer does not provide options to customize the json, nor does it include the pagination data. The Pager Serializer module does include the pagination information, and the property names are customizable, so your api can remain unchanged. By default, it produces something like this. { rows: [ {...}, {...} ], pager: { ...


0

You have two "simple" options and a third "hard" option, which involves writing a custom Views field ... I'm going to skip that one and focus on the simpler options. Those links all share a common pattern with only the order ID changing based on the row you're looking at. You can use tokens ("replacement patterns") in custom text fields on Views, including ...


Top 50 recent answers are included