Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class naming convention #12

Closed
jurgenhaas opened this issue Feb 14, 2024 · 11 comments
Closed

Class naming convention #12

jurgenhaas opened this issue Feb 14, 2024 · 11 comments

Comments

@jurgenhaas
Copy link

We're building code generators for some of our Drupal modules (e.g. ECA, DRD and others) and we just found out, that the class name needs to follow the *Generator name pattern.

Is that really necessary or could that requirement be removed?

I mean, the classes are properly namespaced and come with all the PHP attributes to declare and make them discoverable. Enforcing the generator being part of the class name feels redundant, doesn't it?

@joachim-n
Copy link
Contributor

That sounds very cool!

I don't think that's the case though -- generator classes need to be in the DrupalCodeBuilder\Generator namespace -- see ComponentClassHandler.

@jurgenhaas
Copy link
Author

That doesn't seem to be correct. A generator in a Drupal module has to be in the Drupal\MODULENAME\Drush\Generators namespace; otherwise the autoloader would even find it.

An example of a working generator can be found at https://git.drupalcode.org/project/eca/-/blob/2.0.x/modules/development/src/Drush/Generators/ActionGenerator.php?ref_type=heads

If we rename the class from ActionGenerator to Action, it isn't found anymore. So it's really just about the class name suffix.

@joachim-n
Copy link
Contributor

Ah. You're in the wrong code generator project -- that's Drush code generator stuff.

BTW, this code generator, Drupal Code Builder, probably already can generate what you want -- it can generate any type of plugin OOTB.

@jurgenhaas
Copy link
Author

Oh, never realized that there are 2 different ones. Thanks for the heads-up. So drupal-code-builder/drupal-code-builder can either be used with the module builder project or with this project here, which attempts to provide drush commands to do so. However, that doesn't work with Drush 12, as I'm seeing the same issue as reported 5 years ago: #11

@joachim-n
Copy link
Contributor

Yup, drupal-code-builder/drupal-code-builder is the code generating library, and Module Builder and this package are just UIs. I don't do very much with this package because I personally prefer the Module Builder UI, but I thought I'd fixed that bug -- maybe I need to make a release or push some code from my local.

@joachim-n
Copy link
Contributor

Prompted by your reminder that this package exists, I've updated it for the latest DCB and improved the UI. Try the latest release -- it will already support ECA plugins OOTB.

@joachim-n joachim-n closed this as not planned Won't fix, can't repro, duplicate, stale Feb 19, 2024
@jurgenhaas
Copy link
Author

Hmm, it looks like this breaks differently now:

 [preflight] Class "Drush\Commands\drupal_code_builder_drush\Drush\Commands\CodeBuilderDevDrushCommands" does not exist

This happens for any drush command, since I've update to v10 or this package. When I remove that directory from the code base, Drush works again.

@joachim-n
Copy link
Contributor

What version of Drush are you on? It's working fine for me with Drush 12.

@jurgenhaas
Copy link
Author

I'm on Drush 12.4.3.0

@joachim-n
Copy link
Contributor

Same version here.
Could you open a new issue and give a backtrace please?

@jurgenhaas
Copy link
Author

No backtrace, it's failing in Drush immediately. But yes, I'll dig deeper and open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants