Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291302

ResourceTypes should know about their fields

$
0
0

Problem/Motivation

Resource types don't have a uniform API to extract information about their fields. That information is scattered across different services like:

  • Resource Type: contains the information about the relatable resource types for all possible fields, information about aliases, and if a field is enabled or not.
  • Resource Type Repository: computes the information stored in the resource type. This makes sense for relatable resource types because some computations can be easily shared across resource types, but not for all.
  • Entity API: all the information about fields in configuration entities is accessed at the Entity API level.
  • Field API: all the information about fields in content entities is accessed at the Field API level.

Proposed resolution

A resource type should be aware of the fields that it contains. We should think about this in terms of the specification. The spec talks about the fields of a resource type, but we don't have an easy way to get the fields of a resource type.

Introduce 3 classes:

  • ResourceTypeField: abstract base class for either attribute or relationship fields
  • ResourceTypeAttribute: concrete specialization of a ResourceTypeField for resource type attributes
  • ResourceTypeRelationship: concrete specialization of a ResourceTypeField for resource type relationships. It stores a list of the "relatable" resource types for its particular relationship. This data is currently on the ResourceType class and this issue will move it down to the field level (while preserving the internal API)

Each one of these contains information about the: entity defined field name, the field alias (aka public field), if the field is enabled or not, the field item data type (will become useful in the future*). Relationships will also contain info about the relatable resource types.

API changes

None in this issue. Consider this a refactoring of the $field_mapping argument to ResourceType::__construct() that adds additional safety and structure.

Followups will create two new methods on the ResourceType will contain two new methods (on an internal class):

  • ResourceType::getFields() -> ResourceTypeField[]
  • ResourceType::getFieldByName($alias) -> ResourceTypeField

And then add a ResourceTypeField::hasOne() method so the field "knows" whether it has cardinality > 1 or not.

For now this is only an internal refactoring, but it paves the path for #3014283: [PP-1] Use ResourceFieldInterface to statically determine the field normalizer.


Viewing all articles
Browse latest Browse all 291302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>