我怎么知道 SonataAdminBundle 中 ListMapper->add() 的第三个参数有哪些选项可用
How do I know what options are available as 3rd argument of ListMapper->add() in SonataAdminBundle
我怎么知道 SonataAdminBundle 中 ListMapper->add()
的第三个参数有哪些选项可用。 (与 DatagridMapper->add()
和 FormMapper->add()
相同)。
你说有一个 link 选项 http://symfony.com/doc/current/bundles/SonataAdminBundle/reference/action_list.html#options
我怎么知道是否有更多选项可用?如果有人指出如何从奏鸣曲代码(也许是 ListMapper class)中发现它,那就太完美了。
因为f.e。如果单元格中的文本太大,我想减小它的大小,我不知道我是否可以使用某些第三个参数选项或者我需要覆盖模板。
在 Sonata Bundle 代码中进行一些搜索后,不在文档中!
我认为您有以下选择:
- 类型
- 模板
- 帮助
- 占位符
- link_parameters
签入:Sonata\AdminBundle\Admin\BaseFieldDescription::setOptions(array $options)
您可以像这样一次完成所有操作:
->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',)
)
希望对您有所帮助! :)
玩得开心!
问题是选项存储在原生PHP数组中并被模板使用"on-the-fly" , DoctrineORM bundle, 等等...所以没有简单的方法可以找到所有这些的详尽列表。
但是,我找到了一个解决方案来列出 几乎 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() returns 成为一个自定义数组对象,记录每个调用 isset、unset、getter 和 setter(带括号运算符)。我还记录了 SonataAdminBundle\Admin\BaseFieldDescription::getOption($name, $default = null) calls.
代码相关:
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 的管理员列表。您可能会发现更多显示其他管理员列表的选项(例如使用其他模板)。
N.B.:我运行这是在干净安装Symfony 2.8.11,SonataAdminBundle 3.8.0、SonataDoctrineORMAdminBundle 3.1.0 和 SonataUserBundle 3.0.1.
我怎么知道 SonataAdminBundle 中 ListMapper->add()
的第三个参数有哪些选项可用。 (与 DatagridMapper->add()
和 FormMapper->add()
相同)。
你说有一个 link 选项 http://symfony.com/doc/current/bundles/SonataAdminBundle/reference/action_list.html#options
我怎么知道是否有更多选项可用?如果有人指出如何从奏鸣曲代码(也许是 ListMapper class)中发现它,那就太完美了。
因为f.e。如果单元格中的文本太大,我想减小它的大小,我不知道我是否可以使用某些第三个参数选项或者我需要覆盖模板。
在 Sonata Bundle 代码中进行一些搜索后,不在文档中!
我认为您有以下选择:
- 类型
- 模板
- 帮助
- 占位符
- link_parameters
签入:Sonata\AdminBundle\Admin\BaseFieldDescription::setOptions(array $options)
您可以像这样一次完成所有操作:
->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',)
)
希望对您有所帮助! :)
玩得开心!
问题是选项存储在原生PHP数组中并被模板使用"on-the-fly" , DoctrineORM bundle, 等等...所以没有简单的方法可以找到所有这些的详尽列表。
但是,我找到了一个解决方案来列出 几乎 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() returns 成为一个自定义数组对象,记录每个调用 isset、unset、getter 和 setter(带括号运算符)。我还记录了 SonataAdminBundle\Admin\BaseFieldDescription::getOption($name, $default = null) calls.
代码相关:
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 的管理员列表。您可能会发现更多显示其他管理员列表的选项(例如使用其他模板)。
N.B.:我运行这是在干净安装Symfony 2.8.11,SonataAdminBundle 3.8.0、SonataDoctrineORMAdminBundle 3.1.0 和 SonataUserBundle 3.0.1.