You are here

function tmgmt_smartling_update_8804 in TMGMT Translator Smartling 8.4

Create download by job items action plugin.

File

./tmgmt_smartling.install, line 199
Update function for the tmgmt_smartling module.

Code

function tmgmt_smartling_update_8804() {
  try {
    $plugin_id = 'tmgmt_smartling_download_by_job_items_job_action';
    $plugin_name = 'system.action.tmgmt_smartling_download_by_job_items_job_action';
    $entity_type_manager = \Drupal::entityTypeManager();
    $module_handler = \Drupal::moduleHandler();
    $config_install_path = $module_handler
      ->getModule('tmgmt_smartling')
      ->getPath() . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
    $action_storage = $entity_type_manager
      ->getStorage('action');
    $action = $action_storage
      ->load($plugin_id);

    // Create action if it doesn't exist.
    if (!$action) {
      $storage = new FileStorage($config_install_path);
      $read_file = $storage
        ->read($plugin_name);
      if ($read_file) {
        $entity_type_manager
          ->getStorage('action')
          ->create($read_file)
          ->save();
      }
    }
  } catch (Exception $e) {
    throw new UpdateException('Unable to create "tmgmt_smartling_download_by_job_items_job_action" action.');
  }
}