Verified Commit 502de2e8 authored by Andrei Mateescu's avatar Andrei Mateescu
Browse files

fix: #3045509 EntityFieldManager key/value field map gets out of sync, doesn't...

fix: #3045509 EntityFieldManager key/value field map gets out of sync, doesn't recognise bundle fields

By: catch
By: godotislate
By: crzdev
By: m.stenta
By: joachim
By: berdir
By: amateescu
parent 671d81e9
Loading
Loading
Loading
Loading
Loading
+6 −21
Original line number Diff line number Diff line
@@ -565,30 +565,15 @@ public function getFieldMap() {
                'bundles' => array_combine($bundles, $bundles),
              ];
            }
            foreach ($bundles as $bundle) {
              $fields = $this->getFieldDefinitions($entity_type_id, $bundle);
              foreach ($fields as $field_name => $field_definition) {
                $this->fieldMap[$entity_type_id][$field_name]['type'] = $field_definition->getType();
                $this->fieldMap[$entity_type_id][$field_name]['bundles'][$bundle] = $bundle;
              }
            }

        // In the second step, the per-bundle fields are added, based on the
        // persistent bundle field map stored in a key value collection. This
        // data is managed in the
        // FieldDefinitionListener::onFieldDefinitionCreate() and
        // FieldDefinitionListener::onFieldDefinitionDelete() methods.
        // Rebuilding this information in the same way as base fields would not
        // scale, as the time to query would grow exponentially with more fields
        // and bundles. A cache would be deleted during cache clears, which is
        // the only time it is needed, so a key value collection is used.
        $bundle_field_maps = $this->keyValueFactory->get('entity.definitions.bundle_field_map')->getAll();
        foreach ($bundle_field_maps as $entity_type_id => $bundle_field_map) {
          foreach ($bundle_field_map as $field_name => $map_entry) {
            if (!isset($this->fieldMap[$entity_type_id][$field_name])) {
              $this->fieldMap[$entity_type_id][$field_name] = $map_entry;
            }
            else {
              $this->fieldMap[$entity_type_id][$field_name]['bundles'] += $map_entry['bundles'];
          }
        }
        }

        $this->cacheSet($cid, $this->fieldMap, Cache::PERMANENT, ['entity_types', 'entity_field_info']);
      }
    }
+1 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ public function testSettingsUI(): void {
    ];
    $this->assertSettings('comment', 'comment_article', TRUE, $edit);
    $entity_field_manager = \Drupal::service('entity_field.manager');
    $entity_field_manager->clearCachedFieldDefinitions();
    $definition = $entity_field_manager->getFieldDefinitions('comment', 'comment_article')['comment_body'];
    $this->assertTrue($definition->isTranslatable(), 'Article comment body is translatable.');
    $definition = $entity_field_manager->getFieldDefinitions('comment', 'comment_article')['subject'];
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ public function entityBundleInfo(): array {
    $bundles = [];
    $entity_types = \Drupal::entityTypeManager()->getDefinitions();
    foreach ($entity_types as $entity_type_id => $entity_type) {
      if ($entity_type->getProvider() == 'entity_test'
      if (in_array($entity_type->getProvider(), ['entity_test', 'entity_test_update'], TRUE)
        && !in_array($entity_type_id, ['entity_test_with_bundle', 'entity_test_mul_with_bundle'], TRUE)) {
        $bundles[$entity_type_id] = \Drupal::state()->get($entity_type_id . '.bundles', [$entity_type_id => ['label' => 'Entity Test Bundle']]);
      }
+1 −1
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ public function testViewsData(): void {
    // selected by EntityFieldManagerInterface::getFieldLabels().
    $this->assertEquals('GiraffeB" label (field_string)', $data[$current_table][$field_storage_string->getName() . '_value']['title']);
    $this->assertInstanceOf(MarkupInterface::class, $data[$current_table][$field_storage_string->getName()]['help']);
    $this->assertEquals('Appears in: page, article, news. Also known as: Content: GiraffeA" label', $data[$current_table][$field_storage_string->getName()]['help']);
    $this->assertEquals('Appears in: article, page, news. Also known as: Content: GiraffeA" label', $data[$current_table][$field_storage_string->getName()]['help']);
  }

  /**
+1 −1
Original line number Diff line number Diff line
@@ -220,7 +220,7 @@ public function testHandlerHelpEscaping(): void {

    $this->drupalGet('admin/structure/views/nojs/add-handler/content/default/field');
    $this->assertSession()->assertEscaped('The <em>giraffe"</em> label <script>alert("the return of the xss")</script>');
    $this->assertSession()->assertEscaped('Appears in: page, article. Also known as: Content: The giraffe" label');
    $this->assertSession()->assertEscaped('Appears in: article, page. Also known as: Content: The giraffe" label');
  }

  /**
Loading