MWDelaney / sage-acf-wp-blocks

Composer library for generating ACF Gutenberg blocks from templates. Intended for use with Roots/Sage (http://roots.io)
347 stars 65 forks source link

Register block preview image with acf_register_block_type #48

Open andevit opened 4 years ago

andevit commented 4 years ago

Hi guys! There is a solution for add a preview image for the core Gutenberg blocks when you hover over their icons in the top left add block popup?

It would be great to be able to set a static image for custom blocks registered with acf_register_block_type.

For example we could add a "PreviewImage" like this:

{{--
  Title: Name Block
  Description: Description Block
  Category: formatting
  Icon: admin-comments
  Keywords: quote
  Mode: edit
  Align: left
  PostTypes: page post
  SupportsAlign: left right
  SupportsMode: false
  SupportsMultiple: false
  EnqueueStyle: styles/style.css
  EnqueueScript: scripts/script.js
  EnqueueAssets: path/to/asset
  Preview: true
  PreviewImage: path/to/my/block/preview.jpg
--}}

Can you help me?

robmeijerink commented 4 years ago

Hi!

Looking at ACF's documentation, are you referring to the section with Header: Adding block previews ?

atoupet-toki commented 3 years ago

Hi @andevit did you find something ?? It's exactly what I need 😬

igor-sumonja commented 2 years ago

you can add dummy preview data like like this in meantime Simple hook into filter

`add_filter('sage/blocks/button/register-data', function ($data) {

$data['example'] = [
    'attributes' => [
        'mode' => 'preview',
        'data' => [
            'link' => [
                'title' => 'Change me',
                'url' => '#',
                'target' => '_self'
            ],
            'type' => 'primary',
            'size' => 'regular',
            'icon' => '',
        ]
    ]
];

return $data;

}); `

mantrone commented 2 years ago

Any progress on this?