You are here

class ConfigurationUpdateGenerator in Update helper 8

Same name in this branch
  1. 8 src/Generator/ConfigurationUpdateGenerator.php \Drupal\update_helper\Generator\ConfigurationUpdateGenerator
  2. 8 modules/update_helper_checklist/src/Generator/ConfigurationUpdateGenerator.php \Drupal\update_helper_checklist\Generator\ConfigurationUpdateGenerator

Update hook generator for generate:configuration:update console command.

@package Drupal\update_helper_checklist\Generator

Hierarchy

Expanded class hierarchy of ConfigurationUpdateGenerator

1 file declares its use of ConfigurationUpdateGenerator
CommandGcuSubscriber.php in modules/update_helper_checklist/src/Events/CommandGcuSubscriber.php
1 string reference to 'ConfigurationUpdateGenerator'
console.services.yml in modules/update_helper_checklist/console.services.yml
modules/update_helper_checklist/console.services.yml
1 service uses ConfigurationUpdateGenerator
update_helper_checklist.configuration_update_generator in modules/update_helper_checklist/console.services.yml
Drupal\update_helper_checklist\Generator\ConfigurationUpdateGenerator

File

modules/update_helper_checklist/src/Generator/ConfigurationUpdateGenerator.php, line 14

Namespace

Drupal\update_helper_checklist\Generator
View source
class ConfigurationUpdateGenerator extends Generator {

  /**
   * Module handler service.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Update checklist service.
   *
   * @var \Drupal\update_helper_checklist\UpdateChecklist
   */
  protected $updateChecklist;

  /**
   * AuthenticationProviderGenerator constructor.
   *
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   Extension manager.
   * @param \Drupal\update_helper_checklist\UpdateChecklist $update_checklist
   *   Update checklist service.
   */
  public function __construct(ModuleHandlerInterface $module_handler, UpdateChecklist $update_checklist) {
    $this->moduleHandler = $module_handler;
    $this->updateChecklist = $update_checklist;
  }

  /**
   * Get update hook function name.
   *
   * @param string $module_name
   *   Module name.
   * @param string $update_number
   *   Update number.
   *
   * @return string
   *   Returns update hook function name.
   */
  protected function getUpdateFunctionName($module_name, $update_number) {
    return $module_name . '_update_' . $update_number;
  }

  /**
   * Generate Checklist entry for configuration update.
   *
   * @param string $module
   *   Module name where update will be generated.
   * @param string $update_number
   *   Update number that will be used.
   * @param string $update_version
   *   Update version for module.
   * @param string $description
   *   Checklist entry title.
   * @param string $update_description
   *   Checklist update description.
   * @param string $success_message
   *   Checklist success message.
   * @param string $failure_message
   *   Checklist failed message.
   */
  public function generate($module, $update_number, $update_version, $description, $update_description, $success_message, $failure_message) {
    $module_path = $this->moduleHandler
      ->getModule($module)
      ->getPath();
    $checklist_file = $module_path . DIRECTORY_SEPARATOR . UpdateChecklist::$updateChecklistFileName;
    $update_versions = $this->updateChecklist
      ->getUpdateVersions($module);
    end($update_versions);
    $last_update_version = current($update_versions);
    $parameters = [
      'update_hook_name' => $module . '_update_' . $update_number,
      'file_exists' => file_exists($checklist_file),
      'checklist_title' => $description,
      'checklist_description' => $update_description,
      'checklist_success' => $success_message,
      'checklist_failed' => $failure_message,
      'update_version' => $update_version === $last_update_version ? '' : $update_version,
    ];
    $this
      ->renderFile('configuration_update_checklist.yml.twig', $checklist_file, $parameters, FILE_APPEND);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigurationUpdateGenerator::$moduleHandler protected property Module handler service.
ConfigurationUpdateGenerator::$updateChecklist protected property Update checklist service.
ConfigurationUpdateGenerator::generate public function Generate Checklist entry for configuration update.
ConfigurationUpdateGenerator::getUpdateFunctionName protected function Get update hook function name.
ConfigurationUpdateGenerator::__construct public function AuthenticationProviderGenerator constructor.