Page

A page is a doctrine entity that contains blocks and form builder. For each element defined in buildForm, you must add a getter and a setter. See the example below.

// src/Entity/Page/YourPage.php
namespace App\Entity\Page;

use App\Core\Entity\Site\Page\Block;
use App\Core\Entity\Site\Page\Page;
use App\Core\Form\Site\Page\TextBlockType;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Form\FormBuilderInterface;

/**
 * @ORM\Entity
 */
class YourPage extends Page
{
    public function buildForm(FormBuilderInterface $builder)
    {
        $builder->add(
            'myBlock',
            TextBlockType::class,
            [
                'label' => 'My block',
                'options' => [
                    // options given to the sub form
                ],
            ]
        );

        // ...
    }

    public function setMyBlock(Block $block)
    {
        return $this->setBlock($block);
    }

    public function getMyBlock(): Block
    {
        return $this->getBlock('myBlock');
    }

    // ...
}

Then edit config/packages/app.yaml and add your page:

core:
    site:
        pages:
            App\Entity\Page\SimplePage:
                name: 'Simple page'
                templates:
                    - {name: "Default", file: "page/simple/default.html.twig"}
            App\Entity\Page\YourPage:
                name: 'Your page'
                templates:
                    - {name: "Template 1", file: "page/your_page/template1.html.twig"}
                    - {name: "Template 2", file: "page/your_page/template2.html.twig"}

Blocks

TextBlockType

App\Core\Form\Site\Page\TextBlockType will render a symfony TextType.

TextareaBlockType

App\Core\Form\Site\Page\TextareaBlockType will render a symfony TextareaType.

FileBlockType

App\Core\Form\Site\Page\FileBlockType will render a symfony FileType with a download link.

In the getter, you must specify the block:

use App\Core\Entity\Site\Page\FileBlock;

public function getMyBlock(): Block
{
    return $this->getBlock('myBlock', FileBlock::class);
}

ImageBlockType

App\Core\Form\Site\Page\ImageBlockType will render a symfony FileType with a preview of the image.

In the getter, you must specify the block:

use App\Core\Entity\Site\Page\FileBlock;

public function getMyBlock(): Block
{
    return $this->getBlock('myBlock', FileBlock::class);
}

CollectionBlockType

App\Core\Form\Site\Page\CollectionBlockType will a render a symfony CollectionType with availabity to add and remove elements.

use App\Core\Entity\Site\Page\CollectionBlock;

public function getMyBlock(): Block
{
    return $this->getBlock('myBlock', CollectionBlock::class);
}