Problem/Motivation

Allow different icons between views rows. Differentiated by some field in the view, eg. node type.

Proposed resolution

Enable twig with fields as twig variables on the icon setting field to allow using the values from fields to define the url of the icons.

User interface changes

Icon field setting on the view will be switched from textfield to textarea to account for the longer twig expressions. And icon field setting can no longer be validate as a valid path since we can not evaluate the twig expression without values from a row.

Comments

ooystein created an issue. See original summary.

ooystein’s picture

Status: Active » Needs review
StatusFileSize
new4.73 KB

Here is a patch that enables twig on the icon fields and adds the fields as twig variables.

We should consider adding context variables to the twig variables if this is requested by anyone.

PS. This does not work when twig debugging is enabled as it includes html comments to the variables

netsliver’s picture

StatusFileSize
new6.53 KB

New patch for the latest dev version

joum’s picture

Status: Needs review » Reviewed & tested by the community

Works like a charm! Good job!

I'm using core 8.5.6 under PHP 7.2.7.

If this ends up entering the Leaflet module's core, some info on how to style the marker in depth would be nice, too.

Would it be hard to also add a className to the marker?

itamair’s picture

tnx @netsliver ... going to review this asap, also with @joum requests ... and eventually amend or commit to dev

afsch’s picture

StatusFileSize
new6.58 KB

In Drupal 8.5.6 under PHP 7.1, I got an error trying to load the Manage Display (default display). Here I added the same patch in #3 with an extra condition. This issue is related to Field Formatter.
Anyway this solution works amazing, Thanks.

afsch’s picture

StatusFileSize
new6.58 KB
shortspoken’s picture

Works as expected. Thanks everyone! :)

itamair’s picture

StatusFileSize
new7.06 KB

Thanks dudes for this contribution.
I reviewed more carefully, and some important amends were needed, in the last #7 patch both on coding standards and correct OOP implementations, and also because you didn't considered that all the changes applied into the LeafletSettingsElementsTrait would have affected (and messed up) the LeafletDefaultFormatter ... in which the Views Fields Tokens implementation wouldn't have applied/worked.

Here it is a final patch that works and that is going to be committed into dev and last new module release.

  • itamair committed f1d4ef9 on 8.x-1.x
    Issue #2803299 by alexito, ooystein, itamair, netsliver: Twig in views...
itamair’s picture

Status: Reviewed & tested by the community » Fixed
itamair’s picture

It would be nice to extend this functionality into the LeafletDefaultFormatter too ...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.