Clarify the notion of "main property" for a Field Type

Created on 17 May 2014, almost 11 years ago
Updated 17 March 2025, about 1 month ago

Spin off from #2267753: ContentEntityDatabaseStorage::mapToStorageRecord hard-codes $entity->$name->value β†’ :

The exact semantics of "the main property for a field type" has alawys been a bit vague. IIRC it's been initially introduced to support AllowedValuesConstraint, and has been since then used for a couple other things.

FieldItemInterface::mainPropertyName() basically only says : "Some field types consist "mainly" (whatever that means) of one main property, some others don't and then it's NULL". This doesn't help field type developpers understand what to put in their implementation of mainPropertyName() - "what's my "main property", do I even have one ?".

The exact semantics currently only lie in actual code uses :

- AllowedValuesConstraintValidator only supports field types that have a "main property" (raises an exception if NULL).
--> consequence for Field Type authors : your field type can use AllowedValuesConstraint only if it has a "main property"

- ContentEntityBase::getEntityKey() assumes all entity keys use a field type that has a "main property", and will fatal if not.
--> consequence for Entity Type authors : your "entity keys" can only use field types that have a "main property".

- EntityQuery's Tables.php uses the "main property" of fields used in a condition - not clear what happens if the field type doesn't have one.
--> consequence : ??

- #2267753: ContentEntityDatabaseStorage::mapToStorageRecord hard-codes $entity->$name->value β†’ adds : the "main property" is the one that gets stored for base fields in base tables when the table schema is designed such that there's a single column for the field, named after the field.
I guess that this use will be mostly moot when base table schemas are auto-generated ?
--> meanwhile, consequence for Entity Type authors : beware of field types when designing your base table schemas ?

We should try to convey more of that in the doc for FieldItemInterface::mainPropertyName().

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

field system

Created by

πŸ‡«πŸ‡·France yched

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

  • πŸ‡·πŸ‡΄Romania amateescu

    All the points from the issue summary are still valid, the documentation of \Drupal\Core\Field\FieldStorageDefinitionInterface::getMainPropertyName() doesn't tell developers what the consequences are if a field type has or lacks a "main property".

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thanks. Leaving the tag for stats purposes later

Production build 0.71.5 2024