Support multiple, nested aliases of fields in REST exports

Created on 17 September 2020, over 4 years ago
Updated 26 February 2024, 11 months ago

Problem/Motivation

Views REST exports support for aliases only allows building a flat object for each row. Support for arbitrary nesting of fields for each row would allow for much greater flexibility.

Proposed resolution

Augment handling of aliases in data_field ViewsRow plugin, so that ::render() can generate nested arrays.

Remaining tasks

  1. Write tests

User interface changes

  • Row plugin config form: alias setting will now be alias(es), also supporting '.' syntax for nesting the value in each row.
  • Row plugin validation: error message will now provide details about proper syntax for aliases.

API changes

None

Data model changes

None

Release notes snippet

Feature request
Status

Active

Version

11.0 🔥

Component
REST 

Last updated 10 days ago

Created by

🇨🇴Colombia jedihe

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇴Colombia jedihe

    Thanks @ericpoir! I was able to fix the regular expression so the alias you mention in #9 works correctly. I'm reverting your changes so we can just rely on the regexp for all cases.

    Other improvements:

    • Added detection of alias conflicts: e.g. 'a.b' conflicts with 'a.b.c'.
    • Allowed to use '@' in an alias.
    • Fixed bug where 'a b' would be accepted as an alias.
    • Relax requirement for multiple aliases: both ", " and "," separators will be properly handled.
  • 🇨🇴Colombia jedihe

    #12 also applies on top of Drupal 9.5.3.

  • This doesn't seem to be working on the site i'm currently working on which uses Drupal 9.5.9.

    I'm getting the following error for each fields that contains dots:

    "The machine-readable name must contain only letters, numbers, dashes and underscores."

    Not sure why?

  • After upgrading our site to Drupal 10, I was getting warning saying that ${var} is now deprecated so I created the following patch to fix that.

  • 🇨🇴Colombia jedihe

    Just run a quick diff of #12 vs #16; verified that the only change was replacing e.g. "${abc}" into "{$abc}".

Production build 0.71.5 2024