Reputation: 63
I am trying to customize the maker:crud.
The official documentation and The Symfony MakerBundle indicates "you can create your own make: ... command reusing the tools provided by this bundle .To do that, you should create a class that extends AbstractMaker in your src/Maker/ directory".
So my first step is to copy from the repository, which is also indicated in the documentation, the script MakeCrud.php in the src/Maker/MakeCustomCrud.php (I rename it). I apply some basic changes like renaming the class and the name of the command.
When ready the available commands I am waiting to see between the commands make some make:custom-crud. Obviously when trying to invoke it (php bin/console make:custom-crud) I am informed Command "make:custom-crud" is not defined. I'm doing something wrong and I don't know what it is.
I transcribe part of the code below src/Maker/MakeCustomCrud.php:
<?php
/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\MakerBundle\Maker;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Common\Inflector\Inflector;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\Doctrine\DoctrineHelper;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\Renderer\FormTypeRenderer;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Bundle\MakerBundle\Validator;
use Symfony\Bundle\TwigBundle\TwigBundle;
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\Form\AbstractType;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Csrf\CsrfTokenManager;
use Symfony\Component\Validator\Validation;
/**
* @author Sadicov Vladimir <[email protected]>
*/
final class MakeCustomCrud extends AbstractMaker
{
private $doctrineHelper;
private $formTypeRenderer;
public function __construct(DoctrineHelper $doctrineHelper, FormTypeRenderer $formTypeRenderer)
{
$this->doctrineHelper = $doctrineHelper;
$this->formTypeRenderer = $formTypeRenderer;
}
public static function getCommandName(): string
{
return 'make:custom-crud';
}
/**
* {@inheritdoc}
*/
public function configureCommand(Command $command, InputConfiguration $inputConfig)
{
$command
->setDescription('Creates Custom CRUD for Doctrine entity class')
->addArgument('entity-class', InputArgument::OPTIONAL, sprintf('The class name of the entity to create Custom CRUD (e.g. <fg=yellow>%s</>)', Str::asClassName(Str::getRandomTerm())))
->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeCrud.txt'))
;
$inputConfig->setArgumentAsNonInteractive('entity-class');
}
Upvotes: 3
Views: 2468
Reputation: 1
I resolved this problem with this lines in services.yaml
maker.renderer.form_type_renderer:
class: Symfony\Bundle\MakerBundle\Renderer\FormTypeRenderer
arguments:
- '@maker.generator'
Symfony\Bundle\MakerBundle\Renderer\FormTypeRenderer:
alias: maker.renderer.form_type_renderer
I hope it helps you
Upvotes: 0
Reputation: 394
You can patch it with composer:
./patch
./vendor/symfony/maker--bundle/src/Resources/skeleton/form/Type.tpl.php
and add in your composer.json
Example:
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"patch": [
"cp patch/patch_crud/Type.tpl.php vendor/symfony/maker-bundle/src/Resources/skeleton/form/."
],
"post-install-cmd": [
[
"@patch",
"@auto-scripts"
]
],
"post-update-cmd": [
"@patch",
"@auto-scripts"
]
},
you can modify the file
a example of this here
Upvotes: 2