You are here

function tmgmt_extension_suit_update_8008 in TMGMT Extension Suite 8.2

Same name and namespace in other branches
  1. 8.3 tmgmt_extension_suit.install \tmgmt_extension_suit_update_8008()

Delete old action configuration entities and create new ones.

File

./tmgmt_extension_suit.install, line 229
Update function for the tmgmt_extension_suit module.

Code

function tmgmt_extension_suit_update_8008() {
  $action_plugins = [
    'tmgmt_extension_suit_cancel_job_action',
    'tmgmt_extension_suit_delete_job_action',
    'tmgmt_extension_suit_download_job_action',
  ];
  try {
    $entity_type_manager = \Drupal::entityTypeManager();
    $action_storage = $entity_type_manager
      ->getStorage('action');
    foreach ($action_plugins as $action_plugin) {

      // Create new actions with proper ids.
      tmgmt_extension_suit_create_action_plugin($action_plugin, "system.action.{$action_plugin}");

      // Delete old actions with wrong ids.
      $action = $action_storage
        ->load("{$action_plugin}_id");
      if (!empty($action)) {
        $action
          ->delete();
      }
    }
  } catch (Exception $e) {
    throw new UpdateException("Error during update: {$e->getMessage()}, {$e->getTraceAsString()}.");
  }
}