add maker for builder block
This commit is contained in:
parent
d1649a4959
commit
46e01f504f
85
src/core/Maker/MakeBuilderBlock.php
Normal file
85
src/core/Maker/MakeBuilderBlock.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\Maker;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation;
|
||||
use Symfony\Bundle\MakerBundle\ConsoleStyle;
|
||||
use Symfony\Bundle\MakerBundle\DependencyBuilder;
|
||||
use Symfony\Bundle\MakerBundle\Generator;
|
||||
use Symfony\Bundle\MakerBundle\InputConfiguration;
|
||||
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
|
||||
use Symfony\Bundle\MakerBundle\Str;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class MakeBuilderBlock extends AbstractMaker
|
||||
{
|
||||
public static function getCommandName(): string
|
||||
{
|
||||
return 'make:builder-block';
|
||||
}
|
||||
|
||||
public static function getCommandDescription(): string
|
||||
{
|
||||
return 'Creates a new builder block class';
|
||||
}
|
||||
|
||||
public function configureCommand(Command $command, InputConfiguration $inputConf)
|
||||
{
|
||||
$command
|
||||
->addArgument(
|
||||
'builder-block-class',
|
||||
InputArgument::OPTIONAL,
|
||||
'Choose a name for your block class (e.g. <fg=yellow>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('<fg=blue>created</>: %s', $realTemplatePath));
|
||||
}
|
||||
|
||||
$this->writeSuccessMessage($io);
|
||||
}
|
||||
|
||||
public function configureDependencies(DependencyBuilder $dependencies)
|
||||
{
|
||||
}
|
||||
}
|
38
src/core/Resources/maker/builder/Block.tpl.php
Normal file
38
src/core/Resources/maker/builder/Block.tpl.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php echo "<?php\n"; ?>
|
||||
|
||||
namespace <?php echo $namespace; ?>;
|
||||
|
||||
use App\Core\BuilderBlock\BuilderBlock;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
|
||||
#[AutoconfigureTag('builder_block.widget')]
|
||||
class <?php echo $class_name; ?> extends BuilderBlock
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this
|
||||
->setName('<?php echo $class_name; ?>')
|
||||
->setCategory('Custom')
|
||||
->setTemplate('<?php echo $template; ?>')
|
||||
->setLabel('<?php echo $label; ?>')
|
||||
// ->setOrder(1)
|
||||
// ->setIsContainer(false)
|
||||
// ->setIcon('<i class="fas fa-pencil-alt"></i>')
|
||||
// ->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)
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue