Created
December 28, 2021 13:27
-
-
Save junaidpv/3a5211deec20ae770e6d93a6a9d2c8bd to your computer and use it in GitHub Desktop.
Drush command to fix "non-existent config entity name returned by FieldStorageConfigInterface::getBundles()" errors reported at https://www.drupal.org/project/drupal/issues/2916266
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
update.commands: | |
class: \Drupal\my_module\Commands\UpdateCommands | |
arguments: | |
- '@keyvalue' | |
tags: | |
- { name: drush.command } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\my_module\Commands; | |
use Drush\Commands\DrushCommands; | |
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface; | |
/** | |
* A Drush commandfile. | |
* | |
* In addition to this file, you need a drush.services.yml | |
* in root of your module, and a composer.json file that provides the name | |
* of the services file to use. | |
* | |
* See these files for an example of injecting Drupal services: | |
* - http://git.drupalcode.org/devel/tree/src/Commands/DevelCommands.php | |
* - http://git.drupalcode.org/devel/tree/drush.services.yml | |
*/ | |
class UpdateCommands extends DrushCommands { | |
/** | |
* The key value store to use. | |
* | |
* @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface | |
*/ | |
protected $keyValueStore; | |
/** | |
* @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory | |
* The key value store to use. | |
*/ | |
public function __construct(KeyValueFactoryInterface $key_value_factory) { | |
$this->keyValueStore = $key_value_factory; | |
} | |
/** | |
* Corrects a field storage configuration. See https://www.drupal.org/project/drupal/issues/2916266 for more info | |
* | |
* @command update:correct-field-config-storage | |
* | |
* @param string $entity_type | |
* Entity type | |
* @param string $bundle | |
* Bundle name | |
* @param string $field_name | |
* Field name | |
*/ | |
public function correctFieldStorageConfig($entity_type, $bundle, $field_name) { | |
$field_map_kv_store = $this->keyValueStore->get('entity.definitions.bundle_field_map'); | |
$map = $field_map_kv_store->get($entity_type); | |
unset($map[$field_name]['bundles'][$bundle]); | |
$field_map_kv_store->set($entity_type, $map); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For those who aren't super familiar with drush commands in a module, the UpdateCommands.php file needs to be in the
src/Commands
relative to your custom module.