Hi,
I have developed this patch just as an exercise to become familiar with new Drupal 8 API but I think that it could be interesting to take into consideration.
This patch is a purpose to consider DevelGenerate as a D8 plugin type.
"DevelGeneratePluginManager" extends "DefaultPluginManager" in order to manage this plugin type.
"DevelGenerateBaseInterface" define the methods that most DevelGenerate plugin implementations will want inherit from "DevelGenerateBase".
Every new DevelGenerate plugin implementation just should developing "settingsForm()" method and "generateElements()" method to achieve its own behaviour.
Links to "create every elements" in "admin/config/development" are created dynamically under demand via "DevelGenerateRouteSubscriber" class
There is just one form class "DevelGenerateForm" which shows the form created by each plugin implementation implementing "settingsForm()" method.
This form is able to make use of properties defined in "DevelGenerate" Annotation class whose values are provided via annotations by each plugin implementation.
"GenerateElements($values)" method receives an array with the form values in order to use them for its purpose.
So all a developer should do to have a new DevelGenerate plugin completely integrated with the module is to create a Class extending "DevelGenerateBase" providing its settings via annotations and implementing "settingsFrom()" method and "generateElements()" method.
This patch is just a first approach that provides UserDevelGenerate plugin implementation, obviously there are a lot "todos". I would be glad to continue working on it if you think it is interesting for the module.
Regards.
| Comment | File | Size | Author |
|---|---|---|---|
| #41 | interdiff.txt | 176 bytes | Enxebre |
| #41 | DevelGenerate-2154141-41.patch | 183.3 KB | Enxebre |
| #35 | interdiff.txt | 7.56 KB | Enxebre |
| #35 | DevelGenerate-2154141-35.patch | 183.29 KB | Enxebre |
| #33 | interdiff.txt | 11.85 KB | Enxebre |
Comments
Comment #1
Enxebre commentedComment #2
Enxebre commentedComment #5
Enxebre commentedComment #6
moshe weitzman commentedThanks! Looks like a good modernization. Lets make sure we keep the Drush integration working as we patch this. It is a good exercise to assure that the new code is reusable. Drush has an "engine" system where code can vary by Drupal version. I think that would be appropriate here since the D8 code will be so different. If the author wants to ignore engines for now, I can layer that in later.
Comment #7
Enxebre commentedGreat, I'll send a new patch ASAP.
Regards.
Comment #8
Enxebre commentedComment #9
Enxebre commentedHi,
I was completely unaware about the drush "engine" system so I am developing as normal at the moment but any info about the subject would be appreciate.
Two new methods added to DevelGenerateBase:
- getDrushValues() which is responsible for suiting the drush params to fit in "generateElements()" method.
- drushLog()
The DevelGenerate Annotation class has now tho new params:
- drushSettings.
- drushArgs
Devel_generate.drush.inc has just two functions:
- devel_generate_drush_command() where every command is created dynamically for every instance of DevelGenerate plugin using the plugin annotations.
- drush_devel_generate(). Common callback for every plugin.
With this approach we are able to keep the same drush syntax than old devel_generate versions regarding command names, arguments or options.
So every plugin is responsible for declare and handle its drush settings for suitting generateElements() making Devel_generate.drush.inc just a common "bridge" without business logic for every plugin implementation.
UserDevelGenerate should be practically working full whether via Drush or UI.
So in my opinion next steps would be improve this code as much as possible making the most of the Plugin API and once it is perfect we should implement the other plugins (Content, terms, etc).
So waiting feedback from now.
Regads.
Comment #12
Enxebre commentedSorry, wrong patch.
This one is working.
Comment #13
Enxebre commentedComment #15
Enxebre commentedComment #16
pcambraFirst of all, thanks Enxebre for starting this.
This patch is getting bigger and bigger and I'm afraid we'd end up with something not manageable.
The least we can do here is to provide an interdiff, otherwise it will be impossible to review.
Options we have here:
Here's a review of what I've seen so far.
Why do we need this? seems like overhead to me
Comments go over 80 chars, we need to stick to Drupal standards
Why do we add it then?
Watch out this commented code, we probably need alter hooks?
Also the factory is added.
We should be able to get the element to generate better
53?
Comment #17
Enxebre commentedHi, Thanks a lot for the review pcambra. I'll probably be able to have an stable version of the module with all the plugins implemented during this week so may be the sandbox is the best choice.
Regards.
Comment #18
Enxebre commentedHi,
I am attaching here a patch with a full version of the module.
So now we have:
- A new plugin type called "DevelGenerate".
- The module provides 5 instance of this plugin type (User, Content, Menu, Terms and Vocabulary).
- To create a new instance is necessary to create just a class an implement 3 methods. This provides automatically drush support, a new link in admin/config/development and a settings form.
- The fields management is handle by a group of classes including a factory which instantiate objects depending on the field provider, so to support new field types a developer just have to create a new class extending DevelGenerateFieldNewsuporttedtype and implement a method.
All this and further information is explained in the README.txt file
Regarding @pcambra review:
1 - Not necessary, removed.
3 - Using default factory now.
4 - Yes, developers can altering DevelGenerate plugins settings via hook alter (See Readme).
5 - Done.
6 - Just testing... :-)
I think this is a good version to be patched and to continue working on later to suit the code to fit with the changes of the Drupal 8 API. Anyway if you don't agree with that we can create a sandbox and apply the incoming feedback toward the sandbox.
Thanks!
Regards.
Comment #20
pcambraThanks, this one seem way more complete, let me give it a try and give proper feedback.
Let's try to get the tests green, probably need to be adapted to fit the new plugin system, also a more complete test coverage is desirable.
Regarding this:
It would be ideal to have a generic entity system, but let's leave this for a second iteration maybe.
Comment #21
Enxebre commentedHi,
I have suited the tests for the new version and added some small improvements.
Just let me know if you would like me to send a new patch, otherwise I adding this changes later with the incoming feedback.
Regards.
Comment #22
pcambraReviewing patches that introduce a 100k interdiff and move files is quite hard, that's why I suggested a sandbox instead.
First let's make the tests green, then we can go on with further reviews.
Comment #23
Enxebre commentedHi,
I have created a sandbox here https://drupal.org/sandbox/enxebre/2167477
git clone --branch master http://git.drupal.org/sandbox/Enxebre/2167477.git devel_generate
We are keeping the same functional test coverage.
There is also a devel_generate_example module, it could be useful for creating unit test covering the DevelGeneratePlugin API in the future.
Comment #24
Enxebre commentedI have also added a unit test for the DevelGenerateManager so just waiting for feeback now...
Thanks!
Comment #25
pcambraNice, I'll be creating issues in https://drupal.org/project/issues/2167477 instead of making more noise here, once we've got something stable, we can put a patch back in here.
Anyone interested in contributing to this patch, please refer to the sandbox https://drupal.org/sandbox/enxebre/2167477
Could you give me access to commit in there?
Comment #26
Enxebre commentedGreat! you should have access to commit now.
Comment #27
Enxebre commentedHi,
I am posting here a patch with an stable version of the module after fixing several issues working with @pcambra here https://drupal.org/sandbox/enxebre/2167477, most of them trying to keep the module up to date with the lastest changes in the Drupal API.
Comment #28
pcambraThanks @Enxebre
This would be a really needed change and would allow us to get further and abstract the entity generation to generate any kind of entity.
Assigned to moshe for review as we're completely changing devel generate :)
Comment #29
moshe weitzman commentedI need to review this further. My first impression is to be a bit skeptical about the dynamic declaration of drush commands. How hard would it be to do this with one command? We could do further dispatching in the command callback.
Comment #30
moshe weitzman commentedDoes anyone know of other modules that do dynamic declaration of commands?
Comment #31
pcambraI think @moshe is referring to this part here.
Maybe a better solution could be to have just one command:
Keeping this in sync with d8 head and devel head these days is quite hard, could we revert the change refering to drush, keep the "static" old generate commands and have a followup for the one above?
Comment #32
Enxebre commentedHi,
These are my thinkings:
After a quick look I haven´t found another modules with similar approach what is a little suspect... but on the other hand I have to say that I can´t see any weak point with this approach.
It seems to be a good way for reusing code and give us flexibility and easy drush integration for new plugins.
We could have just one command and to dispatch in the callback function but in that case we could not replicate the current functionality because all plugins should have same drush parameters and options and this is not happening now, and we would be loosing a lot of flexibility.
Keeping the static old generate commands could be a good temporal solution but having in mind a new approach for the future because otherwise we would be missing the point of thinking in DevelGenerate as plugins.
Comment #33
Enxebre commentedHi,
I am posting here a new version with static declaration of drush commands. We are using just one callback which dispatch depending on the plugin.
It could be an intermediate step in the way to have just one command or whatever. If you decide to have just one command we would need to specify common params (args and options) for every plugin.
Comment #34
moshe weitzman commentedLooks good. Could we rename and/or document handleDrushParams(). I'm not clear on what it does, and why it is Drush specific. In the implementations we do a fair amount of input validation which would usually belong in a drush validate hook.
We are preserving all existing tests and assertions?
The Drupal code looks good enough to me.
Comment #35
Enxebre commentedHi,
handleDrushParams() has been renamed to
A least at the moment it should be drush specific, May be in the future we can refactor and do it more generic.
It is encapsulating drush business logic for validating which is being used now by drush_hook_command_validate.
We are keeping the same test and assertions. In addition we have currently one unit test for the DevelGenerateManagerare and a devel_generate_example module which makes life easier for developers who wants to develop new plugins and is useful to create unit tests towards it as well.
Comment #36
Enxebre commentedComment #37
Enxebre commentedComment #38
ianthomas_uk@Enxebre: It looks like devel itself is failing tests at the moment. If you click view on your patch you'll see the testing is postponed, if you click the branch link from there you'll see failures in Drupal\devel\Tests\DevelMailTest and Drupal\devel_generate\Tests\DevelGenerateTest. A function that it was depending on has probably been removed from core.
Comment #41
Enxebre commentedForgot to change the name function in the example module. Should be passing the test now.
Comment #42
Enxebre commentedComment #43
pcambraThe testbot went away but we're green again, if the drush part looks better, I think we're good with the plugin approach and open followups for the next steps.
Again, huge kudos to @Enxebre for working on this :)
Comment #44
moshe weitzman commentedOK, I'm happy with this. I've been away for a week, so pcambra can commit this if now is a good time. Thanks @Enxebre
Comment #45
andypostSuppose now devel should be fixed to work with current HEAD #2208597: Devel HEAD broken: Update calls to config(), drupal_map_assoc, Drupal\Core\Mail\PhpMail
Comment #46
pcambraThe patch has got in! huge thanks to @Enxebre for the work on this.
We've got a remaining issue with the menus, I'll investigate it and open a follow up.
Comment #47
Enxebre commentedGlad to contrib.
Thanks a lot to @pcambra for woking on this with me.