1. Go to this page and download the library: Download umanit/block-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/ */
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Umanit\BlockBundle\Entity\Block;
/**
* @ORM\Entity()
*/
#[ORM\Entity]
class TitleAndText extends Block
{
/**
* @var string
*
* @ORM\Column(name="title", type="string")
*/
#[ORM\Column(name: 'title', type: 'string')]
private $title;
/**
* @var string
*
* @ORM\Column(name="text", type="text")
*/
#[ORM\Column(name: 'text', type: 'text')]
private $text;
// getters and setters ...
/**
*
*/
public function __toString()
{
return $this->getTitle() ? : 'New TitleAndText';
}
}
namespace AppBundle\BlockManager;
use AppBundle\Entity\TitleAndText;
use AppBundle\Form\TitleAndTextType;
use Umanit\BlockBundle\Block\AbstractBlockManager;
use Umanit\BlockBundle\Model\BlockInterface;
use Twig\Environment;
use \Twig\Error\LoaderError;
use \Twig\Error\RuntimeError;
use \Twig\Error\SyntaxError;
class TitleAndTextManager extends AbstractBlockManager
{
/** @var Environment */
private $twig;
/**
* QuoteBlockManager constructor.
*
* @param Environment $twig
*/
public function __construct(Environment $twig)
{
$this->twig = $twig;
}
/**
* Define which Block type is managed by this Manager
*
* @return string
*/
public function getManagedBlockType(): string
{
return TitleAndText::class;
}
/**
* This method must return the form typemanaged by this block manager.
*
* @return string
*/
public function getManagedFormType(): string
{
return TitleAndTextType::class;
}
/**
* Define how the block should be rendered on the front end.
*
* @param BlockInterface $block
* @param array $parameters
*
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function render(BlockInterface $block, array $parameters = []): string
{
return $this->twig->render('blocks/title-and-text.html.twig', ['block' => $block]);
}
}
namespace AppBundle\Form\TitleAndTextType;
use Umanit\BlockBundle\Form\AbstractBlockType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
class TitleAndTextType extends AbstractBlockType
{
/**
* Define the form used by the back end to administrate the block.
*
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('title', TextType::class, [
'constraints' => [
new NotBlank(),
],
])
->add('text', TextareaType::class, [
'constraints' => [
new NotBlank(),
],
])
;
}
}