Skip to content
Snippets Groups Projects
Commit 256ebf39 authored by Tim Rohaly's avatar Tim Rohaly
Browse files

Merge branch '3470119-implement-autowiring-on' into '4.0.x'

Issue #3470119 by TR: Implement autowiring on Drush commands

See merge request !26
parents 912b3231 6cc1e4ff
No related branches found
No related tags found
No related merge requests found
Pipeline #263803 passed with warnings
......@@ -6,17 +6,17 @@
"license": "GPL-2.0-or-later",
"homepage": "https://www.drupal.org/project/votingapi",
"support": {
"issues": "https://drupal.org/project/issues/votingapi",
"source": "https://git.drupalcode.org/project/votingapi"
"issues": "https://drupal.org/project/issues/votingapi",
"source": "https://git.drupalcode.org/project/votingapi"
},
"require-dev": {
"drupal/token": "^1.5"
"drupal/token": "^1.5"
},
"minimum-stability": "dev",
"extra": {
"drush": {
"services": {
"drush.services.yml": ">=9"
"drush.services.yml": ">=12"
}
}
}
......
......@@ -8,8 +8,8 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\votingapi\Entity\Vote;
use Drupal\votingapi\VoteResultFunctionManager;
use Drush\Attributes as CLI;
use Drush\Commands\AutowireTrait;
use Drush\Commands\DrushCommands;
use Symfony\Component\DependencyInjection\ContainerInterface;
// cspell:ignore genv vcalc vflush vtype etype resultfunction
......@@ -20,64 +20,27 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* flushes Voting API data entirely.
*/
class VotingApiDrushCommands extends DrushCommands {
use AutowireTrait;
/**
* The datetime.time service.
* Constructs the VotingApiDrushCommands object.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $timeService;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The vote result function manager.
*
* @var \Drupal\votingapi\VoteResultFunctionManager
*/
protected $voteResultFunctionManager;
/**
* Constructs an object.
*
* @param \Drupal\Component\Datetime\TimeInterface $time_service
* @param \Drupal\Component\Datetime\TimeInterface $timeService
* The datetime.time service.
* @param \Drupal\Core\Database\Connection $database
* The database connection.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\votingapi\VoteResultFunctionManager $vote_result_function_manager
* The vote result function manager.
*/
public function __construct(TimeInterface $time_service, Connection $database, EntityTypeManagerInterface $entity_type_manager, VoteResultFunctionManager $vote_result_function_manager) {
$this->timeService = $time_service;
$this->database = $database;
$this->entityTypeManager = $entity_type_manager;
$this->voteResultFunctionManager = $vote_result_function_manager;
}
/**
* {@inheritdoc}
* The database service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity_type.manager service.
* @param \Drupal\votingapi\VoteResultFunctionManager $voteResultFunctionManager
* The plugin.manager.votingapi.resultfunction service.
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('datetime.time'),
$container->get('database'),
$container->get('entity_type.manager'),
$container->get('plugin.manager.votingapi.resultfunction')
);
public function __construct(
protected TimeInterface $timeService,
protected Connection $database,
protected EntityTypeManagerInterface $entityTypeManager,
protected VoteResultFunctionManager $voteResultFunctionManager,
) {
parent::__construct();
}
/**
......@@ -88,8 +51,7 @@ class VotingApiDrushCommands extends DrushCommands {
* @param string $vote_type
* The type of votes to generate, defaults to 'percent'.
* @param array $options
* An associative array of options whose values come from cli, aliases,
* config, etc.
* An associative array of options.
*
* @command voting:generate
* @aliases genv,generate-votes
......@@ -100,7 +62,7 @@ class VotingApiDrushCommands extends DrushCommands {
* @option age
* The maximum age, in seconds, of each vote.
* @option node_types
* A comma delimited list of node types to generate votes for, if the entity
* A comma-delimited list of node types to generate votes for, if the entity
* type is 'node'.
*
* @usage drush voting:generate [entity_type]
......@@ -221,8 +183,7 @@ class VotingApiDrushCommands extends DrushCommands {
* @param string $vote_type
* The type of votes to generate, defaults to 'percent'.
* @param array $options
* An associative array of options whose values come from cli, aliases,
* config, etc.
* An associative array of options.
*/
protected function generateVotes(string $entity_type = 'node', string $vote_type = 'percent', array $options = []): void {
$options += [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment