Default custom route on SonataORMAdmin list view - symfony

Refering to the SoanataORMAdmin's documentation, it is possible to change the default route of object links.
By default, it's the edit route. I don't want it at all and need to change it to show without override all my admin class.
What is the better way to override the default route ?
Thanks.

The best way is to override the twig by extending SonataORMAdminBundle.
To do this, you need to :
install SonataEasyGenerate Bundle
use the command php app/console sonata:easy-extends:generate SonataORMAdminBundle
this will generate a new repository Application/Sonata/DoctrineORMAdminBundle
Then you need to go to Application/Sonata/DoctrineORMAdminBundle/Ressources/views/CRUD and paste the twigs from the vendors (vendor/Sonata/DoctrineORMAdminBundle/Ressources/views/CRUD)
Finally, change the links in the twigs.
For example, if you want to call the list view to call the show route for a many to one relation :
edit list_orm_many_to_one.html.twig to call generateObjectUrl('show',...) instead of generateObjectUrl('edit',...)
Hope this will help.

Related

New export action for pages in magnolia cms

I need to create a new export action for the page app in magnolia cms that would always export selected page elements to a YAML file.
I would like to override the class definition and the dialog definition for the existing export action since I do not need a dialog that lets me select YAML or XML. It will always be YAML in my case.
I setup a new Maven module and created a new action for the Page app.
How do I configure a custom class for this action? How do I get the current context of the page in my class?
You have to remove the dialog attached to the action first. If you plan to have a custom action then simply do not configure one. We already have two actions for those two cases. If you are interested in YAML export use the following: info.magnolia.ui.framework.action.ExportYamlAction
My action configuration for exportYAML2
My actionbar configuration for exportYAML
* repeating the content of the comment below since I could not post pictures in the comment *
I configured two actions for exporting the YAML configuration of the node.
The second one (exportYAML2) using ExportYamlActionDefinition does not show up in the actionbar for the page even though I added it as an item.
Is there anything else I need to configure for it?
exportYaml with class info.magnolia.ui.framework.action.OpenExportDialogActionDefinition works. exportYaml2 with class info.magnolia.ui.framework.action.ExportYamlActionDefinition doesn't work. Availability for it is set to info.magnolia.ui.framework.availability.IsNotDeletedRule.
It is solved.
There are two things I needed to configure for a custom action in the pages app in magnolia.
configuration app modules>pages>apps>pages>subApps>browser>actions>MyAction withe class={custom or common class from https://documentation.magnolia-cms.com/display/DOCS61/Action+definition }
modules>pages>apps>pages>subApps>browser>actionbar>sections>pageActions>groups>uniquegroupname>items-MyAction

EasyAdmin Using your Own Templates Problem

I am trying to override "new" template for EasyAdmin but system ignores template code.
Here is the relevant part of easy_admin.yaml
entities:
# List the entity class name you want to manage
Places:
class: App\Entity\Places
templates:
list: 'asdfasdf'
As you see, value of list attribute is invalid but system ignores it and works without error and i can not override the template.
Do you have a suggestion?
So, as I mentioned in the comment - for some reason easyadmin doesn't give any errors if specified template doesn't exists. So, you just need to place your new template in templates folder, in example, templates/admin/listPlaces.html.twig and then specify correct path in easyadmin's config file, in example:
entities:
Places:
class: App\Entity\Places
templates:
list: 'admin/listPlaces.html.twig'
If you use EasyAdmin 3.x, for that you can overwrite a specific template specifying it in your entity's Controller or you can create your own folder structures like symfony does.
In this example I am overwriting only the edit template for my 'studient' entity, if you want to change all the edits of your project you must do so by creating the folder structure as symfony does.
public function configureCrud(): Crud
{
return Crud::new()
->overrideTemplate('crud/edit', 'studient/edit.html.twig')
;
}
You can even combine both methods. Suppose that in addition to modifying only the template 'edit' of studient you want to modify the way in which easyadmin displays the flash messages for that you only have to create this structure in your templates folder: "templates\bundles\EasyAdminBundles\flash_messages.html.twig"
I leave the link with the documentation for EasyAdmin 3.x
overriding-templates

Symfony2 - Call the same getRepository in all controller actions

I'm using a repository in Symfony2-controller like this:
$blog = $em->getRepository('BlogBloggerBundle:BlogData')->getBlogData($id);
Before I call it into the twig view through an array.
All works right but the issue is that it make up a footer menu, then, i should call it almost in every action which i need.
How i can call it from a "common" repository every time which i need?
Create a view reponse listener registering a twig variable and add the repository call in there...
... or create a twig extension exposing the data received from the repository as a global twig variable.
... or (my preferred choice) create a controller dedicated to rendering the footer and include the footer like this:
{{ render(controller('Bundle:controller:action')) }}
Read more about rendering fragments in this blog post on the symfony homepage.
FYI Official documentation about embedding controllers : http://symfony.com/doc/current/book/templating.html#embedding-controllers

symfony2: customizing bundles overriding directory

For overriding Bundles template , at the first level Symfony search inside app/Resources/AcmeSampleBundle directory if it doesn't exist then it read template from src/Acme/SampleBundle.
Is there any way for customizing first level directory? for example : app/Resources/AllBundles/
You could use your custom template locator by change service 'templating.locator'. Let check how LiipThemeBundle do this.

Rewrite default Drupal view programmatically

Say we have a defaul view (i.e hardcoded), provided by Views module , for example "taxonomy/term/%"
Now, I'd like to make some modification to that view programmatically, through an installation profile
Normally I use Features module for such work, but Features does not support default views.
Please advise how to do that.
Thanks!
Use hook_views_default_views_alter
function MODULE_views_default_views_alter(&$views) {
if (isset($views['taxonomy_term'])) {
$views['taxonomy_term']->set_display('default');
$views['taxonomy_term']->display_handler->set_option('title', 'Categories');
}
}
You should use the Views theme information. There is a link you can use to find out what you should name your views (Its called "Theme Information") copy the name of the particular part of the view you would like to hardcode and paste it as a new file in your template's directory. You can use a folder (I usually name it views) to separate these files from others in the template. You'll need to refresh your cache to see the changes once you've created the new template file(s).
Yes, use hook_views_default_views_alter()
Here's a good example:
enter link description here

Resources