我怎么知道ListMapper->add()
SonataAdminBundle中的第3个参数可以使用哪些选项。(与DatagridMapper->add()
和相同FormMapper->add()
)。
您说有一个带有选项的链接http://symfony.com/doc/current/bundles/SonataAdminBundle/reference/action_list.html#options
我怎么知道是否还有更多选择?完美的是,如果有人指出如何从Sonata代码中发现它(也许是ListMapper类)。
因为fe我想减小单元格中文本的大小(如果太大),而且我不知道是否可以使用某些第3个参数选项,或者是否需要覆盖模板。
问题在于选项存储在本地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
为了获得此列表,我想到了使函数SonataAdminBundle \ Admin \ BaseFieldDescription :: getOptions()返回一个自定义数组对象,该对象记录对isset,unset,getters和setters(带有方括号运算符)的每次调用。我还记录了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;
}
Sonata \ 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));
然后,在sonata admin上显示一个列表,然后运行cat /tmp/toto.txt | sort -u
以获取上面的列表。
为了获得此选项列表,我显示了SonataUserBundle的管理员列表。您可能会发现显示其他管理列表的更多选项(例如,使用其他模板)。
注意:我在Symfony 2.8.11,SonataAdminBundle 3.8.0,SonataDoctrineORMAdminBundle 3.1.0和SonataUserBundle 3.0.1的全新安装上运行了此程序。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句