diff --git a/src/core/Maker/MakeBuilderBlock.php b/src/core/Maker/MakeBuilderBlock.php new file mode 100644 index 0000000..7e72f78 --- /dev/null +++ b/src/core/Maker/MakeBuilderBlock.php @@ -0,0 +1,85 @@ +addArgument( + 'builder-block-class', + InputArgument::OPTIONAL, + 'Choose a name for your block class (e.g. ExampleBlock)' + ) + ->setHelp('') + ; + } + + public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator) + { + $blockClassNameDetails = $generator->createClassNameDetails( + $input->getArgument('builder-block-class'), + 'BuilderBlock\\', + 'Block' + ); + + $templatePath = sprintf( + 'builder_block/%s.html.twig', + Str::asSnakeCase(preg_replace('/Block$/', '', $blockClassNameDetails->getShortName())) + ); + + $options = [ + 'entity' => $blockClassNameDetails->getFullName(), + 'template' => $templatePath, + 'label' => Str::asHumanWords($blockClassNameDetails->getShortName()) + ]; + + $blockPath = $generator->generateController( + $blockClassNameDetails->getFullName(), + __DIR__.'/../Resources/maker/builder/Block.tpl.php', + $options + ); + + $generator->writeChanges(); + $realTemplatePath = 'templates/'.$templatePath; + + $filesystem = new Filesystem(); + + if (!$filesystem->exists($templatePath)) { + $filesystem->mkdir(dirname($realTemplatePath)); + $filesystem->dumpFile($realTemplatePath, "{% for item in children %}\n\t{{ item|block_to_html(context) }}\n{% endfor %}\n"); + + $io->comment(sprintf('created: %s', $realTemplatePath)); + } + + $this->writeSuccessMessage($io); + } + + public function configureDependencies(DependencyBuilder $dependencies) + { + } +} diff --git a/src/core/Resources/maker/builder/Block.tpl.php b/src/core/Resources/maker/builder/Block.tpl.php new file mode 100644 index 0000000..e1d5afd --- /dev/null +++ b/src/core/Resources/maker/builder/Block.tpl.php @@ -0,0 +1,38 @@ + + +namespace ; + +use App\Core\BuilderBlock\BuilderBlock; +use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; + +#[AutoconfigureTag('builder_block.widget')] +class extends BuilderBlock +{ + public function configure() + { + $this + ->setName('') + ->setCategory('Custom') + ->setTemplate('') + ->setLabel('') + // ->setOrder(1) + // ->setIsContainer(false) + // ->setIcon('') + // ->setClass('col-md-12') + // ->addSetting(name: 'value1', label: 'Text', type: 'text', attributes: [], default: '') + // ->addSetting(name: 'value2', label: 'Checkbox', type: 'checkbox', attributes: [], default: true) + // ->addSetting(name: 'value2', label: 'Number', type: 'checkbox', attributes: [], default: true) + // ->addSetting(name: 'value3', label: 'Textarea', type: 'textarea', attributes: [], default: '') + // ->addSetting(name: 'value4', label: 'Choice', type: 'select', attributes: [], default: '', extraOptions: [ + // 'options' => [ + // ['text' => 'Choice 1', 'value' => 'choice1'], + // ['text' => 'Choice 2', 'value' => 'choice2'], + // ], + // ]) + ; + } + + public function buildVars(array $data, array $context) + { + } +}