A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

New answers tagged

1

Ok, I solved it like this: function THEMENAME_preprocess_views_view_field(&$variables) { $view = $variables['view']; $field = $variables['field']; $rows = $variables['rows']; if ($view->id() == 'VIEW_NAME' && $view->current_display == 'DISPLAY_NAME') { if ($field->field == 'FIELD_NAME') { foreach ($view->field as $fieldId => $field) ...


1

In replacement to your "Learn more" add "Custom text" field after "Field_program_id" in your views. In "Text" add "a" tag like <a href="/search?nodeid={{field_program_id}}" class="button">Learn more</a> Take a look in "Replacement patterns" for available fields. Read description there too for a guidance. (this is in Drupal 8) It is the almost ...


0

There is another way for Drupal8. Try using the verf module


0

If someone is looking to change the field view mode then I have managed this something like below code. I'm using a taxonomy term view and inside term name field I have chosen Rendered Entity formatter and default view mode. In some case I want to change the view mode so that I can show another design. I made one condition like below use use Drupal\views\...


0

I had the same challenge, and I was able to set up multi-level relationships - thanks to another article on this platform.


2

Use a views_view_ hook, i.e. views_view_unformatted, views_view_list etc... I tried this with a PHP count for my views block and it worked great. My function is: function MYTHEME_preprocess_views_view_unformatted(&$vars) { $num_rows = $vars["rows"]; $count = count($num_rows); echo '<h2>This view has ' . $count . ' rows</h2><br&...


0

You can add Attachment to a view. And Page: filter -> contenttype 1 Attachment: filter -> contenttype2


0

I don't think you can get the value of field from paragraph field inside views-view-unformatted.twig all you can get is the target_id of referenced paragraph using view.result[key]._entity: I suggest to use template_preprocess_views_view_unformatted like the following: function YOURTHEME_preprocess_views_view_unformatted(&$variables) { $view = $...


0

The problem is that the records actually are distinct from a database perspective as there are multiple records generated by different entity references. The Drupal 8 core issue for this is Views relationships with multi-valued entity reference fields invalidate Distinct query option. There should be usable patches there. For Drupal 7, use the Views ...


0

This solution is working on Drupal >= 8 function YOURMODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ($form['#id'] == 'views-exposed-form-my-view-display') { $request = \Drupal::request(); if (is_null($request->get('EXPOSED_FILTER_FIELD_MACHINE_NAME'))) { $form_state->setUserInput(['...


3

Looks like Views Infinite Scroll is a good option for you: Views infinite scroll allows you to load and display pages of any view inline, using AJAX (this has been called infinite scrolling, load more, autopaging, endless pages and more). The pager can be triggered with the press of a button or automatically as the user scrolls to the bottom of the view'...


0

I have not been able to figure out how to conditionally change field to link using hook_views_pre_render(), but I did figure out how to do it within the Views UI: Fields->Parent ID->Rewrite results->Override the output of this field with custom text: {% if parent_type == 'paragraph' %} <a href="/find-paragraphs?id={{ parent_id }}">{{ parent_id }}</...


0

Currently, the Views Exposed Form Fieldset module is probably the way to go as that is actively supported and has both Drupal 7 and 8 versions.


0

Based on of the @Colan solution. Add the following Patch to your composer.json file "extra": { "patches": { "drupal/core": { "View Entity Reference Field" : "https://www.drupal.org/files/issues/2019-12-24/drupal-generalize-taxonomyindextid-filter-2429699-277.patch" } } } then run composer install and Rebuild the cache.


0

I used this code and it solved my problem. // Bind table rows that will open ctools modals to the appropriate function. $('tr.ctools-use-modal', context).once('ctools-use-modal', function() { var $this = $(this); $this.click(Drupal.CTools.Modal.clickAjaxLink); // Create a drupal ajax object var element_settings = {}; ...


2

The Easy way in Views UI add field_link 2 times. in 1) Exclude from display, Select url only, and Show url as plain text. which will give you the url only. in 2) Exclude from display, and REWRITE RESULTS -> Strip HTML tags which will give you the title only. Then in a custom field you can use twig URL: {{ field_link }} Url Title: {{ field_link_1 }} ...


0

Wow -3 rating? This was intended to be an authentic question. Not ideal, but my solution was to render a static link in the View's footer: // Render "more" link in footer $footer_options = array( 'label' => t('Footer text'), // Administrative label. 'content' => '<a href="/link/to/display">View All Events</a>', // Content ...


1

You can render a views block within another views page. E.g. you want to show 10 nodes in total, and 1 of them in full mode: Duplicate the existing view display as a new display of type "block". (Do not duplicate the entire view, only the sub-display by using "Duplicate as block"). In the original page display, in the Pager section, limit the number of ...


1

Take a look to \Drupal\views\Plugin\views\field\FieldPluginBase::renderText /** * {@inheritdoc} */ public function render(ResultRow $values) { $tokens = $this->getRenderTokens($this->options['text']); return [ '#theme' => 'custom_button', '#target' => $this->options['target'], '#class' => $this->options['class'], '#...


0

Below are a couple of things you can try to reduce duplicates caused by a multi-value field. Results will vary depending on your particular view. 1. Use aggregation Under "Other" in Advanced options, enable Use aggregation. Locate the offending field under "Sort criteria". Click on Aggregration settings, then select Aggregation type: Maximum. 2. Filter ...


0

Found the answer: // https://drupal.stackexchange.com/questions/272495/how-to-get-views-field-names-values-for-hook-views-pre-render foreach ($view->result as $key => $value) { //- Get parent_id value $parent_id_value = $value->_entity->parent_id->getValue()[0]['value']; //- Get parent_type value $parent_type_value = $value->...


1

In Drupal 8, you can do one of the following. These are in order from more recommended to less recommended: Apply the latest core patch from Generalize TaxonomyIndexTid filter to be available for all entity reference fields (unless it's been committed by the time you're reading this), Use the Entity Reference Exposed Filters module, or Follow the ...


0

To add to Berdir's answer. If you are working with a custom entity. Its best to redefine the label method on the custom entity declaration for the autocomplete to work. Simply creating a EntityReferenceSelection plugin will not work with autocomplete since the autocomplete classes reference the label of an entity and there is no clear workaround that I ...


0

I started working on a way to achieve this, however I am sure this is not the best way to do this, but it is working for my purposes. In src/Plugin/views/filter/TutorViewsFilter.php I have replaced the hardcoded entity query conditions and created some semi logic to generate them from the views handlers. $eq = \Drupal::entityQuery('node'); $...


1

Based on the following article, I have a suggestion: https://zanzarra.com/blog/custom-views-filter-plugin-drupal-8-bounding-box-geofield . I haven't tried this out myself, but I think the following should work: Override the valueForm and valueSubmit methods in your filter class: Create a form that allows you to configure whether or not to include entities ...


1

Instead of sticking on page URL, I've done this: /** * Implements hook_theme_suggestions_page_alter(). */ function mytheme_theme_suggestions_page_alter(array &$suggestions, array $variables) { $parameters = \Drupal::routeMatch()->getParameters()->all(); if (isset($parameters['view_id']) && isset($parameters['display_id'])) { ['...


0

Directly from the Drupal documentation, you can pass multiple variables like this: {{ drupal_view('who_s_new', 'block_1', arg_1, arg_2, arg_3) }}


1

Recently I ran into the same issue, but I think there's a fairly simple solution to this. Oddly enough, disabling the grouping settings for your plugin and passing the function parameter to the addField method works just fine. I'll show you what I mean: class InvitationCompletionState extends Boolean { /** * Called to add the field to a query. */ ...


0

Streamlining the above answer. To switch quantity textbox to be a select field... function THEME_form_alter(&$form, $form_state, $form_id) { switch ($form_id){ case 'views_form_commerce_cart_form_default': $select = array('1' => '1 ','2' => '2 ','3' => '3 ','4' => '4 ','5' => '5 ','6' => '6 ','7' => '7 ','8' => '8 ','...


0

Make sure that the VBO field is loaded in the Master display. In the Views module settings, it is possible to force this Master display.


1

You can view the item at /node/{node_id}. If you need the item in a view, you can add a filter to the view for the node's id.


0

So this is what I did, in case anyone wants to accomplish the something similar. You first have to add a new region just above the content region in your MY_THEME.info file which in my case was: regions[manufacturer_prefix_title] = Manufacturer Prefix Title Then I overwrote the page.tpl.php which contained: <?php if ($title): ?> <h1>&...


1

As greggles mentioned it, first thing is to check that the configuration of the view did not change. Go to yoursite.com/admin/structure/views/view/user_admin_people and look for any exposed filters in the "Filter criteria" section (maybe your features altered the configuration). Here is an example of Drupal default configuration for this view.


2

I would check: Is the views module still enabled? Is this specific view enabled? Did the configuration get changed for the view that exists at admin/people? For #1, go to the modules page and scroll down to views and confirm it is enabled. For #2, I noticed that I was able to "Disable" the user_admin_people view and then I get a screen at admin/people ...


1

To pass contextual filters with OR logic, you can make use of the Views Contextual Filters OR module: The module provides a views plugin to modify query of contextual filters. The module can changes contextual filters condition to OR logic. When you install and enable the module from Query settings in your display check Contextual filters OR option and ...


0

If you wont to show in views taxonomy terms, translated with entity_translate, try to use "Entity translation: Name" field instead "Taxonomy term: Name (translated)"


1

you will need flag module make a global user flag: user_has_content, make a rule: react on event: after saving new content of your special type, add a condition: user author is NOT flagged, inside rules action: flag it, only once your user author will be flagged, then on your view, add relationship to author & one more relationship on the new flag on ...


1

To extend and clarify Saud Alfadhli's answer for others (I'm not allowed to comment yet), hook_preprocess_views_view_field (hook_preprocess_views_view_fields with the "s" exists as well) works great for this. Both the view ID, display ID, and field ID can be easily inferred from this hook, and the field output can easily get overwritten (as both a string or ...


0

I contribute a module for this check it out here: This module add views filter by year exact, instead of full date like mm-dd-yyyy you can use date year like yyyy. https://www.drupal.org/project/views_year_filter


0

Drupal 8 views will strip away any markup it thinks it is dangerous you have to rely on a custom theme solution here is a general overview of how this can be done if you don't have a custom theme you have to create one (more info) Enable Twig debugging (more info) Inspect your page in browser to find the appropriate templates to override. In the html ...


2

Well I think you are asking how to hide a block view completely when it is inserted as a global: view area in the header of another view. For the parent view: When inserting the block view into the header of another view, make sure you leave the box unchecked that says: Display even if view has no result For the block view that is being inserted check ...


Top 50 recent answers are included