class DevelGenerateCommands

Same name in this branch
  1. 5.x devel_generate/src/Commands/DevelGenerateCommands.php \Drupal\devel_generate\Commands\DevelGenerateCommands
Same name in other branches
  1. 8.x-1.x devel_generate/src/Commands/DevelGenerateCommands.php \Drupal\devel_generate\Commands\DevelGenerateCommands
  2. 4.x devel_generate/src/Commands/DevelGenerateCommands.php \Drupal\devel_generate\Commands\DevelGenerateCommands

Provide Drush commands for all the core Devel Generate plugins.

For commands that are parts of modules, Drush expects to find commandfiles in __MODULE__/src/Drush/Commands, and the namespace is Drupal/__MODULE__/Drush/Commands.

Hierarchy

  • class \Drupal\devel_generate\Drush\Commands\DevelGenerateCommands extends \Drush\Commands\DrushCommands uses \Drush\Commands\AutowireTrait

Expanded class hierarchy of DevelGenerateCommands

1 file declares its use of DevelGenerateCommands
DevelGenerateCommandsTest.php in devel_generate/tests/src/Functional/DevelGenerateCommandsTest.php

File

devel_generate/src/Drush/Commands/DevelGenerateCommands.php, line 20

Namespace

Drupal\devel_generate\Drush\Commands
View source
final class DevelGenerateCommands extends DrushCommands {
    use AutowireTrait;
    const USERS = 'devel-generate:users';
    const TERMS = 'devel-generate:terms';
    const VOCABS = 'devel-generate:vocabs';
    const MENUS = 'devel-generate:menus';
    const CONTENT = 'devel-generate:content';
    const BLOCK_CONTENT = 'devel-generate:block-content';
    const MEDIA = 'devel-generate:media';
    
    /**
     * The plugin instance.
     */
    private DevelGenerateBaseInterface $pluginInstance;
    
    /**
     * The Generate plugin parameters.
     */
    private array $parameters;
    
    /**
     * DevelGenerateCommands constructor.
     *
     * @param \Drupal\devel_generate\DevelGeneratePluginManager $manager
     *   The DevelGenerate plugin manager.
     */
    public function __construct(DevelGeneratePluginManager $manager) {
        parent::__construct();
        $this->setManager($manager);
    }
    
    /**
     * Get the DevelGenerate plugin manager.
     *
     * @return \Drupal\devel_generate\DevelGeneratePluginManager
     *   The DevelGenerate plugin manager.
     */
    public function getManager() : DevelGeneratePluginManager {
        return $this->manager;
    }
    
    /**
     * Set the DevelGenerate plugin manager.
     *
     * @param \Drupal\devel_generate\DevelGeneratePluginManager $manager
     *   The DevelGenerate plugin manager.
     */
    public function setManager(DevelGeneratePluginManager $manager) : void {
        $this->manager = $manager;
    }
    
    /**
     * Get the DevelGenerate plugin instance.
     *
     * @return \Drupal\devel_generate\DevelGenerateBaseInterface
     *   The DevelGenerate plugin instance.
     */
    public function getPluginInstance() : DevelGenerateBaseInterface {
        return $this->pluginInstance;
    }
    
    /**
     * Set the DevelGenerate plugin instance.
     *
     * @param mixed $pluginInstance
     *   The DevelGenerate plugin instance.
     */
    public function setPluginInstance(mixed $pluginInstance) : void {
        $this->pluginInstance = $pluginInstance;
    }
    
    /**
     * Get the DevelGenerate plugin parameters.
     *
     * @return array
     *   The plugin parameters.
     */
    public function getParameters() : array {
        return $this->parameters;
    }
    
    /**
     * Set the DevelGenerate plugin parameters.
     *
     * @param array $parameters
     *   The plugin parameters.
     */
    public function setParameters(array $parameters) : void {
        $this->parameters = $parameters;
    }
    
    /**
     * Create users.
     */
    public function users(int $num = 50, array $options = [
        'kill' => FALSE,
        'roles' => self::REQ,
    ]) : void {
        // @todo pass $options to the plugins.
        $this->generate();
    }
    
    /**
     * Create terms in specified vocabulary.
     */
    public function terms(int $num = 50, array $options = [
        'kill' => FALSE,
        'bundles' => self::REQ,
        'feedback' => '1000',
        'languages' => self::REQ,
        'translations' => self::REQ,
        'min-depth' => '1',
        'max-depth' => '4',
    ]) : void {
        $this->generate();
    }
    
    /**
     * Create vocabularies.
     */
    public function vocabs(int $num = 1, array $options = [
        'kill' => FALSE,
    ]) : void {
        $this->generate();
    }
    
    /**
     * Create menus.
     */
    public function menus(int $number_menus = 2, int $number_links = 50, int $max_depth = 3, int $max_width = 8, array $options = [
        'kill' => FALSE,
    ]) : void {
        $this->generate();
    }
    
    /**
     * Create content.
     */
    public function content(int $num = 50, int $max_comments = 0, array $options = [
        'kill' => FALSE,
        'bundles' => 'page,article',
        'authors' => self::REQ,
        'roles' => self::REQ,
        'feedback' => 1000,
        'skip-fields' => self::REQ,
        'base-fields' => self::REQ,
        'languages' => self::REQ,
        'translations' => self::REQ,
        'add-type-label' => FALSE,
    ]) : void {
        $this->generate();
    }
    
    /**
     * Create Block content blocks.
     */
    public function blockContent(int $num = 50, array $options = [
        'kill' => FALSE,
        'block_types' => 'basic',
        'feedback' => 1000,
        'skip-fields' => self::REQ,
        'base-fields' => self::REQ,
        'languages' => self::REQ,
        'translations' => self::REQ,
        'add-type-label' => FALSE,
        'reusable' => TRUE,
    ]) : void {
        $this->generate();
    }
    
    /**
     * Create media items.
     */
    public function media(int $num = 50, array $options = [
        'kill' => FALSE,
        'media-types' => self::REQ,
        'feedback' => 1000,
        'skip-fields' => self::REQ,
        'languages' => self::REQ,
        'base-fields' => self::REQ,
    ]) : void {
        $this->generate();
    }
    
    /**
     * The standard drush validate hook.
     *
     * @param \Consolidation\AnnotatedCommand\CommandData $commandData
     *   The data sent from the drush command.
     */
    public function validate(CommandData $commandData) : void {
        $manager = $this->manager;
        $args = $commandData->input()
            ->getArguments();
        // The command name is the first argument but we do not need this.
        array_shift($args);
        
        /** @var \Drupal\devel_generate\DevelGenerateBaseInterface $instance */
        $instance = $manager->createInstance($commandData->annotationData()
            ->get('pluginId'), []);
        $this->setPluginInstance($instance);
        $parameters = $instance->validateDrushParams($args, $commandData->input()
            ->getOptions());
        $this->setParameters($parameters);
    }
    
    /**
     * Wrapper for calling the plugin instance generate function.
     */
    public function generate() : void {
        $instance = $this->pluginInstance;
        $instance->generate($this->parameters);
    }

}

Members

Title Sort descending Modifiers Object type Summary
DevelGenerateCommands::$parameters private property The Generate plugin parameters.
DevelGenerateCommands::$pluginInstance private property The plugin instance.
DevelGenerateCommands::blockContent public function Create Block content blocks.
DevelGenerateCommands::BLOCK_CONTENT constant
DevelGenerateCommands::CONTENT constant
DevelGenerateCommands::content public function Create content.
DevelGenerateCommands::generate public function Wrapper for calling the plugin instance generate function.
DevelGenerateCommands::getManager public function Get the DevelGenerate plugin manager.
DevelGenerateCommands::getParameters public function Get the DevelGenerate plugin parameters.
DevelGenerateCommands::getPluginInstance public function Get the DevelGenerate plugin instance.
DevelGenerateCommands::MEDIA constant
DevelGenerateCommands::media public function Create media items.
DevelGenerateCommands::menus public function Create menus.
DevelGenerateCommands::MENUS constant
DevelGenerateCommands::setManager public function Set the DevelGenerate plugin manager.
DevelGenerateCommands::setParameters public function Set the DevelGenerate plugin parameters.
DevelGenerateCommands::setPluginInstance public function Set the DevelGenerate plugin instance.
DevelGenerateCommands::terms public function Create terms in specified vocabulary.
DevelGenerateCommands::TERMS constant
DevelGenerateCommands::USERS constant
DevelGenerateCommands::users public function Create users.
DevelGenerateCommands::validate public function The standard drush validate hook.
DevelGenerateCommands::VOCABS constant
DevelGenerateCommands::vocabs public function Create vocabularies.
DevelGenerateCommands::__construct public function DevelGenerateCommands constructor.