我如何知道哪些选项可用作 SonataAdminBundle 中 ListMapper->add() 的第三个参数

use*_*096 4 symfony sonata-admin

我怎么知道哪些选项可用作ListMapper->add()SonataAdminBundle 中的第三个参数。(与DatagridMapper->add()和相同FormMapper->add())。

你说有一个带有选项的链接http://symfony.com/doc/current/bundles/SonataAdminBundle/reference/action_list.html#options

但这里也有一些http://symfony.com/doc/current/bundles/SonataAdminBundle/reference/action_list.html#visual-configuration

我如何知道是否有更多选项可用?如果有人指出如何从 Sonata 代码(可能是 ListMapper 类)中发现这一点,那就太完美了。

因为 fe 我想减少单元格中文本的大小,如果它太大,我不知道我是否可以使用一些第三个参数选项或者我需要覆盖模板。

Jul*_*mur 5

问题是选项存储在原生 PHP 数组中,并由模板、DoctrineORM 包等“即时”使用......因此没有简单的方法来找到所有这些的详尽列表。

但是,我找到了一个解决方案,可以列出ListMapper 的几乎所有选项(有些来自DatagridMapper,但真的很难区分它们)。

他们来了:

_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
Run Code Online (Sandbox Code Playgroud)

为了得到这个列表,我想让函数SonataAdminBundle\Admin\BaseFieldDescription::getOptions()返回一个自定义数组对象,该对象记录对issetunset、 getter 和 setter 的每次调用(带括号运算符)。我还记录了SonataAdminBundle\Admin\BaseFieldDescription::getOption($name, $default = null)调用。

代码相关:

  • 测试包\阵列测试

    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);
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • 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;
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • SonataAdminBundle\Admin\BaseFieldDescription::getOptions()

    新函数的原型:getOptions($fakeArray = true)

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

    第 129 行:

    $filter = $this->filterFactory->create($fieldDescription->getName(), $type, $fieldDescription->getOptions());
    
    Run Code Online (Sandbox Code Playgroud)

    $filter = $this->filterFactory->create($fieldDescription->getName(), $type, $fieldDescription->getOptions(false));
    
    Run Code Online (Sandbox Code Playgroud)

然后,在 sonata admin 上显示一个列表,然后运行cat /tmp/toto.txt | sort -u以获取上面的列表。

为了获得这个选项列表,我显示了管理员的SonataUserBundle列表。您可能会发现更多显示其他管理列表的选项(例如使用其他模板)。


注意:我在Symfony 2.8.11SonataAdminBundle 3.8.0SonataDoctrineORMAdminBundle 3.1.0SonataUserBundle 3.0.1 的全新安装上运行了这个。

  • 赏金了,干得好! (2认同)