You are here

public function ConfigActionsService::importAction in Config Actions 8

Process a specific action id from a given module

Parameters

string $module_name:

string $action_id: if empty, process all actions in the module. Nested actions can be separated with a colon, such as "action:subaction"

string $file: if empty, process all actions files in the module. Otherwise only process actions in the named file. Just the file, not the path. The .yml extension is optional, but you cannot reference non *.yml files.

array $variables: list of action variables to override imported behavior.

Return value

mixed Returns data imported or NULL if nothing was found. Data is keyed by the name of the action file that was found.

Overrides ConfigActionsServiceInterface::importAction

File

src/ConfigActionsService.php, line 353

Class

ConfigActionsService
Base class for config_actions plugins.

Namespace

Drupal\config_actions

Code

public function importAction($module_name, $action_id = '', $file = '', $variables = []) {
  $result = [];

  // Remove optional .yml extension.
  $file = str_replace('.yml', '', $file);

  // Get list of all action files within the module to loop over.
  $files = $this
    ->getConfigActionsFiles($module_name);
  foreach ($files as $action_file) {
    if (empty($file) || $file === $action_file['file']) {
      $actions = $this
        ->readActions($action_file['path']);

      // Rebase so any includes look in the specified module.
      $actions['module'] = !empty($actions['module']) ? $actions['module'] : $action_file['module'];
      $actions['base'] = DRUPAL_ROOT . '/' . drupal_get_path('module', $actions['module']);

      // Use file key as default source.
      $actions['source'] = !empty($actions['source']) ? $actions['source'] : $action_file['file'];

      // Prevent auto:false actions from running if not given a file or
      // specific action id.
      $this
        ->autoExecute(empty($file) && empty($action_id));
      $result[$action_file['file']] = $this
        ->processAction($actions, $variables, $action_id);
    }
  }
  return $result;
}