Hot answers tagged

6

There are 2 ways to do this, but you should do this the Drupal way. You can use JavaScript to iterate through each <tr> adding a class to the <tr> if it finds finished in the last column. You can do it the Drupal way in views. I assume you are using the table view to output your data since that's what you are showing us. Under your edit view ...


6

Go to /admin/config/development/configuration/single/export and export the .yml file for that view, manually delete the flag_id filter section, and reimport the .yml file under "Single Item", that should fix it.


5

I can't help with the PHP filter and I don't think it is safe to use it in D8 by looking at the project's page. There are better solutions. You could for example add a Views Reference Field to the block type or use Twig Tweak in a template. You can also try to embed the View in the WYSIWYG text area, which is a bit more work to set up, but then should give ...


5

In short: field_data_body is the current body data. field_revision_body is a historic backup, that you can revert to if necessary. Detailed explanation of revision: Drupal lets you create a new revision every time a node is updated. This allows you to track how the node has changed over time on your site. To enable this feature you go to the ...


4

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'...


4

If you don't set a variables key for a theme hook implementation, the system defaults to expecting a render element. It appears your theme hook doesn't require either of those, so you can fix it by setting an empty array for variables. You can change this: function site_core_theme() { return [ 'site_search_block' => [ 'template' => 'site-...


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 ...


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-&...


4

For the current node ID try this token: [current-page:url:unaliased:args:value:1] See http://www.drupal.org/node/1360922


4

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 ...


4

Remove quotes. Remove wiggly brackets around. Surround image_responsive_style by quote. responsive=true Should passed as object: {{ drupal_image(uri , 'image_responsive_style', {responsive: true}) }}


4

You can not get the value of field directly from row result. You can get it by accessing to the entity like the following: Option1 foreach ($view->result as $id => $result) { $node = $result->_entity; // Get the full name value. $name = $node->get('field_user_full_name')->value; // check the result output for testing ...


3

The plugin was missing the proper annotation (added now in the question). Views plugins use Annotation Discovery. Adding something like the following solved the problem: /** * My custom serializer * * @ViewsStyle( * id = "hindi_custom_serializer", * title = @Translation("Hindi Custom Serializer"), * help = @Translation("Serializes views row ...


3

UPDATE As discussed here, this issue was caused by some missconfiguration at view level and normally should not occur. Read the full post to get the full picture on how you can step on this error. ORIGINAL ANSWER I'm adding my findings as answer since comments have limitations both on styles and length, but by all means THIS IS NOT an actual answer to the ...


3

In the view fields search for "Link to content", add the field, exclude this from presentation and move it to the top, and now you can use: {% if body|render|trim is not empty %} {{ view_node }} {% else %} {{ title }} {% endif %}


3

Nodes are rendered only once per view mode and then are cached. So the easiest solution would be to configure different view modes. Which makes sense in this case, these are in fact two different displays of the same node. Another benefit, you don't need this hook, because view modes have theme suggestions out-of-the-box.


3

This is a display which can be embedded via views_embed_view() or drupal_view() of Twig Tweak. You can embed other display types, too, for example Page or Block, but the first one generates a route and the second one a block derivate you see when adding blocks to the block layout. So Embed is basically a display type which does nothing until you embed it in ...


3

Depends if you need OR or AND clause : $view->setArguments(array('23,46')); $view->setArguments(array('23+46')); One string for each argument.


3

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: { "...


3

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:...


3

Following example unsets the filter average when user is NOT administrator, you can modify it to your specific case. use Drupal\Core\Form\FormStateInterface; function my_modulename_form_alter(&$form, FormStateInterface $form_state, $form_id){ $roles = \Drupal::currentUser()->getRoles(); $is_user_admin = in_array("administrator", $roles); $...


3

Considering the first option, it is simple : add a contextual filter of type "ID: Content" with the following configuration : WHEN THE FILTER VALUE IS NOT AVAILABLE > provide a default value > content id from url Go all the way down in the "more" section, expand it and check "exclude". Then click apply And save the views That's it !


2

Entity reference fields store the ID of the referenced entity. They don't store anything else about the referenced entity. You have an Entity reference towards nodes and the data that the ER field stores is the node ID. That is why when you add a filter for that ER field you get the "number" options, because the ID is a number/integer. But there is a way ...


2

It took me a while to find out how to do it in Drupal 8, and since this post is one of the first google hits I'll add the solution here: function MODULE_form_node_NODETYPE_alter(&$form, FormStateInterface $form_state, $form_id) { ... $form['my_embedded_view'] = [ '#type' => 'view', '#name' => 'my_view_name', '#...


2

You do not have to write any code to achieve that. Just go to the views edit page, add a contextual filter named as Has taxonomy term ID and select Provide default value, see screenshot for more options However, you can also do it pragmatically function HOOK_views_query_alter($view, $query) { $term = menu_get_object('taxonomy_term', 2); if ($term &...


2

You don't need additional modules to create different Taxonomy term pages, in D7 nor D8. Taxonomy Display and Taxonomy Views Integrator modules save steps in certain cases, but you can recreate their functionality with configuring different Views for different cases. You can reuse the existing Taxonomy term Views (this lists nodes based on the taxonomy ...


2

Exposed filters do create/update the page URL. You can construct a link with a combination of values for your Exposed filters and the Views results will react to it by displaying the "correct" results narrowed down to what is set in the URL. The confusion you're having is the Ajax option. Ajax (asynchronous JavaScript and XML) option fetches only a ...


2

I think this is what you are looking for. https://www.drupal.org/project/view_mode_page It will create viewable routes for view modes. Check the examples and readme. They will display on the page the way they are configured to display from the backend.


2

hook_schema() is only used to return a structured array representing your module's database tables. You can't execute a query from it. Well, you physically can, but you shouldn't. Since hook_schema() is used on install, your code to create the View should be in hook_install(), and the code to remove it should be in hook_uninstall()


Only top voted, non community-wiki answers of a minimum length are eligible