n How to fix "non-existent config entity name" in Drupal 8 & 9 | CodimTh

Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

How to fix "non-existent config entity name returned by FieldStorageConfigInterface::getBundles()" in Drupal 8 & 9

 

Code snippet that can be used to fix "non-existent config entity name returned by FieldStorageConfigInterface::getBundles()" in Drupal 8 & 9

Example of issue:

views throws warnings similar to "A non-existent config entity name returned by FieldStorageConfigInterface::getBundles(): field name: field_dates, bundle: page" for fields that are in the entity bundle field field map that no longer exist on the site. We had a handful of these fields which threw warnings on every cache clear. To fix this, simply add an update hook which clears out these stale fields from the entity.definitions.bundle_field_map keyvalue collection:

 

/**
 * Fix entity.definitions.bundle_field_map key store with old bundles.
 */
function my_module_update_8001() {

  /** @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory */
  $key_value_factory = \Drupal::service('keyvalue');

  $field_map_kv_store = $key_value_factory->get('entity.definitions.bundle_field_map');

  $node_map = $field_map_kv_store->get('node');
 
 // Remove the field_dates field from the bundle field map for the page bundle.
  unset($node_map['field_dates']['bundles']['page']);

  $field_map_kv_store->set('node', $node_map);
}

 

Example 2

 

/**
 * Fix entity.definitions.bundle_field_map key store with old bundles.
 */
function my_module_update_8001() {
  /** @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory */
  $key_value_factory = \Drupal::service('keyvalue');
  $field_map_kv_store = $key_value_factory->get('entity.definitions.bundle_field_map');
  $node_map = $field_map_kv_store->get('node');
  // Remove the field_dates field from the bundle field map for the page bundle.
  unset($node_map['field_dates']['bundles']['page']);
  $field_map_kv_store->set('node', $node_map);
}

 

Example 3:

function my_module_update_8002() {
    $entity_type = 'node';
    $bundle = 'article';
    $field_name = 'field_description';

    /** @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory */
    $key_value_factory = \Drupal::service('keyvalue');
    
    $field_map_kv_store = $key_value_factory->get('entity.definitions.bundle_field_map');

    $map = $field_map_kv_store->get($entity_type);

    // Remove the field_fpimage field from the bundle gallery_assist for the page bundle.
    unset($map[$field_name]['bundles'][$bundle]);

    $field_map_kv_store->set($entity_type, $map);

}

 

Example for comment entity. I have this error when migrate d7 to d8:

A non-existent config entity name returned by FieldStorageConfigInterface::getBundles(): entity type: comment, bundle: comment_node_schools_and_colleges, field name: comment_body

 

function my_module_update_8001() {
  /** @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory */
  $key_value_factory = \Drupal::service('keyvalue');
  $field_map_kv_store = $key_value_factory->get('entity.definitions.bundle_field_map');
  $comment_map = $field_map_kv_store->get('comment');
  // Remove the field_dates field from the bundle field map for the page bundle.
  unset($comment_map['comment_body']['bundles']['comment_node_schools_and_colleges']);
  $field_map_kv_store->set('comment', $comment_map);
}

 

Example for Commerce Product entity.:

entity type : commerce_product, bundle: product, field name : field_deadline
entity type : commerce_product, bundle: product, field name : commerce_stock_override
entity type : commerce_product, bundle: product, field name : commerce_stock

function my_module_update_8001() {
  /** @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory */
  $key_value_factory = \Drupal::service('keyvalue');
  $field_map_kv_store = $key_value_factory->get('entity.definitions.bundle_field_map');
  $node_map = $field_map_kv_store->get('commerce_product');
  
  // Remove the field_deadline field from the bundle field map for the page bundle.
  unset($node_map['field_deadline']['bundles']['product]);
  
   // Remove the commerce_stock_override field from the bundle field map for the page bundle.
  unset($node_map['commerce_stock_override']['bundles']['product']);
  
   // Remove the commerce_stock field from the bundle field map for the page bundle.
  unset($node_map['commerce_stock']['bundles']['product']);
  
  $field_map_kv_store->set('node', $node_map);
}

 

Example with Paragraph module:

function my_module_update_8001() {
  ## Fixes:
  ## A non-existent config entity name returned by FieldStorageConfigInterface::getBundles(): entity type: paragraph, bundle: text, field name: field_image
  $entity_type = 'paragraph';
  $bundle = 'text';
  $field_name = 'field_image';

  /** @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory */
  $key_value_factory = \Drupal::service('keyvalue');
  $field_map_kv_store = $key_value_factory->get('entity.definitions.bundle_field_map');
  $map = $field_map_kv_store->get($entity_type);
  // Remove the field_dates field from the bundle field map for the page bundle.
  unset($map[$field_name]['bundles'][$bundle]);
  $field_map_kv_store->set($entity_type, $map);
}

 

After that, just you need to enable the module, and call the /update.php, clean the cache and now the error is gone.

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook