Issue #3032451 was merged and released in 8.x-3.4. It introduces a new normaliser ResourceObjectNormalizer to apply field enhancers to config entities. However, after applying the enhancers to fields of $normalization['attributes'], it adds the fields to $normalization instead of replacing the fields in $normalization['attributes'].

  protected static function enhanceConfigFields(array $normalization, ConfigurableResourceType $resource_type) {
    if (!empty($normalization['attributes'])) {
      foreach ($normalization['attributes'] as $field_name => $field_value) {
        $enhancer = $resource_type->getFieldEnhancer($field_name);
        if (!$enhancer) {
          continue;
        }
        $normalization[$field_name] = $enhancer->undoTransform($field_value);
      }
    }
    return $normalization;
  }

enhanceConfigFields

It results in changes in JSONAPI response for config entities. For example, below is JSONAPI response for webform in 8.x-3.3 with a YAML field enhancer to the attributes.elements:

    "attributes": {
      "langcode": "en",
      "status": "open",
      "dependencies": [],
      "open": null,
      "close": null,
      "weight": 0,
      "uid": 200,
      "template": false,
      "archive": false,
      "entity_id": "pso",
      "title": "PSO",
      "description": "Checkbox form for PSO",
      "category": "form-redirect",
      "elements": {
        "pso_recruitment_process": {
          "#type": "checkbox",
          "#title": "I UNDERSTAND THE RECRUITMENT PROCESS",
          "#required": true
        }
      }
      "css": "",
      "javascript": "",
      "settings": { ... }
    },

On 8.x-3.4:

    "attributes": {
      "langcode": "en",
      "status": "open",
      "dependencies": [],
      "open": null,
      "close": null,
      "weight": 0,
      "uid": 200,
      "template": false,
      "archive": false,
      "entity_id": "pso",
      "title": "PSO",
      "description": "Checkbox form for PSO",
      "category": "form-redirect",
      "elements": "pso_recruitment_process:\n  \u0027#type\u0027: checkbox\n  \u0027#title\u0027: \u0027I UNDERSTAND THE RECRUITMENT PROCESS\u0027\n  \u0027#required\u0027: true",
      "css": "",
      "javascript": "",
      "settings": { ... }
    },
    "elements": {
      "pso_recruitment_process": {
        "#type": "checkbox",
        "#title": "I UNDERSTAND THE RECRUITMENT PROCESS",
        "#required": true
      }
    }

Is this change on purpose or a mistake?

Comments

sonnykt created an issue. See original summary.

sonnykt’s picture

Issue summary: View changes
sonnykt’s picture

sonnykt’s picture

If it's a bug, here is the patch.

e0ipso’s picture

Status: Active » Fixed

This looks good!

  • e0ipso committed 12d4243 on 8.x-3.x authored by sonnykt
    Issue #3037833 by sonnykt, e0ipso: JSON:API Extras 3.4 adds enhanced...
e0ipso’s picture

Thanks for the fix!

e0ipso’s picture

Title: JSON:API Extras 3.4 adds enhanced field values outside of attributes for Config Entities » Test coverage for config entity field enhancers
Issue tags: +Needs tests

Retitling to add test coverage. It's worrisome that no tests went red with this bug.

wim leers’s picture

Status: Fixed » Closed (fixed)

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