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 ;)

CommentFileSizeAuthor
#3 3525775-3.patch1.65 KBduaelfr
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

duaelfr created an issue. See original summary.

duaelfr’s picture

Assigned: duaelfr » Unassigned
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.65 KB

There is a proposal.
Patch attached for composer.

pdureau’s picture

Assigned: Unassigned » just_like_good_vibes

Hi Mikael, I know you are busy but it is part of your initial scope. Don't hesitate to assign to Christian if necessary.

duaelfr’s picture

(Sorry for the above commits. It was a rebase mistake.)

pdureau’s picture

Title: [2.0.x] Cannot use computed entity reference bundle field in a component » [2.0.5] Cannot use computed entity reference bundle field in a component

just_like_good_vibes made their first commit to this issue’s fork.

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » Unassigned
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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