Steps to reproduce:

1. Create a view
2. Add a "REST export" display
3. Select Format = Serializer and Show = Fields
4. Add a "Global: View result counter" field

When you check view results you will see counter field's value as {{ counter }}

Proposed solution:

Use render and postRender functions instead of advancedRender at https://git.drupalcode.org/project/drupal/blob/8.8.x/core/modules/rest/s...
This will allow for uncacheable fields in row level to replace placeholder by the correct value as described in
https://git.drupalcode.org/project/drupal/blob/8.8.x/core/modules/views/...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

piggito created an issue. See original summary.

piggito’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
808 bytes

Status: Needs review » Needs work

The last submitted patch, 2: 3063180-2.patch, failed testing. View results

piggito’s picture

Assigned: Unassigned » piggito
Status: Needs work » Needs review
FileSize
739 bytes
805 bytes

Trying to fix tests, new test for scenario in issue description still pending.

andypost’s picture

It miss unit test

piggito’s picture

Assigned: piggito » Unassigned
Issue tags: -Needs tests
FileSize
7.93 KB
8.83 KB
8.68 KB

I'm now including a patch introducing a new "FieldCounterTest" to proof the failing scenario described in issue summary.
Also, attaching the patch in 4 + test + an additional comment about usage of advancedRender

The last submitted patch, 6: 3063180-6-test-only.patch, failed testing. View results

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks great to go

Wim Leers’s picture

Title: View result counter shows {{counter}} placeholder when using "data_field" row plugin » REST views: View result counter shows {{counter}} placeholder when using "data_field" row plugin
Issue tags: +API-First Initiative, +VDC

Looks good!

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 06d2de1 and pushed to 8.8.x. Thanks!

  • catch committed 06d2de1 on 8.8.x
    Issue #3063180 by piggito, andypost: REST views: View result counter...

Status: Fixed » Closed (fixed)

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

SebaZ’s picture

patch #14 from Fix for global view counter works great for this issue. For me it should be fixed in core. You can use mentioned patch or just make your own plugin view field as a clone of a core Counter with change in ::render() method

public function render(ResultRow $row) {
  return $this->getValue($row);
}

Patch #6 https://www.drupal.org/project/drupal/issues/3063180#comment-13156215 do almost the same, calling ::postRender() method which do what ::render() should do.