Sonata Admin overrides layout template per one Admin - symfony

I try to override layout template in Sonata Admin. I did all steps founded in official documentation, but my changes don`t work.
I did:
Copied from vendor appropriate template (standard_layout.html.twig) to app/Resources/SonataAdminBundle/views/. I will check if I override here template my changes applied to all of Admins in project (I want have this change only in one Admin)
In next step I created new file in my Bundle (Name/InfoBundle/Resources/views/JobOffer) and add there my custom template: findCandidate.html.twig. Below is content of this file:
https://gist.github.com/anonymous/5f4780a1ae8d7329cd91
Added to bundle service:
name_info.admin.offers:
class: Name\InfoBundle\Admin\JobOfferAdmin
tags:
- {name: sonata.admin, manager_type: orm, group: Info, label: Job offers}
arguments: [~, Name\Info\Entity\JobOffer, NameInfoBundle:JobOffer]
calls:
- [ setTemplate, [findCandidate, NameInfoBundle:JobOffer:findCandidate.html.twig]]
After that my changes are not applied. So probably I made mistake in services or maybe I have to call this template also in controller? I am not sure where I make mistake. Could anyone help me?

Probably you mistyped a template placeholder in setTemplate function.
Try to set it like:
calls:
- [setTemplate, [layout, NameInfoBundle:JobOffer:findCandidate.html.twig]]
It will change a standard_layout only for the selected admin.

Related

Sylius: How to reference your own twig template in a grid?

This is not a duplicate of e.g. Referencing a template in Twig / Symfony2 because creating bundles as applications is deprecated/not recommended anymore and therefore the answer is not applicable anymore. How do I reference my own template in a Sylius grid?
What I tried:
1.
options:
template: "#App/Order/Grid/Field/channel.html.twig"
2.
options:
template: ":Order/Grid/Field:channel.html.twig"
3.
options:
template: "templates/Order/Grid/Field/channel.html.twig"
4.
options:
template: "Order/Grid/Field/channel.html.twig"
(I tried some of these on the basis of the documentation: https://docs.sylius.com/en/1.6/components_and_bundles/bundles/SyliusGridBundle/field_types.html#twig-twig , https://docs.sylius.com/en/1.6/components_and_bundles/bundles/SyliusGridBundle/your_first_grid.html)
In all cases it says the template was not found. Any ideas?
How do you create grid or customize them? For example, I am trying to customize Admin > Catalog > Options grid, so by this tutorial put these lines at the end of config/packages/_sylius.yaml file:
sylius_grid:
grids:
sylius_admin_product_option:
fields:
name:
type: twig
options:
template: "Grid/mytemplate.html.twig"
Secondly, I create folder "Order" in /templates, then "Grid" folder in "Order" dir, and then folder "Field" in "Grid" directory. There I create file "mytemplate.html.twig" with any content. Did you tried similar steps?

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

Override view view field twig drupal 8

I have to override this template for my view:
views-view-fields.html.twig
My view name: banner_bim
My view block name: Block_1
I tried with:
views-view-field--banner_bim.html.twig
views-view-field--banner_bim--page.html.twig
views-view-field--banner-bim.html.twig
views-view-field--banner-bim--page.html.twig
None of these templates override base field template.
Any idea?
The correct one was:
views-view-field--banner_bim.html.twig
The problem was not the name of the file, but the cache.
I deleted the "Render cache" but it was necessary to clear the entire cache to see the change.

Custom block service not found by Sonata

I am having a weird situation which has halted my progress for the second day now and I am almost going bald from pulling my hair on this. I have a custom block on the sonata admin dashboard which is not being found when I try to load the page.
I have gone over the configuration a couple of times and maybe I am missing something which an extra pair of eyes may be able to spot which is why I am posting this question here.
I have built my block as below and saved it under src\AppBundle\Block\NumbersBlockService.php
namespace AppBundle\Block;
use Symfony\Component\HttpFoundation\Response;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\BlockBundle\Block\BaseBlockService;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Doctrine\ORM\Query\ResultSetMapping;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use DoctrineExtensions\Query\Mysql;
class NumbersBlockService extends BaseBlockService
{
......
}
Then defined my service in the service.yml file as below:
sonata.block.service.topnumbers:
class: AppBundle\Block\NumbersBlockService
arguments:
- sonata.block.service.topnumbers
- "#templating"
- "#doctrine.orm.entity_manager"
- "#security.token_storage"
tags:
- { name: sonata.block }
My config.yml file includes the block like this
sonata_block:
default_contexts: [cms]
blocks:
sonata.user.block.menu: # used to display the menu in profile pages
sonata.user.block.account: # used to display menu option (login option)
sonata.block.service.text: # used to if you plan to use Sonata user routes
sonata.block.service.topnumbers:
and finally, I position the block on top with the line below
sonata_admin:
dashboard:
blocks:
- { position: top, type: sonata.block.service.topnumbers, class: col-md-12}
I have checked the tutorial on creating a custom block here https://sonata-project.org/bundles/block/master/doc/reference/your_first_block.html and everything seems to check out but I still get the following error below:
An exception has been thrown during the rendering of a template ("The block type "sonata.block.service.topnumbers" does not exist") in SonataAdminBundle:Core:dashboard.html.twig at line 60.
Someone please help put me out of my misery. Thanks in advance

Symfony CMF BlockBundle default admin can't change parent

With the default admin classes for the BlockBundle (1.0.*) in Symfony CMF, I am unable to modify the "parent" of a block.
The parent filed is disabled (both when adding and editing), but always shows "/cms/content".
I would like to just use the admin classes and be able to set the parent of a block (particularly to setup some container blocks with content).
Why is it disabled? Do I need some common root for blocks to get it to work? If I tried to create my own admin class, I'm not sure what to do because the admin class does add the "parent" field the same way I would.
I suspect you have a javascript issue with your installation. Did the installation finish successfully, and are you accessing the site through app_dev.php or did run all the composer commands listed in the setup?
You should have a tree of documents above that field with the path. Have a look at the sandbox demo install:
http://cmf.liip.ch/en/admin/cmf/block/simpleblock/cms/content/home/additionalInfoBlock/child1/edit
I was missing the proper Sonata admin configuration to allow this. Thanks dbu for pointing out that it works in the sandbox.
sonata_doctrine_phpcr_admin:
document_tree:
...
Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\ReferenceBlock:
valid_children: []
Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\ActionBlock:
valid_children: []
Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\SimpleBlock:
valid_children: []
Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\SlideshowBlock:
valid_children:
- Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\ImagineBlock
Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\ImagineBlock:
valid_children: []
Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\RssBlock:
valid_children: []
Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\ContainerBlock:
valid_children:
- Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\SimpleBlock
- Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\ContainerBlock
- Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\ReferenceBlock
- Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\ActionBlock
- Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\SlideshowBlock
- Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\RssBlock
...

Resources