Hey all,

I've recently been working on creating a pluggable service for generating ipsum filler text.

The general idea is to allow for modules to implement ipsum provider plugins to generate different kinds of lorem ipsum. At the moment there's a "classic" lorem ipsum plugin and also a Drupal-ipsum one, bacon coming next, you get the idea!

I'm concentrating efforts in the new Ipsum module: https://drupal.org/project/ipsum

What do you think about leveraging the ipsum service for devel generate? :)

PS - It's still very much a work in progress, the pluggable service stuff works but still locking down plugin settings, etc.

Comments

pcambra’s picture

I was thinking to open that door to things like https://drupal.org/project/faker but not sure if we want to bloat the thing, it's supposed to be a quick generation content tool...

moshe weitzman’s picture

At least in D7, we already support a way to hook in own content generation strategy. Not sure whats happenned in D8.

alexweber’s picture

@pcamba I don't see any reason why we couldn't implement a Faker Ipsum plugin :)

@moshe I wasn't aware there was a way to hook into it, that would make it really easy...

calebtr’s picture

I'm also curious about how to use a different generation strategy in d7. In D7, it looks to me like all of devel_generate calls devel_create_greeking(), which has a built-in dictionary.

What I'd like is to allow devel_generate to use the same /strategy/ for generating text but a different dictionary source.

Maybe the best way to accommodate both Faker and Ipsum/Drupal_Ipsum and whatever else comes along is with a hook? ie one of:

hook_devel_greeking_dictionary
hook_devel_dictionary
hook_devel_text_dictionary

pcambra’s picture

Assigned: Unassigned » moshe weitzman

@moshe weitzman now that the generation logic is in core :) how you suggest we deal with these? we've got a bunch of issues asking for text, image and files replacement, faker, ipsum...?

moshe weitzman’s picture

@pcambra - I'm kinda hand waving, but my thinking is that you write a module which provides an alternative textfield plugin (for example) and overrides the generateSampleValue() method. See \Drupal\Core\Field\FieldItemList::generateSampleItems which will load your custom field class and then call generateSampleValue().

Then its a matter of getting your site to use your custom textfield class. I think thats done with a services.yml but I'm not 100% familiar with this. See default.services.yml, for example.

ndf’s picture

Can't we use the 'hook' approach directly at the point where the random strings/names/words/etc are generated?
In d8 this is in file /core/lib/Drupal/Component/Utility/Random.php

That way it is possible for modules like 'ipsum' to override generation globally.

Although I didn't catch up with drupal 8 development yet, it expect something like:

// Allow other modules to change the sentences.
\Drupal::moduleHandler()->alter('sentences', $sentences, $min_word_count, $capitalize);

would work well. (somewhere in public function sentences() in named file).

What do you think about this? I am happy to write a patch if we can agree about the 'right' approach.

@see drupal7 issue: https://www.drupal.org/node/1228470

willzyx’s picture

Status: Active » Closed (outdated)

Closing for lack of activity. Feel free to reopen if the issue still exists