New answers tagged

0

Thanks to @4k4 (here) and @nikathone and @dorf (via Slack), I was able to arrive at this, placed in exposed_filter_images.module (all caps should be replaced with a machine name): function exposed_filter_images_block_alter(&$plugins) { if (isset($plugins['views_exposed_filter_block:VIEW_NAME-DISPLAY_NAME'])) { $plugins['views_exposed_filter_block:...


0

None of the above solution worked in my case. Here how I solved it by coding function mytheme_preprocess_views_view_field(&$variables) { if ($variables['view']->id() == 'my_viewname' && $variables['field']->field == 'field_description') { $output = $variables['field']->getValue($variables['row']); $variables['output'] = ['#...


0

The second argument to views_get_view is $reset: If TRUE, reset this entry in the load cache. So second time around you just need to pass that: $view = views_get_view('my_view'); $view->set_display('default'); ... $view = views_get_view('my_view', TRUE); That will reset the static cache and the data will be fresh.


0

Solved. The problem was that I had a template file for html.html.twig, where the main content was being wrapped in two divs. The problem was that the code <js-bottom-placeholder token="{{ placeholder_token|raw }}"> was being wrapped too making the AJAX fail, although I don't know why only for users that were not administrators. Moving this piece ...


0

Figured it out. Had to use the striptags filter. This works like a charm! {% if php|striptags in field_dates|striptags %} True {% else %} False {% endif %}


0

This code should do it: function MYMODULE_form_views_exposed_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { $view_ids = ['YOUR_VIEW_ID']; $view = $form_state->getStorage('view'); if ($form_id == 'views_exposed_form' && in_array($view['view']->id(), $view_ids)) { $form['field_new_used']['#...


0

You can create a relationship to the media from the fields. In advanced add a relationship to the two media fields.


0

Since you're creating a reference to a location node, you'll know its node id upon saving the event. At that point, you need to call \Drupal\Core\Cache\Cache::invalidateTags([$nid]) where $nid is the node id of the location. There are many possibilities where this could be invoked, for example, in hook_entity_presave()


0

I have been doing something similar and put this code in each of the cells where I wanted the information top aligned . . . <td style="vertical-align:top"> It has worked well for me. Overrides the CSS as I only needed it in select cells.


1

Try adding the placeholder % to the path (in the main views UI in the middle column under "Page settings"), e.g. something like my-view/by-year/% which will accept URLs like my-view/by-year/2019


0

To show the Parent info (Company) through Child nodes (Employee) you need to add the Relationship for the Entity Reference field that is connecting the child to the parent. Once you add that Relaionship you will be able to add the fields from the Company CT. Those fields must use that Relationship to show the Company info, otherwise if you don't select the ...


0

You can use a PHP field. Place it after the field you want to rewrite. Hide the initial field and use PHP to output the result. This does quickly become opaque as noted it is best to go under 'advance', review the template choices (at the bottom of the column) and then put the php in the template. I have also been trying to avoid this and use display ...


0

So I was able to get my functionality by changing the Contextual Filter to a query parameter: So in my widget block, I changed the link values from /press-releases/2015 to /press-releases?year=2015. Now the functionality works as wanted. Both urls /press-releases/ and /press-releases?year=all show all the press releases, and the node urls still work.


0

You can 'hide the title' field from the display and afterwards create a php field. The php field can reference the title field if it is declared higher in the list than the php block and then you can use php for your condition.


0

Views module comes with the field Has new content that outputs New or Updated depending on the status of the node as being viewed by a visitor. Anonymous visitors don't see anything because there is no history record about that users visits to a particular node. Authenticated users will see the word New if they never visited that node. If they have ...


1

Ok, yeah, I feel a bit silly now and was making this too difficult. There is a module for this for Drupal 8! I was able to accomplish what I needed with Views Custom Table. Thank you prkos for the comment.


0

You'd have to come up with your own query to make it work. To display "the most recent date" you'd have to limit the results to only 1. If you allow for all 3 CTs you'd get the latest date for whatever the number was latest, but that would still be only one result. Which number or which CT would be a chance. You can create 3 different Views, one for each ...


0

I would try this. Go into The solr server configuration - assuming it's named 'solr' /admin/config/search/search-api/server/solr/edit In Advanced, see if "Targeted content domain" is set to scientific. And see the description next to it to see why I'm thinking this might be your issue. Save. You'll probably need to re-export your config zips and ...


1

My edit gave me a clue to look at the date formatting. In our specific calendar instance there is an event-calendar.js file that was manually converting the dates pre-Drupal 8.7 to UTC with a .field_date_range[0].value+'+00:00',. It appears that Drupal 8.7 does this automatically, so removing that extra bit of code solved the issue and dates are being ...


0

having run into the same problem as you I hope I can save you a headache. Depending on the amount of results you have I can provide 2 ways to tackle this: 1. Works when you don't need pagination HOOK_views_post_execute. This will have the rows in the variable. In here you can check the access and unset() the rows not allowed. 2. Works when you need ...


0

What you're looking for is often called "siblings". When sharing the same Taxonomy terms there are Contextual filters Has taxonomy term that can be used and this can work in a lot of cases. But there are cases even with shared Taxonomy that needs to go a different route (possibly when using Aggregation or Multilingual sites). That second "sibling" route ...


1

Yes you can use the Rewrite results option on your Field settings. Use the Output this field as a link option and enter only the URL with the field token replacement pattern at the end of it. You can look up the token under Replacement patterns under the Rewrite results option. If you need some more control over the link HTML you can use the Rewrite the ...


0

A module that provides the "collapsible" functionality is Views Accordion so maybe you can try it and see if it performs better. But it doesn't change the layout depending on the browser width. The proper way of addressing this is with CSS. You can use CSS grid to make the fields appear as a table on wider widths, and stacked one below the other on ...


2

Goto admin/structure/views/add and add a view like below: After adding view, go to view edit page and Under "ADVANCED", select "Contextual filters", and add "Content: Id". Under "WHEN THE FILTER VALUE IS NOT IN THE URL" check "Display all results for the specified field". In the same block, under "Exceptions", Exception value should be null. Check below ...


0

You don't need "Better Exposed Filters" to display the Exposed Taxonomy term filter dropdown with hierarchy. It works in both cases, the "Basic" and the "Better Exposed Filters". Just make sure that in your Term Filter settings you have chosen Dropdown with Show hierarchy in dropdown instead of the Autocomplete option! Better exposed filters additionally ...


0

It's very simple to create the tree structure output you're looking for: Create the Content type Views, add the Taxonomy term Field next to the Title field, under Format Views settings choose to group by the Taxonomy field Grouping field Nr.1 On the Taxonomy field choose Exclude from display. This will give you a list of nodes that are displayed in ...


1

Adding Relationships often causes duplicate rows in the results. You can "remove" the duplicates using the Aggregation in Views (enable it under Advanced). Then adjust the Aggregation settings for some Fields, specifically the Group column option. You may need to change it from Value to Entity ID or vice versa. The exact combination of settings depends ...


0

This is old, but there is some misinformation here so I thought I'd contribute. Make sure you expose your pseudo field to Views. Don't overdo this and confuse yourself, just add what is required. The handler doesn't need to be defined in here cause you can use annotations. /** * Implements hook_views_data_alter(). */ function hook_views_data_alter(array &...


0

I have a view set up that sounds similar to what I think you are trying to accomplish: Create your content view filtering by taxonomy. Create your taxonomy view. Go back to your content view and use "no results behavior" under "advanced" and insert your taxonomy view into your content view as a "global view area". Now where there is no content assigned ...


0

This is my solution in D7/Views 3. It adds a last order_by clause to the query if its not already present. I believe you could look at the $view parameter and add the order by columns from there if you dont want to do it statically like I did. function MODULENAME_views_query_alter(&$view, &$query) { if ($view->name == '...


0

That's probably an opinion-based thing and actually also a too broad question. But here's what I'd do: Programmatically create a new block. Provide a hook_theme and your own template to later render the output the way you want. Follow one answer from How to get all node entities tagged with a specific term? to get the data you need. In the block's build() ...


0

I have managed to create a usable filter, though there is still a portability issue. This is the filter class I ended up with: /** * Filter to handle dates stored as a timestamp. * * @ingroup views_filter_handlers * * @ViewsFilter("views_dates_day_of_week") */ class DayOfWeek extends InOperator { /** * {@inheritdoc} */ protected function ...


0

Just an update for those than land here for Drupal 8.5+ The Path field no longer exists in views, you now need the "Link To Content" field instead. If you need to output the path only, then make sure you tick the "Out put URL as Text" option. Reference: Issue raised on DO after Path field disappeared in Drupal 8.5.0


2

The easiest way would be to execute the View again in the page preprocess hook. If you want to avoid executing the View twice the task is getting a bit more tricky. This is because in D8 page elements are not necessarily rendered downstream in the order you expect. The element could have been cached in a previous request or in case the element doesn't ...


0

You can use both Rewrite and Grouping at the same time. You can Rewrite the field and use that as Group by. If you need the same Field in the results as well as in the Group by headings, then simply add the Field twice. You can style/Rewrite them separately too. If you want to style the grouping in a special way, or need more than one field in the Group, ...


1

First I need to comment on the UX of the long titles. Is there some huge difference between your desktop and mobile users WRT the title length? If the longer titles are better for users then maybe they should be long on all devices. If there is not much lost by trimming them maybe they should be trimmed on desktops too, or simply rewritten to be shorter? ...


1

Views::getView is just a shortcut to loading the entity via the usual methods - it doesn't execute the View, so you won't see any results with the object you have. I'm not sure there's an elegant way to do what you need (although I hope I'm wrong, it seems like there would be). One simple-ish workaround would be to hook into the View's build process after ...


0

There is a good recipe for using leafhttps://civicrm.stackexchange.com/questions/12862/how-to-put-your-civicrm-contacts-on-a-leafleft-map-in-5min if you are happy to slightly switch track. For D7 Also you will get more Civi eyeballs if you post on that channel, and while I appreciate this is a 'drupal' question, more civi folk use drupal than drupal folk ...


0

There are features in Views concerning taxonomy hierarchy, displaying terms with depth, you should look into it. There is also Group by field option under Format in Views where you can, for example, group by Parent field (Parent of the Taxonomy term). You may need to add a Relationship for the Taxonomy field first before you can see those extra Fields/...


1

The appearance of the Select widget on a Content type can be changed on the Manage form display page for that Content type (for example for Article CT it's under Structure > Content types > Article > Manage form display (/admin/structure/types/manage/article/form-display)). For a List field you can change it from the Select list to Check boxes/...


0

You can add extra fields (referencing taxonomy vocabulary(fresher/prathama/prarambhik) to user profile. You can add extra field to user profile under configuration->account settings . Now you can display the list of questions based on the "reference field value(fresher/prathama/prarambhik)" . Good luck!


1

Well above solution may work but it looks far too complex to my eyes. ;) I have achieved this on Drupal 8 by following below steps, Create a user view Load user data into fields Add relationship to "webform submissions" (Do not enable "Require this relationship") Add filter "Webform submission: Submitted by" Set that filter to "Is Empty (NULL)" This will ...


0

It turns out that I had to add a relationship to Product Variation Type in order for those fields to show up. Hope this helps others!


0

Here's a step-by-step: Install the UI Patterns Views module Insert the fields and map them to the UI Pattern fields Note: You are mapping fields for the rows. At this point, each piece of content should be rendered as a UI Pattern Now, if you want to arrange the cards in a specific way (say, using Masonry), then you can do it in one of the following ways:...


-1

It's been a while since this question has been asked, but in case someone searches for a solution for this problem and ends up here (like I did): You can add the iframe-Tag to the Xss whitelist: Open the file core/lib/Drupal/Component/Utility/Xss.php Add 'iframe' to the $adminTags array After refreshing the cache, iframe-Tags will no longer be stripped ...


0

The solution above is for Drupal 7. In Drupal 8, hook_views_ajax_data_alter is deprecated and was replaced by hook_ajax_render_alter. For those of you looking for it, here is how to do it in Drupal 8 (source here). function YOURMODULE_ajax_render_alter(array &$data) { foreach ($data as $key => $command) { if ($command['command'] === '...


0

Normally you would iterate through the rows and call a row plugin to render the field values. As I understand the question you want to access the field values directly by row index and field id? Then try StylePluginBase::getFieldValue: $value = $this->getFieldValue($index, $field); Normally a style plugin iterates the rows like this: public function ...


1

According to your description and code you have only one requirement that is update views block on form submission. So, You don't have to alter the form AJAX as AFB form submission already uses AJAX. Furthermore, you don't have to replace the form using ajax_command_replace() as its already replacing using AFB You don't have even to return the form as well. ...


0

I think using views for displaying a part of node fields on the node page is not the best way to do it. I would create a page template and a node template for Article content Type and display the needed fields there. You can find more about Drupal 8 theming here Also, training materials by Drupalize.me are fantastic. Let's do it the proper Drupal way.


1

Different Field information can be displayed in Views by using the Rewrite results and Replacement patterns options in the Field configuration. Different Field data is usually available as tokens (replacement patterns) that can be used to construct a different output than those available under the Formatter option. Here's an example for displaying the ...


Top 50 recent answers are included