Command "subentity" is not defined.

Created on 11 January 2024, 11 months ago
Updated 31 January 2024, 10 months ago

Command "subentity" is not defined

when I execute

drush generate subentity

I have this when a Drush 12 & Drupal 10.2.x

💬 Support request
Status

Fixed

Version

2.0

Component

Code

Created by

🇫🇷France Nicolas S. Lyon, France

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Nicolas S.
  • 🇫🇷France Nicolas S. Lyon, France

    I test this code but it seems not ok

    diff --git a/www/modules/contrib/subentity/composer.json b/www/modules/contrib/subentity/composer.json
    index 732579a83..6f6bf80ac 100644
    --- a/www/modules/contrib/subentity/composer.json
    +++ b/www/modules/contrib/subentity/composer.json
    @@ -8,6 +8,6 @@
             "drupal/core": "^9 || ^10"
         },
         "conflict": {
    -        "drush/drush": "<11"
    +        "drush/drush": "<12"
         }
     }
    diff --git a/www/modules/contrib/subentity/src/Generators/Entity/SubEntityGenerator.php b/www/modules/contrib/subentity/src/Generators/Entity/SubEntityGenerator.php
    index 635306a2a..a537300ee 100644
    --- a/www/modules/contrib/subentity/src/Generators/Entity/SubEntityGenerator.php
    +++ b/www/modules/contrib/subentity/src/Generators/Entity/SubEntityGenerator.php
    @@ -2,77 +2,71 @@
     
     namespace Drupal\subentity\Generators\Entity;
     
    -use DrupalCodeGenerator\Command\ModuleGenerator;
    +use DrupalCodeGenerator\Asset\AssetCollection;
    +use DrupalCodeGenerator\Attribute\Generator;
    +use DrupalCodeGenerator\Command\BaseGenerator;
     use DrupalCodeGenerator\Utils;
     
    +#[Generator(
    +  name: 'entity:subentity',
    +  description: 'Generates a subentity.',
    +  aliases: ['subentity'],
    +  templatePath:  __DIR__ . '/../../../templates/',
    +)]
     /**
      * Implements subentity command.
      */
    -final class SubEntityGenerator extends ModuleGenerator {
    +final class SubEntityGenerator extends BaseGenerator {
     
       /**
        * {@inheritdoc}
        */
    -  protected string $name = 'entity:subentity';
    +  protected function generate(array &$vars, AssetCollection $assets): void {
    +    $ir = $this->createInterviewer($vars);
     
    -  /**
    -   * {@inheritdoc}
    -   */
    -  protected string $alias = 'subentity';
    -
    -  /**
    -   * {@inheritdoc}
    -   */
    -  protected string $description = 'Generates a subentity.';
    -
    -  /**
    -   * {@inheritdoc}
    -   */
    -  protected string $templatePath = __DIR__ . '/../../../templates/';
    -
    -  /**
    -   * {@inheritdoc}
    -   */
    -  protected function generate(array &$vars): void {
    -    $this->collectDefault($vars);
    -
    -    $vars['label'] = $this->ask('Entity label', '{name}');
    -    $vars['entity_class'] = $this->ask('Class name', '{label|camelize}');
    -    $vars['bundle'] = $this->confirm('Has bundle?', FALSE);
    +    $vars['label'] = $ir->ask('Entity label', '{name}');
    +    $vars['entity_class'] = $ir->ask('Class name', '{label|camelize}');
    +    $vars['bundle'] = $ir->confirm('Has bundle?', FALSE);
         $vars['entity_name'] = Utils::human2machine($vars['entity_class']);
     
    -    $this->addFile(
    -      'src/Entity/{entity_class}.php',
    -      'generator/subentity.php.twig'
    -    );
    -
    -    $this->addFile(
    -      '{machine_name}.links.menu.yml',
    -      'generator/links.menu.yml.twig'
    -    )->prependIfExists();
    -
    -    $this->addFile(
    -      '{machine_name}.links.task.yml',
    -      'generator/links.task.yml.twig'
    -    )->prependIfExists();
    +    if ($vars['entity_class']) {
    +      $assets->addFile(
    +        'src/Entity/{entity_class}.php',
    +        'generator/subentity.php.twig'
    +      );
    +    }
     
    -    $this->addFile(
    -      '{machine_name}.routing.yml',
    -      'generator/routing.yml.twig'
    -    )->prependIfExists();
    +    if ($vars['machine_name']) {
    +      $assets->addFile(
    +        '{machine_name}.links.menu.yml',
    +        'generator/links.menu.yml.twig'
    +      )->prependIfExists();
    +
    +      $assets->addFile(
    +        '{machine_name}.links.task.yml',
    +        'generator/links.task.yml.twig'
    +      )->prependIfExists();
    +
    +      $assets->addFile(
    +        '{machine_name}.routing.yml',
    +        'generator/routing.yml.twig'
    +      )->prependIfExists();
    +    }
     
    -    if ($vars['bundle']) {
    -      $this->addFile(
    +    if ($vars['entity_class']) {
    +      $assets->addFile(
             'src/Entity/{entity_class}Type.php',
             'generator/subentity_type.php.twig'
           );
     
    -      $this->addFile(
    +      $assets->addFile(
             'config/schema/{entity_name}_type.yml',
             'generator/subentity_type.schema.yml'
           );
    +    }
     
    -      $this->addFile(
    +    if ($vars['machine_name']) {
    +      $assets->addFile(
             '{machine_name}.links.action.yml',
             'generator/links.action.yml.twig'
           );
    
  • 🇫🇷France MacSim

    Drush 12 now requires the commands to be stored in src/Drush/Commands and extend DrushCommands

    We need to keep the existing files to ensure we still have a Drush11- compatibility and add new files for Drush12+

  • Status changed to Postponed 10 months ago
  • 🇫🇷France anfor

    Hi Nicolas,

    The subentity module is not compatible with Drush 12, at version 2.x.

    You can either wait for a release on the 3.x branch or downgrade to drush 11 on your project.

    Regards,

  • First commit to issue fork.
  • 🇫🇷France Nicolas S. Lyon, France

    Hi @anfor,

    I'm according to you but my project, it is in Drupal 10.2.x et we are a conflict with drush < 12.4.1 (https://packagist.org/packages/drupal/core)

    So, I can't create a subentity with 2.x and Drupal 10.2.x/Drush 12.x

  • Status changed to Needs review 10 months ago
  • 🇫🇷France anfor

    Hi MacSim,

    Yes for drush command it's simple but not so much for some generator command.

    In subentity (2.x) the generator is depending on the class ModuleGenerator. This class does not exist anymore in DCG 3.x (include in drush 12).
    In this regard, we have chosen to create a new branch for drush 12 compatibility.
    You can use this release on your projects already in Drupal 10.2.x.

    Regards,

  • Status changed to Fixed 10 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024