How to find out which options are available as the third argument to ListMapper-> add () in SonataAdminBundle

How to find out which options are available as the 3rd argument ListMapper->add()in the SonataAdminBundle. (Same thing with DatagridMapper->add()and FormMapper->add()).

You say there is a link with options http://symfony.com/doc/current/bundles/SonataAdminBundle/reference/action_list.html#options

but there are also some http://symfony.com/doc/current/bundles/SonataAdminBundle/reference/action_list.html#visual-configuration here

How to find out if there are additional options? Great if someone points out how to find out what is from the code of the sonata (possibly of the ListMapper class).

Because fe I want to reduce the size of the text in the cell if it is too large, and I do not know if I can use the parameter of the third argument or if I need to redefine the template.

+4
source share
2 answers

The problem is that the parameters are stored in the native PHP array and are used on the fly using templates, the DoctrineORM package, etc., so there is no easy way to find an exhaustive list of all of them.

However, I found a solution for a list of almost all ListMapper parameters (some of DatagridMapper , but it is really difficult to distinguish between them).

Here they are:

_sort_order
admin_code
ajax_hidden
association_mapping
code
editable
field_mapping
field_name
field_options
field_type
format
global_search
header_class
header_style
identifier
label
mapping_type
name
operator_options
operator_type
options
parameters
parent_association_mappings
route
route.name
route.parameters
row_align
sort_field_mapping
sort_parent_association_mappings
sortable
timezone
translation_domain
virtual_field

, SonataAdminBundle\Admin\BaseFieldDescription:: getOptions() , isset, unset, getters seters ( ). SonataAdminBundle\Admin\BaseFieldDescription:: getOption ($ name, $default = null).

:

  • TestBundle\ArrayTest

    namespace TestBundle;
    
    class ArrayTest implements \ArrayAccess
    {
        private $container = array();
        private $previousOffset;
    
        public function __construct($array, $previousOffset = null) {
            $this->container = $array;
            $this->previousOffset = $previousOffset;
        }
    
        public function offsetSet($offset, $value) {
            if (is_null($offset)) {
                $this->container[] = $value;
            } else {
                $this->dump($offset);
                $this->container[$offset] = $value;
            }
        }
    
        public function offsetExists($offset) {
            $this->dump($offset);
            return isset($this->container[$offset]);
        }
    
        public function offsetUnset($offset) {
            $this->dump($offset);
            unset($this->container[$offset]);
        }
    
        public function offsetGet($offset) {
            $this->dump($offset);
            if (isset($this->container[$offset])) {
                if (is_array($this->container[$offset])) {
                    $newOffset = ($this->previousOffset ?: '').$offset.'.';
    
                    if ($newOffset === 'route.parameter.') { // because of Sonata\AdminBundle\Admin\AbstractAdmin::generateObjectUrl()
                        return $this->container[$offset];
                    }
                    return new ArrayTest($this->container[$offset], $newOffset);
                }
    
                return $this->container[$offset];
            }
            return null;
        }
    
        private function dump($offset)
        {
            $offset = ($this->previousOffset ?: '').$offset;
            file_put_contents("/tmp/toto.txt", $offset."\n", FILE_APPEND);
        }
    }
    
  • SonataAdminBundle\Admin\BaseFieldDescription:: getOption ($ name, $default = null)

    public function getOption($name, $default = null)
    {
        file_put_contents("/tmp/toto.txt", $name."\n", FILE_APPEND);
        return isset($this->options[$name]) ? $this->options[$name] : $default;
    }
    
  • SonataAdminBundle\Admin\BaseFieldDescription:: getOptions()

    : getOptions ($ fakeArray = true)

    public function getOptions($fakeArray = true)
    {
        if ($fakeArray) {
            return new \TestBundle\ArrayTest($this->options);
        }
    
        return $this->options;
    }
    
  • \DoctrineORMAdminBundle\Builder\DatagridBuilder:: addFilter (DatagridInterface $datagrid, $type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)

    129:

    $filter = $this->filterFactory->create($fieldDescription->getName(), $type, $fieldDescription->getOptions());
    

    $filter = $this->filterFactory->create($fieldDescription->getName(), $type, $fieldDescription->getOptions(false));
    

cat /tmp/toto.txt | sort -u, .

, SonataUserBundle. , (, ).


N.B.: Symfony 2.8.11, SonataAdminBundle 3.8.0, SonataDoctrineORMAdminBundle 3.1.0 SonataUserBundle 3.0.1.

+3

Bundle, !
, :

  • link_parameters

: Sonata\AdminBundle\Admin\BaseFieldDescription:: setOptions ( $)

:

  ->add('_action','actions',array(
                                  'actions'=>array(
                                         'view'=>array(),
                                         'edit'=>array(),
                                         'delete'=>array()
                                         )
                                  )
        )

SonataAdmin, , .

:

 ->add('first_name', null,array(
       'template'=>'AppBundle:User:_partial_with_some_template.html.twig',)
       )

, !:)
!

+1

Source: https://habr.com/ru/post/1659809/


All Articles