Problem/Motivation

The cheat sheat says

This is an opposite of core without filter.

This is incorrect and misleading, the with function (not using the phrase "filter" class here to avoid confusion) does something with a render array key, but it does not filter (remove, reduce,...) something.

Proposed resolution

Change documentation to

This filter allows to set a value in a render array.

API changes

Maybe change the function name in the next major version? It behaves like a setter, but the TwigFilter name set is already used by Components! module. Something like set_by_key?

Issue fork twig_tweak-3399652

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

hudri created an issue. See original summary.

hudri’s picture

Issue summary: View changes
hudri’s picture

Issue summary: View changes
chi’s picture

Many other Twig Tweak filters are also not filters. And Drupal core has such examples as well. Furthermore Twig itself has filters that don't filter anything. That's a historical naming convention that we can't change.

https://github.com/twigphp/Twig/issues/3298

hudri’s picture

My "filter" comment was meant in regard to the current description (the opposite of core's without), because without actually does filter a render array. I can't see the reason why with (setter) should be the opposite of without (filter)

chi’s picture

I can't see the reason why with (setter) should be the opposite of without (filter)

without removes properties
with adds properties
Isn't this what "opposite" term means?

hudri’s picture

OK, now I got the naming.

In my mental model, without is a filter by disallow list, so reading the description I thought with is a filter by safe list, and used it like content|with(computedListOfAllowedFieldnames). This did not work and resulted into the creation of this issue.

I'd suggest extending the description in the cheat sheat to

This is an opposite of core without filter and adds properties instead of removing it.

hudri’s picture

Title: with-filter does not work as described » with-filter description can be ambiguous
Component: Code » Documentation
Category: Bug report » Task
Priority: Normal » Minor
Status: Active » Needs review
shyam_bhatt’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new141.42 KB
new125.85 KB

@hudri I have checked the "MR !39", documentation updated on the "cheat-sheet.md" file.

Before:
2023-11-10/3399652-10-before.png

After:
2023-11-10/3399652-10-after.png

+ Moving to RTBC

chi’s picture

Status: Reviewed & tested by the community » Fixed

@Shyam_Bhatt no need to make screenshots for code. It only proves that you correctly deployed the Git branch to your localhost.

The change is visible here.
https://git.drupalcode.org/issue/twig_tweak-3399652/-/blob/3399652-with-...

Thank you.

Status: Fixed » Closed (fixed)

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