Commit 96bd1b2e authored by Mohit Aghera's avatar Mohit Aghera
Browse files

Issue #3260258 by mohit_aghera, larowlan: Refactor "getEntitiesToView" method...

Issue #3260258 by mohit_aghera, larowlan: Refactor "getEntitiesToView" method of BackFillByTermsFormatter
parent 68f38da1
Loading
Loading
Loading
Loading

composer.json

0 → 100644
+20 −0
Original line number Diff line number Diff line
{
    "name": "drupal/backfill_formatter",
    "description": "Provides a field formatter for entity reference fields that allows back-filling values when a field is not completely populated by finding content with matching terms.",
    "type": "drupal-module",
    "homepage": "https://www.drupal.org/project/backfill_formatter",
    "authors": [
        {
            "name": "Lee Rowlands",
            "homepage": "https://www.drupal.org/u/larowlan"
        }
    ],
    "support": {
        "issues": "https://www.drupal.org/project/issues/backfill_formatter",
        "source": "http://git.drupal.org/project/backfill_formatter.git"
    },
    "license": "GPL-2.0-or-later",
    "require": {
        "drupal/taxonomy_entity_index": "^1.7"
    }
}
+14 −5
Original line number Diff line number Diff line
@@ -227,16 +227,25 @@ class BackFillByTermsFormatter extends EntityReferenceEntityFormatter {
  }

  /**
   * {@inheritdoc}
   * Get the list of all the enabled vocabularies.
   *
   * @return array
   */
  protected function getEntitiesToView(EntityReferenceFieldItemListInterface $items, $langcode) {
    $entities = parent::getEntitiesToView($items, $langcode);
    $cache = new CacheableMetadata();
    $vocabularies = array_map(function (array $item) {
  public function getVocabularies(): array {
    return array_map(function (array $item) {
      return $item['weight'];
    }, array_filter($this->getSetting('vocabularies'), function (array $item) {
      return !empty($item['enabled']);
    }));
  }

  /**
   * {@inheritdoc}
   */
  protected function getEntitiesToView(EntityReferenceFieldItemListInterface $items, $langcode) {
    $entities = parent::getEntitiesToView($items, $langcode);
    $cache = new CacheableMetadata();
    $vocabularies = $this->getVocabularies();
    $back_filled = $this->backFillTerms->backfillEntity($items->getEntity(), $entities, $this->fieldDefinition, $this->getSetting('quantity'), $vocabularies, $this->getSetting('mode'), $this->getQueryCallback($items));
    $allowed = [];
    foreach ($back_filled as $entity) {