Symfony 6 and EasyAdmin 4 extends page : Variable "ea" does not exist - symfony

Symfony 6 and EasyAdmin 4 : in new twig when I extends #EasyAdmin/page/content.html.twig, error "ea" does not exist
{"status":500,"message":"Variable \u0022ea\u0022 does not exist."}

Related

Routing changes when upgrading easyadmin bundle symfony

I am in charge of upgrading easyadmin bundle on an app that was previously built using symfony v4.4.19. Initially we had: easycorp/easyadmin-bundle v2.3.12. Then, we decided to upgrade the easyadmin bundle to v3 because we faced some issues when enabling/disabling a boolean property from the list view.
When I was using the v2 :
php bin/console debug:router showed a route called easyadmin with a path /myworkshop/ .
I had no Dashboard controller nor NecklaceCrudController, I simply had a controlller called
AccessoriesController.php with several actions like deleteAction that is executed when the user
deletes an entity, editAction when the user edits an entity, SearchAction ...
In the deleteAction there is this line of code:
return $this->redirect($this->generateUrl('easyadmin', array('action' => 'list', 'entity'=> $this->entity['name'])));
so the url would become something like this
/myworkshop/?action=list&entity=necklace
To open the easy admin interface I have to click on a menu link whose link is :
->createItem('Visit my workshop', ['route' => 'easyadmin']);
When I open this interface /references, I get the list of the different entities in my app, if
I select one, I see the list view and I can edit one entity successfully but I cannot
enable/disable boolean properties from the list view as mentioned earlier.
We specified /myworkshop instead of /admin in app>config>routing.yml
# easy admin
easy_admin_bundle:
resource: "#myShop/Controller/AccessoriesController.php"
type: annotation
prefix: /myworkshop```
- A custom css was successfully employed in : app>config>config.yml
easy_admin:
design:
assets:
css:
- 'bundles/css/easyadmin.css
When I upgraded to v3:
php bin/console debug:router showed a route called myshop_admin_dashboard_index (which was
automatically generated) with a path /easyadmin.
Dashboard controller and NecklaceCrudController were created, The DashboardController only has configureCrud() and configureMenuItems() functions. The latter contains the links yield MenuItem::linkToCrud . Question 1 : In version 2 no menu links where created explicitely like here, so I was wondering how was the complete list of entities correctly showing up on my application interface?
In DashboardController there is no index () function nor a route nor a link just configureCrud() and configureMenuItems() functions.
I want to keep the AccessoriesController.php with his several actions but now, with the new route and path, it is completely being ignored. Question 2 : Is there something that I have to change in the generateUrl part? can someone give me an example of what this will become if I opt for adminUrlgenerator like I read in the documentation?
The routing.yml file remains the same however, my easyadmin interface appears only when visiting this link /easyadmin instead of /myworkshop . Question 3: I want to keep the /workshop url , what should I do in addition to keeping the routing.yml as it is now?
I wish we could change myshop_admin_dashboard_index to easyadmin and /easyadmin to my /myworkshop as it was in version 2, because there are many parts in AccessoriesController where I use $this->generateUrl('easyadmin',
Question 4: The css is no longer applicable any idea why? could be related to the AccessoriesController that is not currently being taken into account.
Well, you can add the index method to your dashboard controller with route annotation to change the route
class DashboardController extends AbstractDashboardController
{
/**
* #Route("/myworkshop", name="admin")
*/
public function index(): Response
{
return $this->render('dashboard/index.html.twig');
}
You can add any route to easyadmin menu like this
class DashboardController extends AbstractDashboardController
{
public function configureMenuItems(): iterable
{
yield MenuItem::linktoRoute('Some Route', 'fa fa-info', 'route_name_here');
#...
}
}
You can add any CSS/js file too
class DashboardController extends AbstractDashboardController
{
public function configureAssets(): Assets
{
return Assets::new()
->addCssFile('build/admin.css')
->addJsFile('build/admin.js')
;
}
}

Symfony FOSRestBundle exception error 404

I try to add an exeption when i a page not found, 404.
So i add this is ocnfig fos_rest :
# exception:
# codes:
# 'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
# 'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
# messages:
# 'Acme\HelloBundle\Exception\MyExceptionWithASafeMessage': true
But i have this error :
FOSRestBundle exception mapper: Could not load class 'Acme\HelloBundle\Exception\MyExceptionWithASafeMessage' or the class does not extend from '\Exception'. Most probably this is a configuration problem.
Since the namespace is acme it looks like you copied some demo tutorial code and the bundle doesn't exist.
You need to create your OWN exception class extending \Exception and pass its namespace there in the yml .

Option Model_manager for ModelAutocompleteType::class in SonataAdminBundle

i am trying to upgrade my application to symfony 3. But there a deprecation notice i can't fix:
My Code with Symfony 2 :
protected function configureFormFields(FormMapper $formMapper){
->add('town', 'sonata_type_model_autocomplete', array(
'property'=>'name',
'placeholder'=>'Select one',
'label'=>'town.name,
));
}
The deprecation notice :
Accessing type "sonata_type_model_autocomplete" by its string name is
deprecated since version 2.8 and will be removed in 3.0. Use the
fully-qualified type class name
"Sonata\AdminBundle\Form\Type\ModelAutocompleteType" instead
So, to be compliant with Symfony 3 :
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType;
protected function configureFormFields(FormMapper $formMapper){
->add('town', ModelAutocompleteType::class , array(
'property'=>'name',
'placeholder'=>'Select one',
'label'=>'town.name',
'model_manager'=> null
));
}
But i get this error :
Catchable Fatal Error: Argument 1 passed to
Sonata\AdminBundle\Form\DataTransformer\ModelToIdPropertyTransformer::__construct()
must implement interface
Sonata\AdminBundle\Model\ModelManagerInterface, null given, called in
/vendor/sonata-project/admin-bundle/Form/Type/ModelAutocompleteType.php
on line 37 and defined
So instead of null, i have to pass an ModelManagerInterface object, but where i can find it ?
Thank you for reading

Overriding Registration Form (SonataUserBundle) since Symfony2 Update to 2.8

After updating symfony2 with the dependencies to 2.8 I get the following error message when trying to override the sonata user bundle registration form:
The field type "Sonata\UserBundle\Form\Type\RegistrationFormType" is not registered with the service container.
If I switch back to Symfony 2.7 everything works again.
My services.yml:
sonata.user.registration.form.type:
class: My\Bundle\Form\Type\RegistrationFormType
arguments: [ "%fos_user.model.user.class%" , "#service_container"]
tags:
- { name: form.type, alias: sonata_user_registration }
In my controller the following line triggers the error:
$form = $this->container->get( 'sonata.user.registration.form' );
Unfortunately I couldn't find any resources on this subject (i.e. if there are any changes in overriding the registration form since the latest version)
Ok, this isn't a bug, but a new feature. You have to use the build() and boot() methods in your bundle to register your FormType via FormHelper::registerFormTypeMapping.

Symfony 1.2 to 2.3 migration

I've got a pretty big Symfony 1.2 project to migrate.
First, I modified my .htaccess so I can have some pages handled by Symfony 2.
What I'd like to do, to make the migration smoother, is to be able to render some SF2 action/templates/methods/... inside SF1.
I added the autoloader to the SF1 app, so I can access to twig rendering methods and other stuff.
But how can I call a SF2 action ?
For example, if I want to migrate only the footer first, I would also need some php methods, not only rendering. That was previously in SF1 component, where should it be now ?
If you've got any suggestion about the way of migrating, don't hesitate !
EDIT 1 :
Apparently, the only way to do something like that is to render a full twig template, and/or in this template call some other partial twig templates with render(url, params).
Here is my SF1 code to be able to render twig templates :
public static function getTwig()
{
require_once __DIR__.'SF2_PATH/vendor/twig/extensions/lib/Twig/Extensions/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem( __DIR__.'SF2_PATH/sf2/src/VENDOR/BUNDLE/');
$twig = new Twig_Environment($loader, array(
'cache' => __DIR__.'SF2_PATH/sf2/app/cache/dev/twig',
));
return $twig;
}
And so :
$twig->loadTemplate('header.html.twig');
EDIT 2 :
That doesn't seem to work, if in a twig template I try to render an other one with {{render(controller('BUNDLE:CONTROLER:ACTION', {})) }} for example Twig_Error : The function "controller" does not exist. And if I try to render the url Unknown tag name "render".
I guess Symfony 2 twig functionalities are not loaded, how can I do that ?
EDIT 3 :
Ok, now I can do it, but I've got the following message...
Twig_Error_Runtime An exception has been thrown during the rendering
of a template ("Rendering a fragment can only be done when handling a
master Request.") in ...
EDIT : I solved it !
Here is my full bootstrap method to render a Twig template and be able to use some Symfony 2 functionalities, in Symfony 1.
$loader = require_once __DIR__.'/../../../sf2/app/bootstrap.php.cache';
Debug::enable();
require_once __DIR__.'/../../../sf2/app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$kernel->boot();
$kernel->getContainer()->enterScope('request');
$kernel->getContainer()->set('request', new \Symfony\Component\HttpFoundation\Request(), 'request');
$this->container = $kernel->getContainer()->get('twig');

Resources