Customize generated content

Created on 17 November 2023, 7 months ago
Updated 9 February 2024, 5 months ago

Problem/Motivation

Sometimes content generated while placing a block is a bit much. It there a way to control what gets generated and/or whether some fields can be left empty?

✨ Feature request
Status

Fixed

Version

2.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States boinkster

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @boinkster
  • Status changed to Postponed 7 months ago
  • πŸ‡ΊπŸ‡Έ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.

  • πŸ‡ΊπŸ‡ΈUnited States Tim Bozeman

    Okay

    Β―\_(ツ)_/Β―

  • Status changed to Active 6 months ago
  • πŸ‡ΊπŸ‡Έ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 β†’ .

  • Merge request !30Add support for field_sample_value. β†’ (Merged) created by Tim Bozeman
  • Status changed to Fixed 5 months ago
  • πŸ‡ΊπŸ‡Έ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.

  • Merge request !32Add support for field_sample_value. β†’ (Merged) created by Tim Bozeman
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024