You are here

function lingotek_update_8210 in Lingotek Translation 8.2

Install needed actions if action module and lingotek are enabled.

File

./lingotek.install, line 586
Install, update and uninstall functions for the Lingotek module.

Code

function lingotek_update_8210() {
  if (!\Drupal::moduleHandler()
    ->moduleExists('action')) {
    return;
  }
  $actions = [
    'entity:lingotek_upload_action',
    'entity:lingotek_check_upload_action',
    'entity:lingotek_request_translations_action',
    'entity:lingotek_check_translations_action',
    'entity:lingotek_download_translations_action',
    'entity:lingotek_disassociate_action',
  ];
  $enabled_entity_types = \Drupal::service('lingotek.configuration')
    ->getEnabledEntityTypes();
  foreach ($enabled_entity_types as $entity_type_id => $entity_type) {
    foreach ($actions as $action) {
      $pluginId = $action . ':' . $entity_type_id;

      /** @var \Drupal\Component\Plugin\Definition\PluginDefinitionInterface $plugin */
      $plugin = \Drupal::service('plugin.manager.action')
        ->getDefinition($pluginId);
      $action_id = $entity_type_id . '_' . str_replace('entity:', '', $action);
      Action::create([
        'id' => $action_id,
        'label' => $plugin['label'],
        'type' => $entity_type_id,
        'plugin' => $pluginId,
        'configuration' => [],
      ])
        ->save();
    }
  }
}