hook_entity_base_field_info() implementations should not be able to override base fields: throw helpful exception

Created on 20 September 2022, about 2 years ago
Updated 20 February 2023, almost 2 years ago

Problem/Motivation

You can override predefined properties ('languages' for example) using new base field definitions.

Steps to reproduce

  • Create a new content entity type.
  • Add a new field with a predefined key.
    $fields["languages"] = BaseFieldDefinition::create('string_long')
      ->setRequired(self::requiredSection('languages'))
      ->setLabel("Languages");
  • In the function 'getLanguages', $this->languages will be overridden.
  • This issue might be reproducible using base_field_alter hook.

    Proposed resolution

    Simply prevent adding fields like these by checking their keys, and throw and exception if one of them matches a predefined property. We should do this because errors like these are extremely silent and can cause other issues. This is tested with $this->languages property.

    πŸ“Œ Task
    Status

    Needs work

    Version

    10.1 ✨

    Component
    EntityΒ  β†’

    Last updated about 4 hours ago

    Created by

    πŸ‡―πŸ‡΄Jordan yahyaalhamad Palestine

    Live updates comments and jobs are added and updated live.
    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

      This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

      Deprecation doesn't follow the standard template. Should link to a change record.

      Also needs a simple test checking for deprecation call.

    Production build 0.71.5 2024