Problem/Motivation

When the user has no access to field content the Twig field value module produces an empty array. This is usually no problem, but when working with multiple values, this may result in unwanted behavior. For example we make a comma separated list of node labels from an entity reference field: "One, Two, Three. When node "Two" is unpublished, the list will become: "One, ,Three"

Proposed resolution

The field_value filter should retrieve the field delta from the render array of the formatter and not from the FieldItemList.

Remaining tasks

Tests. Maybe we KernelTest that has access checks.

API changes

none

Comments

webflo created an issue. See original summary.

webflo’s picture

Status: Active » Needs work
StatusFileSize
new876 bytes
webflo’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 2936194-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

webflo’s picture

Status: Needs work » Needs review
StatusFileSize
new3.08 KB
webflo’s picture

StatusFileSize
new3.94 KB

Patch + Test

Status: Needs review » Needs work

The last submitted patch, 6: 2936194-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

webflo’s picture

Status: Needs work » Needs review
StatusFileSize
new5.34 KB
sutharsan’s picture

Oh, great! I tried to add a test this afternoon but I failed.

webflo’s picture

+++ b/src/Twig/Extension/FieldValueExtension.php
@@ -61,14 +63,11 @@ class FieldValueExtension extends \Twig_Extension {
+    $elements = Element::getVisibleChildren($build);

::getVisibleChildren is not really necessary. The render api uses ::children is most cases.

sutharsan’s picture

StatusFileSize
new5.5 KB
new2.63 KB
heine’s picture

heine’s picture

Republishing on request.

sutharsan’s picture

Title: field_value filter should obey access checks from formatters » field_value filter should produce no output when access is denied
Issue summary: View changes

Updating title and issue summary to accurately describe the issue.

  • Sutharsan committed 10e51f6 on 8.x-1.x
    Issue #2936194 by webflo, Sutharsan: field_value filter should produce...
sutharsan’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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