PHP code example of web-systems / gutenberg-bundle

1. Go to this page and download the library: Download web-systems/gutenberg-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

web-systems / gutenberg-bundle example snippets


$builder->add('content', GutenbergType::class);

$builder->add('content', GutenbergType::class, [
    'editor_height' => 800,
    'allowed_blocks' => ['core/paragraph', 'core/heading', 'core/image'],
    'block_template' => [['core/heading', ['level' => 2]], ['core/paragraph', []]],
    'template_lock' => 'insert',
]);

use WebSystems\GutenbergBundle\EasyAdmin\Field\GutenbergField;

yield GutenbergField::new('content', 'Page content')
    ->setHeight(760)
    ->renderOnDetail();

public function configureCrud(Crud $crud): Crud
{
    return $crud->setFormThemes([
        '@WebSystemsGutenberg/form/gutenberg_widget.html.twig',
        '@EasyAdmin/crud/form_theme.html.twig',
    ]);
}

public function __construct(private ContentRendererInterface $renderer) {}

$html = $this->renderer->render($page->getContent());

#[AsBlock(
    name: 'app/hero',
    title: 'Hero',
    icon: 'cover-image',
    category: 'cms',
    template: 'blocks/hero.html.twig',
)]
final class HeroBlock extends AbstractBlockType
{
    public function configureAttributes(AttributeBuilder $builder): void
    {
        $builder
            ->richText('title', 'Heading', 'Welcome')
            ->textarea('lead', 'Intro text')
            ->image('background', 'Background image')
            ->color('overlay', 'Overlay colour', '#1d3557')
            ->range('overlayOpacity', 'Overlay strength (%)', 55, 0, 100, 5)
            ->select('align', 'Alignment', ['left' => 'Left', 'center' => 'Centre'], 'center')
            ->url('cta', 'Button');
    }
}

public function __construct(private PageRepository $pages) {}

public function render(BlockRenderContext $context): string
{
    return $this->getTwig()->render($this->getTemplate(), [
        'attributes' => $context->attributes,
        'pages' => $this->pages->findPublished((int) $context->get('limit', 3)),
    ]);
}