Problem/Motivation

I am wondering what the key differences between those two layers are and when to use which kind.

So far I can tell that Attachment Layers can only be attached to the same view they are in whereas Data Layers can be added to widgets and formatters too. Attachment Layers can inherit exposed filters from the map they are attached to, Data Layers can not. What else?

I basically want to display point geometries in a map, filter them with an exposed filter and have the same points displayed in the widget of that content type. The only setup I can get this working is having a CommonMap as map with filtering and an extra Data Layer with the same geometry data for the widget. Ideal would be just one Data Layer. Using an Attachment Layer allows to inherit filters but I can't use it in widgets. If that's the way it is, it's fine for me, I just want to clarify I have the right understanding an don't miss something.

Comments

janc48 created an issue. See original summary.

christianadamski’s picture

Status: Active » Closed (works as designed)

Historically attachment layer came first. And it inherits by nature the filters and all from the parent. But it is bound to that view and specifically the page displays of that view.

Data Layers are universal and can be referenced from elsewhere, including maps not based on views, but that means inheriting is a bit hit and miss.

AI summary:

What still reaches it

There is no inheritance, but the layer view still runs inside the current request, so two things work:

1. Contextual filters with a default value. No arguments are passed, so Views uses each contextual filter's default value, for example "Content ID from route", "Query parameter" or "Raw value from URL". This is how you'd make a field-formatter map show "items related to this node": add a contextual filter on the layer display with the default "Content ID from route".
2. Exposed filters read from the URL query. Like any view, getExposedInput() reads $request->query. If the layer display has exposed filters, ?identifier=value on the page URL would filter it. That's just core behaviour, not something the module supports on purpose. Nothing on the page submits those values for you. I haven't checked whether the display would also render its own exposed form inside the layer.

So for your field formatter case
- If you want the layer filtered by the host entity: use a contextual filter with a route-based default value.
- If you want it to follow exposed filters from some other view on the page: that doesn't work. That's only possible with the attachment layer on a views map display, where the attachment runs as a clone of the same view on the same request.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

christianadamski’s picture

Or you can use some custom code and call a view with some arguments, if that works for you.