Skip to content
Snippets Groups Projects

Issue #3252278: Computed entity reference fields cannot express cacheable metadata

Open Issue #3252278: Computed entity reference fields cannot express cacheable metadata
3 unresolved threads
Open Brad Jones requested to merge issue/drupal-3252278:3252278-jsonapi--computed into 11.x
3 unresolved threads

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
1 <?php
2
3 namespace Drupal\Core\Field;
4
5 use Drupal\Core\Cache\CacheableMetadata;
6
7 /**
8 * Interface for field item lists which have cacheable metadata for empty state.
9 *
10 * Field item lists should implement this interface when their being empty
11 * results from a condition with cacheability distinct from its parent. For
12 * instance, computed fields may change their value due to entity CRUD events
13 * orthogonal to the parent entity itself. Non-empty lists would continue to
14 * yield cacheable metadata (e.g., during serialization) via their items.
15 */
16 interface EmptyFieldItemListCacheabilityInterface {
  • 393 393 * @return string
    394 394 * The property name which has an entity as its value.
    395 395 */
    396 protected static function getDataReferencePropertyName(EntityReferenceItem $item) {
    396 public static function getDataReferencePropertyName(EntityReferenceItem $item) {
  • 35 37 $normalized_items = $this->normalizeFieldItems($field, $format, $context);
    36 38 assert($context['resource_object'] instanceof ResourceObject);
    37 39 return $context['resource_object']->getResourceType()->getFieldByInternalName($field->getName())->hasOne()
    38 ? array_shift($normalized_items) ?: CacheableNormalization::permanent(NULL)
    40 ? array_shift($normalized_items)
    41 ?: new CacheableNormalization(
    42 $field instanceof EmptyFieldItemListCacheabilityInterface
    43 ? $field->getEmptyListCacheability()
    44 : new CacheableMetadata(),
    45 NULL
    46 )
    • I understand the logic here, but i'd prefer this a little more readable than the nested tertiary consitions. A little more verbosity is fine here imo.

    • Please register or sign in to reply
  • Brad Jones added 4382 commits

    added 4382 commits

    • 323bb165...655cb760 - 4372 earlier commits
    • 01da0fd9 - Issue #3371937 by yash.rode, Abhijith S, smustgrave, fgm: Theme declaration...
    • 7b1d78a7 - Issue #3446577 by mondrake: Prepare test docblocks for annotation conversion to attributes
    • de44e097 - Issue #3446962 by kim.pepper: Remove incorrectly added...
    • 825985c4 - Allow ER fields to express cacheable metadata on properties.
    • e32f7cf8 - Fix broken copypasta
    • 2f206c12 - Don't revert recent work... oof
    • 786e6b28 - Conditional on cacheable dependency interface
    • 684b8f75 - Update for handling of empty items and only add cacheability if interface exists.
    • e59931ed - CS fix
    • 99473fc6 - Filtered field items object is still an object.

    Compare with previous version

  • Brad Jones changed the description

    changed the description

  • Brad Jones changed target branch from 9.4.x to 11.x

    changed target branch from 9.4.x to 11.x

  • Please register or sign in to reply
    Loading