sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

Configuration or Admin Class option to enable / disable mosaic list mode #2551

Closed webdevilopers closed 8 years ago

webdevilopers commented 10 years ago

Related to my question here: https://github.com/sonata-project/SonataAdminBundle/issues/2461#issuecomment-60731284

there seems to be no option (at least not documented yet in http://www.sonata-project.org/bundles/admin/master/doc/cookbook/recipe_customizing_a_mosaic_list.html) to disable the mosaic list view globally (except overriding the template) or oer Admin Class.

Are these options of interest?

soullivaneuh commented 9 years ago

Also interested.

Is mosaic disabled global option already present for now? And per class?

For the moment, I found an ugly (for my opinion) method to disable mosoaic on one admin class:

    /**
     * @param ListMapper $listMapper
     */
    protected function configureListFields(ListMapper $listMapper)
    {
        unset($this->listModes['mosaic']);

        $listMapper
            // [...]
        ;
    }

But I have 49 admin's classes on my project, It will be very painful to add this on each class.

webdevilopers commented 9 years ago

@rande mentioned it on the 2.4 wish list under "Mozaic view list" https://github.com/sonata-project/SonataAdminBundle/issues/2406 @pulzarraider has tagged this issue for that milestone.

Not sure if this means that a configurable option will be available.

But there were some changes on the layout: https://github.com/sonata-project/SonataAdminBundle/issues/1723

OskarStark commented 9 years ago

i added a custom BaseAdmin and added this method:

{
    /**
     * @param ListMapper $listMapper
     */
    protected function configureListFields(ListMapper $listMapper)
    {
        unset($this->listModes['mosaic']);
    }

and in my Admin:

    /**
     * @param ListMapper $listMapper
     */
    protected function configureListFields(ListMapper $listMapper)
    {
        parent::configureListFields($listMapper);
        // ...
    }

but if you manipulate the url... you are allowed to visit the mosaic view...

clytemnestra commented 9 years ago

Any update on this? Manipulating the URL still works.

linkito87 commented 9 years ago

Again.... Any update?

For now, i have a javascript extending standard_layout.html.twig with:

$(".fa.fa-th-large.fa-fw").parent().parent().remove();

But please, any better solution?

clytemnestra commented 9 years ago

I think

$this->setListMode('list');

could be a temporary solution. This disables any other mode(like tree) or custom ones, if you've made any. How's that?

krioo commented 8 years ago

@OskarStark or you can do it right in the constructor of BaseAdmin:

public function __construct($code, $class, $baseControllerName)
{
    parent::__construct($code, $class, $baseControllerName);

    // Disable mosaic list mode
    unset($this->listModes['mosaic']);
}
OskarStark commented 8 years ago

this is a better solution by far @kriodev 👍

but anyway we should add a configuration option, maybe it would be better to deactivate it and make it opt-in

soullivaneuh commented 8 years ago

@OskarStark or you can do it right in the constructor of BaseAdmin:

@kriodev Maybe something can be done on the AdminExtension too.

krioo commented 8 years ago

@OskarStark configuration option would be perfect indeed!

@Soullivaneuh BaseAdmin is part of my bundle and it extends \Sonata\AdminBundle\Admin\Admin if that is what you meant.

soullivaneuh commented 8 years ago

@kriodev No I'm just saying that you may do something on class extending AdminExtension to avoid repetition.

krioo commented 8 years ago

@OskarStark @Soullivaneuh I just realized that visibility of listModes property is set to protected, so there is even more elegant solution for BaseAdmin class without extending the constructor:

use Sonata\AdminBundle\Admin\Admin;

class BaseAdmin extends Admin
{
    protected $listModes = [
        'list' => array(
            'class' => 'fa fa-list fa-fw',
        ),
    ];
}
tim96 commented 8 years ago

@Soullivaneuh @OskarStark hello. I created a small PR #3822 to add parameter in configuration file to show/hide mosaic button.