Comments (13)
https://github.com/sonata-project/SonataAdminBundle/blob/4.x/src/Datagrid/ListMapper.php#L193
Might be interesting to add docs explaining how to use it then
from sonatapagebundle.
In this case if I want to overwrite the PageAdmin
I need to do like this right?
<?php
namespace App\Admin;
use Knp\Menu\ItemInterface;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Sonata\AdminBundle\Show\ShowMapper;
class PageAdmin extends AbstractAdmin
{
private AdminInterface $admin;
public function __construct(AbstractAdmin $admin)
{
parent::__construct();
$this->admin = $admin;
}
protected function configureRoutes(RouteCollectionInterface $collection): void
{
$this->admin->configureRoutes($collection);
}
protected function preUpdate(object $object): void
{
$this->admin->preUpdate($object);
}
protected function prePersist(object $object): void
{
$this->admin->prePersist($object);
}
protected function getAccessMapping(): array
{
return $this->admin->getAccessMapping();
}
protected function configureBatchActions(array $actions): array
{
return $this->admin->configureBatchActions($actions);
}
protected function alterNewInstance(object $object): void
{
$this->admin->alterNewInstance($object);
}
protected function configurePersistentParameters(): array
{
return $this->admin->configurePersistentParameters();
}
protected function configureShowFields(ShowMapper $show): void
{
$this->admin->configureShowFields($show);
}
protected function configureListFields(ListMapper $list): void
{
$this->admin->configureListFields($list);
}
protected function configureDatagridFilters(DatagridMapper $filter): void
{
$this->admin->configureDatagridFilters($filter);
}
protected function configureFormFields(FormMapper $form): void
{
$this->admin->configureFormFields($form);
}
protected function configureTabMenu(ItemInterface $menu, string $action, ?AdminInterface $childAdmin = null): void
{
$this->admin->configureTabMenu($menu, $action, $childAdmin);
}
}
App\Admin\PageAdmin:
decorates: sonata.page.admin.page
arguments: [ '@App\Admin\PageAdmin.inner' ]
tags:
- {name: 'sonata.admin', model_class: 'App\Entity\SonataPagePage', controller: 'sonata.page.controller.admin.page', manager_type: 'orm', group: 'sonata_page', translation_domain: 'SonataPageBundle', label: 'page', label_translator_strategy: 'sonata.admin.label.strategy.underscore', icon: 'fa fa-sitemap' }
from sonatapagebundle.
When I try to decorate the admin as I did above, I got this exception :'(
InvalidArgumentException:
Template named "tree" doesn't exist.
at vendor/sonata-project/admin-bundle/src/Templating/AbstractTemplateRegistry.php:47
at Sonata\AdminBundle\Templating\AbstractTemplateRegistry->getTemplate('tree')
(vendor/sonata-project/page-bundle/src/Controller/PageAdminController.php:122)
at Sonata\PageBundle\Controller\PageAdminController->treeAction(object(Request))
(vendor/symfony/http-kernel/HttpKernel.php:153)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
(vendor/symfony/http-kernel/HttpKernel.php:75)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
(vendor/symfony/http-kernel/Kernel.php:202)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
(public/index.php:25)
from sonatapagebundle.
When I try to decorate the admin as I did above, I got this exception :'(
InvalidArgumentException: Template named "tree" doesn't exist. at vendor/sonata-project/admin-bundle/src/Templating/AbstractTemplateRegistry.php:47 at Sonata\AdminBundle\Templating\AbstractTemplateRegistry->getTemplate('tree') (vendor/sonata-project/page-bundle/src/Controller/PageAdminController.php:122) at Sonata\PageBundle\Controller\PageAdminController->treeAction(object(Request)) (vendor/symfony/http-kernel/HttpKernel.php:153) at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1) (vendor/symfony/http-kernel/HttpKernel.php:75) at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true) (vendor/symfony/http-kernel/Kernel.php:202) at Symfony\Component\HttpKernel\Kernel->handle(object(Request)) (public/index.php:25)
It's because the template is automatically injected for the admin
https://github.com/sonata-project/SonataPageBundle/blob/4.x/src/DependencyInjection/SonataPageExtension.php#L225
would be interesting to see if it's possible to do the same for decorated services.
from sonatapagebundle.
hmmmm ok, I'll check :D
from sonatapagebundle.
Hey @VincentLanglet is there a other solution But I don't know if it's ok
App\Admin\PageAdmin:
decorates: sonata.page.admin.page
arguments:
- '@App\Admin\PageAdmin.inner'
+ calls:
+ - setTemplate: ['tree', '@@SonataPage/PageAdmin/tree.html.twig']
tags:
- {name: 'sonata.admin', model_class: 'App\Entity\SonataPagePage', controller: 'sonata.page.controller.admin.page', manager_type: 'orm', group: 'sonata_page', translation_domain: 'SonataPageBundle', label: 'page', label_translator_strategy: 'sonata.admin.label.strategy.underscore', icon: 'fa fa-sitemap' }
I found others PR related with it, using a new tag
sonata-project/SonataAdminBundle#6566
sonata-project/SonataAdminBundle#6766
But it's not really clean how I can use it :/
I tested something like this
tags:
- {name: sonata.template_registry, type: show, template: '@@FooAdmin/CRUD/show.html.twig'}
But it doesn't work, do you have any idea how could I use it?
from sonatapagebundle.
Hey @VincentLanglet is there a other solution But I don't know if it's ok
Sure it can be done with the configuration, but you shouldn't have to know every templates to add in the configuration.
Especially one day if you want to change the tree template, you'll have to update the sonata page config and all of your admins.
I would expect something from the config here
https://github.com/sonata-project/SonataPageBundle/blob/4.x/src/DependencyInjection/SonataPageExtension.php#L223-L230
to do the job.
$container->getDefinition('sonata.page.admin.page');
is done,
I dunno if we can also get the definition of all the service which decorate this one in order to add the setTemplate call too.
from sonatapagebundle.
but you shouldn't have to know every templates to add in the configuration.
That's true
from sonatapagebundle.
I know it's a huge change to do in 4.x, But what do you think we split the admin in small piece of code?
for example, we extract the methods from the PageAdmin
to small classes/interfaces and inject it in constructor like
https://github.com/sonata-project/SonataPageBundle/blob/4.x/src/Admin/PageAdmin.php
final class PageAdmin extends AbstractAdmin
{
public function __construct(private AdminListFields $adminListFields) {}
....
protected function configureListFields(ListMapper $list): void
{
$this->adminListFields-> configureListFields($list);
}
}
interface AdminListFields
{
public function configureListFields(ListMapper $list): void;
}
final class PageAdminListFields implements AdminListFields
{
public function configureListFields(ListMapper $list): void
{
$list
->add('hybrid', null, ['template' => '@SonataPage/PageAdmin/field_hybrid.html.twig'])
->addIdentifier('name')
->add('type')
->add('pageAlias')
->add('site', null, [
'sortable' => 'site.name',
])
->add('decorate', null, ['editable' => true])
->add('enabled', null, ['editable' => true])
->add('edited', null, ['editable' => true])
->add(ListMapper::NAME_ACTIONS, ListMapper::TYPE_ACTIONS, [
'translation_domain' => 'SonataAdminBundle',
'actions' => [
'edit' => [],
],
]);
}
}
This way you just need to decorate/customize what is really necessary, and you don't need to implements too many methods that you don't want to touch like in the current solution: #1639 (comment)
in this case I will decorate like this
#[AsDecorator(decorates: PageAdminListFields::class)]
class YourCustomPageAdminListFields implements AdminListFields
{
public function __construct(#[MapDecorated] private AdminListFields $currentPageAdminListFields) {}
public function configureListFields(ListMapper $list): void
{
$this->currentPageAdminListFields-> configureListFields($list);
$list->add('YourCustomField');
}
}
https://symfony.com/doc/current/service_container/service_decoration.html
@VincentLanglet @jordisala1991
from sonatapagebundle.
I know it's a huge change to do in 4.x, But what do you think we split the admin in small piece of code?
for example, we extract the methods from the
PageAdmin
to small classes/interfaces and inject it in constructor likehttps://github.com/sonata-project/SonataPageBundle/blob/4.x/src/Admin/PageAdmin.php
final class PageAdmin extends AbstractAdmin { public function __construct(private AdminListFields $adminListFields) {} .... protected function configureListFields(ListMapper $list): void { $this->adminListFields-> configureListFields($list); } }
interface AdminListFields { public function configureListFields(ListMapper $list): void; } final class PageAdminListFields implements AdminListFields { public function configureListFields(ListMapper $list): void { $list ->add('hybrid', null, ['template' => '@SonataPage/PageAdmin/field_hybrid.html.twig']) ->addIdentifier('name') ->add('type') ->add('pageAlias') ->add('site', null, [ 'sortable' => 'site.name', ]) ->add('decorate', null, ['editable' => true]) ->add('enabled', null, ['editable' => true]) ->add('edited', null, ['editable' => true]) ->add(ListMapper::NAME_ACTIONS, ListMapper::TYPE_ACTIONS, [ 'translation_domain' => 'SonataAdminBundle', 'actions' => [ 'edit' => [], ], ]); } }
This way you just need to decorate/customize what is really necessary, and you don't need to implements too many methods that you don't want to touch like in the current solution: #1639 (comment)
in this case I will decorate like this
#[AsDecorator(decorates: PageAdminListFields::class)] class YourCustomPageAdminListFields implements AdminListFields { public function __construct(#[MapDecorated] private AdminListFields $currentPageAdminListFields) {} public function configureListFields(ListMapper $list): void { $this->currentPageAdminListFields-> configureListFields($list); $list->add('YourCustomField'); } }
https://symfony.com/doc/current/service_container/service_decoration.html
Extension works better then my suggestion :D
I'll test that :)
from sonatapagebundle.
Using extension works!
<?php
namespace App\Admin\Extension;
use Sonata\AdminBundle\Admin\AbstractAdminExtension;
use Sonata\AdminBundle\Datagrid\ListMapper;
class PageAdminExtension extends AbstractAdminExtension
{
public function configureListFields(ListMapper $list): void
{
$list->add('id');
}
}
But it added the fields in the end of the list like this
are there anyway to put the field in the begin of table
from sonatapagebundle.
are there anyway to put the field in the begin of table
You can play with the reorder method
from sonatapagebundle.
I didn't find anything in sonata docs about reorder
method 👀
from sonatapagebundle.
Related Issues (20)
- [BUG] Composer (Compose page blocks) gives incorrect position to new created block after deleting few of them HOT 2
- [4.x] doctrine extension version is wrong? HOT 2
- [4.x] Recipe is broken? HOT 6
- Page type filter not working HOT 5
- CmsPageRouter not working
- The SiteAdmin doesn't honor admin option "list_action_button_content" HOT 5
- CmsManagerSelector.isEditor always returns false HOT 2
- Remove Twig form_themes HOT 1
- Removing a page doesn't work from the edit route (works using batch delete) HOT 6
- Switch cocur/slugify to symfony/string HOT 3
- Fix pipeline TransformerInterface HOT 15
- [Model/Page] Remove nullable return for methods that is required HOT 3
- Web profiler not working after runtime added HOT 14
- Decorate `BlockAdmin`, `SnapshotAdmin` and `CreateSnapshotService` HOT 6
- View page button in PageAdmin with multisite HOT 3
- Unable update deprecated RequestFactory::createFromGlobals('host_with_path'); in index.php HOT 16
- Undefined property SonataPageBlock::$lazyObjectState HOT 21
- Add sonata_page twig extension HOT 4
- A circular reference has been detected when serializing the object of class when saving snapshot HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sonatapagebundle.