You are here

protected function WebformCliService::drush_webform_generate_commands_drush8 in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Commands/WebformCliService.php \Drupal\webform\Commands\WebformCliService::drush_webform_generate_commands_drush8()

Generate webform.drush.inc for Drush 8.x.

Return value

string webform.drush.inc for Drush 8.x.

See also

drush/webform.drush.inc

1 call to WebformCliService::drush_webform_generate_commands_drush8()
WebformCliService::drush_webform_generate_commands in src/Commands/WebformCliService.php
Implements drush_hook_COMMAND().

File

src/Commands/WebformCliService.php, line 1248

Class

WebformCliService
Drush version agnostic commands.

Namespace

Drupal\webform\Commands

Code

protected function drush_webform_generate_commands_drush8() {
  $items = $this
    ->webform_drush_command();
  $functions = [];
  foreach ($items as $command_key => $command_item) {

    // Command name.
    $functions[] = "\n/******************************************************************************/\n// drush {$command_key}. DO NOT EDIT.\n/******************************************************************************/";

    // Validate.
    $validate_method = 'drush_' . str_replace('-', '_', $command_key) . '_validate';
    $validate_hook = 'drush_' . str_replace('-', '_', $command_key) . '_validate';
    if (method_exists($this, $validate_method)) {
      $functions[] = "\n/**\n * Implements drush_hook_COMMAND_validate().\n */\nfunction {$validate_hook}() {\n  return call_user_func_array([\\Drupal::service('webform.cli_service'), '{$validate_method}'], func_get_args());\n}";
    }

    // Commands.
    $command_method = 'drush_' . str_replace('-', '_', $command_key);
    $command_hook = 'drush_' . str_replace('-', '_', $command_key);
    if (method_exists($this, $command_method)) {
      $functions[] = "\n/**\n * Implements drush_hook_COMMAND().\n */\nfunction {$command_hook}() {\n  return call_user_func_array([\\Drupal::service('webform.cli_service'), '{$command_method}'], func_get_args());\n}";
    }
  }

  // Build commands.
  $drush_command = $this
    ->webform_drush_command();
  foreach ($drush_command as $command_key => &$command_item) {
    $command_item += [
      'aliases' => [],
    ];
    $command_item['aliases'][] = str_replace('-', ':', $command_key);
  }
  $commands = Variable::export($drush_command);

  // Remove [datatypes] which are only needed for Drush 9.x.
  $commands = preg_replace('/\\[(boolean)\\]\\s+/', '', $commands);
  $commands = trim(preg_replace('/^/m', '  ', $commands));

  // Include.
  $functions = implode(PHP_EOL, $functions) . PHP_EOL;
  return "<?php\n\n// @codingStandardsIgnoreFile\n\n/**\n * This is file was generated using Drush. DO NOT EDIT.\n *\n * @see drush webform-generate-commands\n * @see \\Drupal\\webform\\Commands\\DrushCliServiceBase::generate_commands_drush8\n */\n\nrequire_once __DIR__ . '/webform.drush.hooks.inc';\n\n/**\n * Implements hook_drush_command().\n */\nfunction webform_drush_command() {\n  return {$commands};\n}\n{$functions}\n";
}