Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Allowing the function responsible for specific field generation to be alterable would make replacing the default generated field content quite easy, and would actually solve some other problems for devel_generate, e.g:
#1228470: Support for alternate dictionaries (instead of the default greeking)
#1238344: Allow other modules to generate images for devel_generate
(probably others)
Comment | File | Size | Author |
---|---|---|---|
#4 | devel_generate_alter-1326204-4.patch | 965 bytes | duellj |
#1 | devel_generate_alter-1326204-1.patch | 814 bytes | duellj |
Comments
Comment #1
duellj CreditAttribution: duellj commentedAnd here's a patch. Basically it allows modules to override the devel generate function based any number of criteria, including field module, field type, bundle, or object properties. Simple patch, but would open up a whole host of possibilities with devel_generate.
Comment #2
duellj CreditAttribution: duellj commentedAnd here is a simple implementation of hook_devel_generate_field_function_alter() that generates very simple text for all text fields.
Comment #3
salvisI like the idea, but...
... drupal_alter() takes only 4 arguments. You need to wrap them into an array.
Comment #4
duellj CreditAttribution: duellj commentedGood call, missed that. Updated patch.
Comment #5
axe312 CreditAttribution: axe312 commentedIs working for me!
here is a fixed implementation example:
Comment #6
salvisI still like the idea, but now it's D8-first...
Comment #7
salvis#4: devel_generate_alter-1326204-4.patch queued for re-testing.
Comment #8
pcambraLoving this idea, it would be really useful to standardize all the alteration (i.e. for making a pluggable text generation and reuse it in the image provider module).
Needs a reroll to D8 and adding #5 as an example/docs.
Comment #9
pcambraTagging, needs reroll
Comment #10
pcambraComment #11
moshe weitzman CreditAttribution: moshe weitzman commentedCan modules provide their own plugins now, and replace devel's? Using an autoloader hack?
Comment #12
pcambraWe have an example on this for the image generation in the tests modules http://cgit.drupalcode.org/devel/tree/devel_generate/tests/modules/devel...
Comment #13
moshe weitzman CreditAttribution: moshe weitzman commentedField generate functions are now on the Field item classes (e.g. \Drupal\file\Plugin\Field\FieldType\FileItem::generateSampleValue) so you swap those with however you swap plugins. I dunno yet. Anyway, not a devel problem in D8, and not likely changing in prior versions.