- Issue created by @boinkster
- Status changed to Postponed
over 1 year ago 2:39pm 17 November 2023 - πΊπΈUnited States tim bozeman
boinkster, now that's an awesome username! That's a great question. Right now I am doing something like this to tweak the auto-generated content.
In an event subscriber:
public function onPrePlaceBlockFormBuild(PlaceBlockEvent $event) { if ($event->getBlockPluginId() === 'inline_block' && $event->getBundle() === 'basic_text_or_something') { $block_plugin = $event->getBlockPlugin(); $configuration = $block_plugin->getConfiguration(); $block_content = unserialize($configuration['block_serialized']); $random = new Random(); $block_content->set('body', $random->sentences(mt_rand(5, 19), FALSE)); $configuration['block_serialized'] = serialize($block_content); $configuration['label_display'] = 'visible'; $configuration['label'] = $block_plugin->label(); $block_plugin->setConfiguration($configuration); } } /** * {@inheritdoc} */ public static function getSubscribedEvents() { return [ // After PlaceBlockFormBuild is called. PlaceBlockEvent::class => ['onPrePlaceBlockFormBuild'], ]; }
That scratches our itch for the moment, but a teammate is writing a field sample value contrib module which we'll integrate with at some point to solve this problem.
- πΊπΈUnited States boinkster
Thanks. it comes from an old nickname
A field sample value module sounds useful. My main issue is a couple of block types that have a potpourri of optional fields (text and media) with the intention that the user could edit as needed but never use all of them. I'll see if I can adapt your code to populate one but null the rest. - πΊπΈUnited States boinkster
Would it be an option to use the default field value?
- πΊπΈUnited States tim bozeman
I have seen a demo of that sample field value module that Andrei is writing and it provides a UI that lets you choose from different lorem ipsum generators or use the default field value. Maybe there's other stuff too, but I know you will definitely be able to choose the default value in the future.
In the meantime you could probably load the default value for that field in the event subscriber. π€
- πΊπΈUnited States boinkster
Looking forward to it. I keep bouncing between this and Layout Paragraphs - each has UI quirks for my use case and themes so choosing is difficult. Staying closer to core LB is preferable, though. Great work on this!
- πΊπΈUnited States tim bozeman
Thanks!
What's the UI quirks for your use case?
- πΊπΈUnited States boinkster
Maybe quirks is too strong a word... just all the different LB solutions out there. Each offers different opinions and approaches. Some combine nicely, while some collide badly. The issue queue probably isn't the right forum to riff on this.
- Status changed to Active
over 1 year ago 4:11pm 11 January 2024 - πΊπΈUnited States tim bozeman
Just an update, that module was in fact posted a while ago. We just need to integrate LB+ and field_sample_value β .
- Status changed to Fixed
over 1 year ago 9:59pm 22 January 2024 - πΊπΈUnited States tim bozeman
Okay cool. Now if you want to tweak the auto-generated values you can do so in the field settings right by where you would set a default value.
Automatically closed - issue fixed for 2 weeks with no activity.