Score:2

how to extend existing drush command class

fr flag

Can anyone please let me know how to extend existing drush command class.

I am writing a custom module which provides custom content entity and created a devel generate plugin similar to ContentDevelGenerate.

It is working as expected to generate dummy content from UI . I would like to create a drush command as well for the devel generator plugin. Similar to DevelGenerateCommands content method I would like to add additional method to generate my custom content entity.

My drush command class as follows :

<?php

namespace Drupal\omdb_api\Commands;

use Drupal\devel_generate\Commands\DevelGenerateCommands;

/**
 * Class to create omdb api entity drush commands.
 */
class OmdbApiEntityDevelGenerateCommands extends DevelGenerateCommands {

  /**
   * Create omdb api entity items by drush command.
   *
   * @command devel-generate:omdb-api
   * @aliases dgen:omdb-api, devel-generate-omdb-api
   * @pluginId omdb_api_entity_devel_generate
   * @validate-module-enabled omdb_api
   *
   * @param int $num
   *   Number of omdb api entity items to generate.
   * @param array $options
   *   Array of options as described below.
   *
   * @option kill Delete all omdb api entity items before generating new omdb api entity.
   * @option feedback An integer representing interval for insertion rate logging.
   * @option skip-fields A comma delimited list of fields to omit when generating random values.
   * @option languages A comma-separated list of language codes
   */
  public function omdbApiEntities($num = 50, array $options = ['kill' => FALSE, 'feedback' => 1000]) {
    $this->generate();
  }

  /**
   * Wrapper for calling the plugin instance generate function.
   */
  public function generate() {
    $instance = $this->getPluginInstance();
    $instance->generate($this->getParameters());
  }

}

OmdbApiEntityDevelGenerateCommands If i paste this method directly in DevelGenerateCommands class, command is working as expected. So it seems I am missing something to extend the DevelGenerateCommands class.

# drush.services.yml
services:
  omdb_api.devel_generate_commands:
    class: \Drupal\omdb_api\Commands\OmdbApiEntityDevelGenerateCommands
    tags:
      - { name: develgenerate.command }
Score:2
fr flag

In order to fix the issue I need to update my drush.services.yml as below :

services:
  omdb_api.devel_generate_commands:
    class: \Drupal\omdb_api\Commands\OmdbApiEntityDevelGenerateCommands
    arguments: ['@plugin.manager.develgenerate']
    tags:
      -  { name: drush.command }
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.