Last active
October 9, 2020 22:14
-
-
Save vladdancer/65f1ad79c94649b8ba205d50c302edbd to your computer and use it in GitHub Desktop.
Fix entity type after removing entity key. #drupal8 #drupal #entity #drush
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 | |
/** | |
* For the details see https://www.drupal.org/project/drupal/issues/3058082 | |
* Run with: | |
* `drush scr fix_entity_type_after_removing_entity_key.drush entity_type -- YOUR_ENTITY_TYPE_NAME entity_key -- KEY_TO_REMOVE` | |
* How to run php script with Drush on Drupal see `drush scr --help`. | |
*/ | |
if ($extra[0] !== 'entity_type' || !isset($extra[1])) { | |
print "You should provide 'entity_type' argument\n"; | |
return; | |
} | |
if ($extra[2] !== 'entity_key' || !isset($extra[3])) { | |
print "You should provide 'entity_key' argument\n"; | |
return; | |
} | |
$entity_name = $extra[1]; | |
$entity_key = $extra[3]; | |
$repo = \Drupal::service('entity.last_installed_schema.repository'); | |
$entity_type = $repo->getLastInstalledDefinition($entity_name); | |
var_dump($entity_type); | |
$keys = $entity_type->getKeys(); | |
unset($keys[$entity_key]); | |
$entity_type->set('entity_keys', $keys); | |
$repo->setLastInstalledDefinition($entity_type); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment