[2.0.x] Cannot use computed entity reference bundle field in a component

Created on 21 May 2025, 2 months ago

Problem/Motivation

Drupal allows to declare computed fields per bundle using the @hook_entity_bundle_field_info@.
For example:

/**
 * Implements hook_entity_bundle_field_info().
 */
function mymodule_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
  $computed_fields = [];
  if ($entity_type->id() === 'node') {
    if ($bundle === 'production') {
      $computed_fields['prod_all_pictures'] = BaseFieldDefinition::create('entity_reference')
        ->setLabel('Toutes les images')
        ->setComputed(TRUE)
        ->setTranslatable(FALSE)
        ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
        ->setSetting('target_type', 'media')
        ->setClass('\Drupal\mymodule\Plugin\ComputedField\ProductionPictures')
        ->setDisplayConfigurable('view', TRUE);
    }
  }
  return $computed_fields;
}

A field declared this way cannot be used in components because the @\Drupal\ui_patterns\Plugin\Derivative\EntityReferenceFieldPropertyDerivableContextDeriver@ deriver does not implement the @getDerivativeDefinitionsForEntityBundleField()@ method to handle those.

Proposed resolution

Implement the method ;)

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France duaelfr Montpellier, France

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024