Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vladdancer/65f1ad79c94649b8ba205d50c302edbd to your computer and use it in GitHub Desktop.
Save vladdancer/65f1ad79c94649b8ba205d50c302edbd to your computer and use it in GitHub Desktop.
Fix entity type after removing entity key. #drupal8 #drupal #entity #drush
<?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