Views Contextual filter: current path and route

Created on 7 July 2024, 2 months ago
Updated 9 August 2024, 29 days ago

Problem/Motivation

I think there should be a relationship with the entity id in the module data tables.

The visitor tab is very useful for administrators, but since it contains sensitive data such as IP or data such as ID that does not concern the normal users, we cannot open it to users. Since the tab content cannot be customized, it becomes necessary to create it with a view when there are important requirements.

I tried to create view with "Contextual filters >> Content Id >>Content ID from URL" to show data with a view block.

The goal is to create a view that will only show the entity's own visit data, but unfortunately it cannot be created because the "content-id" is not present or accessible in the contextual filters.
There may be another way or something I missed.
Any advice to filter data according to entity id in the views ?
Thanks

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @toprak
  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    Hi @toprak,

    I understand your concern about exposing data to users.

    The node report is still created with SQL queries and a table render array is constructed. Visitors created reporters this way until recently. Now, most of the reports are using views. There are a few issues left before Visitors are exclusively using views.

    Visitors still use custom Controllers to display reports. I think I will use the path as the contextual filter, create the path, e.g. node/12 in the controller, and pass it to the view. Adding a contextual filter for the entity ID is an interesting idea. I am still learning field plugins so it may be a while before I learn contextual filters.

    πŸ“Œ Replicate or replace /node/*/visitors with a view Active
    πŸ“Œ Replace visitors/referers with Views Active

  • Hi @bluegeek9,
    Thanks for reply.
    Actually I want to leave the core statistics module(deprecated in Drupal 10.3) and use visitor in most future projects.
    I know it's a different perspective but the scenario requires it. Currently, "path" way in contextual filter is not solution to filter "specific node" data in views.Since it is not filtered, all other visit data comes through as well.
    I guess I have no choice but to wait for the next updates for the scenario above...
    I am also following the related issues. If I can create a solution, I will share it.
    Thanks again.

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    I am finishing up replacing the Node report with a view. I created the path string in the Report controller and passed it to the view.

    "Content ID from URL" will return just an integer. This will not work.

    We could create a default argument plugin for the path like there is for Query parameters. It would be the current path, but the form will have the option to remove x number of items

    So 'node/10/visitors' with a 1 would filter for 'node/10'.

    A text field should be added to append to the path optionally, allowing you to filter for 'node/10/edit'.

    PS
    I added ✨ core statistics: migrate view count Active . If the Core Statistics view count could be migrated, would you move existing projects to Visitors?

  • Of course, why not. The reason for preference here is that it offers more features than the core statistic module. Maybe, there is also the concern that these features may cause performance problems compared to the core statistic module. But, I haven't encountered any problems in my current tests.

    As for ID (integer), take a look at the core statistic or node view count modules. They do a good job with ID.

    I had tried the Path&Query method before, but I tried it again. Unfortunately, it doesn't work.
    Ex : node/10/new-visits
    No result.

    Why did I mention the ID point? The reason is;
    Let's say we will filter only the data belonging to node 10.
    I embed the following view into the node twig.
    {{ drupal_view('visitors_recent_visits', 'embed_1') }} or {{ drupal_view('visitors_recent_visits', 'block_5') }}.
    Or using a view block working with path&query filter.
    I tried different filters or path and query parameters, it doesn't work.
    Or maybe I missed it.

    But if there was an ID option, I could customize the data I wanted and show it in twig, in block or with a different url..
    Anyway, I really respect your work and approach. I guess there's nothing to do. I will try to move forward with your path.

  • Assigned to bluegeek9
  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9
Production build 0.71.5 2024