Problem/Motivation

We want to have entity level resources, so we can provide entity listings that are not segregated by bundle. This is specially interesting for decoupled administrative listings.

Proposed resolution

Have the normalizer to provide an output that contains only the entity field and the base fields. We want to have the lowest common denominator for what an entity schema looks like. By setting a flag in the context when serializing the entity we can avoid having the fields that are tied to the bundles. We can set that flag as an option in the route definition.

Important

This feature was reverted in #2755025: [CLEANUP] Refactor relationships to have a unified base class

Comments

e0ipso created an issue. See original summary.

e0ipso’s picture

e0ipso’s picture

Issue summary: View changes
dawehner’s picture

Is it against JSONAPI to have more content than the schema defines? I mean there are usecases like site to site synchronizations where you might want to have a resource which just exposes every available item to full degree.

e0ipso’s picture

@dawehner one of the things that I'm really considering is adding a Drupal specific link & relationship to the bundle level resource. Then you can do an include of the bundle specific resource. Something like:

{
  "data": {
    "type": "node",
    "id": "1234-asd12-1234",
    "attributes": {
    	"nid": "45",
    	…
    },
    "relationships": {
    	"type": {"type": "node_type--node_type", "id": "article"},
    	…
    	"_bundle_object": {"type": "node--article", "id": "1234-asd12-1234"},
    }
  },
  "links": {
  	"self": "…",
  	"bundle": "/node--article/1234-asd12-1234"
  },
  "included": [
  	{
  		  "data": {
		    "type": "node--article",
		    "id": "1234-asd12-1234",
		    "attributes": {
		    	"nid": "45",
		    	// Includes bundle specific fields
		    	…
		    },
		    "relationships": {
		    	"type": {"type": "node_type--node_type", "id": "article"},
		    	…
		    }
		  }

  	}
  ]
}

That way we can have it both ways. What do you think?

e0ipso’s picture

Status: Active » Needs review
StatusFileSize
new24.35 KB

This patch creates the /node/4 resource. That resource will only have the data present in all the nodes, nothing specific to the actual bundle. We need a follow up to access all the fields in the bundle as a relationship.

Status: Needs review » Needs work

The last submitted patch, 6: 2751527--entity-resources--6.patch, failed testing.

The last submitted patch, 6: 2751527--entity-resources--6.patch, failed testing.

e0ipso’s picture

e0ipso’s picture

Status: Needs work » Needs review
StatusFileSize
new13.52 KB

Re-roll

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Nice idea!

  • e0ipso committed 211dfb7 on 8.x-1.x
    Issue #2751527 by e0ipso: [FEATURE] Create entity level resources
    
e0ipso’s picture

Status: Reviewed & tested by the community » Fixed
e0ipso’s picture

Status: Fixed » Closed (fixed)

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