本文整理汇总了PHP中Sonata\AdminBundle\Admin\FieldDescriptionInterface类的典型用法代码示例。如果您正苦于以下问题:PHP FieldDescriptionInterface类的具体用法?PHP FieldDescriptionInterface怎么用?PHP FieldDescriptionInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FieldDescriptionInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addFilter
/**
* @param \Sonata\AdminBundle\Datagrid\DatagridInterface $datagrid
* @param null $type
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
*/
public function addFilter(DatagridInterface $datagrid, $type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
{
if ($type == null) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
$type = $guessType->getType();
$fieldDescription->setType($type);
$options = $guessType->getOptions();
foreach ($options as $name => $value) {
if (is_array($value)) {
$fieldDescription->setOption($name, array_merge($value, $fieldDescription->getOption($name, array())));
} else {
$fieldDescription->setOption($name, $fieldDescription->getOption($name, $value));
}
}
} else {
$fieldDescription->setType($type);
}
$this->fixFieldDescription($admin, $fieldDescription);
$admin->addFilterFieldDescription($fieldDescription->getName(), $fieldDescription);
$fieldDescription->mergeOption('field_options', array('required' => false));
$filter = $this->filterFactory->create($fieldDescription->getName(), $type, $fieldDescription->getOptions());
if (false !== $filter->getLabel() && !$filter->getLabel()) {
$filter->setLabel($admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'filter', 'label'));
}
$datagrid->addFilter($filter);
}
示例2: fixFieldDescription
/**
* The method defines the correct default settings for the provided FieldDescription.
*
* {@inheritdoc}
*
* @throws \RuntimeException if the $fieldDescription does not have a type.
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
$fieldDescription->setAdmin($admin);
if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
$metadata = $admin->getModelManager()->getMetadata($admin->getClass());
// set the default field mapping
if (isset($metadata->fieldMappings[$fieldDescription->getName()])) {
$fieldDescription->setFieldMapping($metadata->fieldMappings[$fieldDescription->getName()]);
}
// set the default association mapping
if (isset($metadata->associationMappings[$fieldDescription->getName()])) {
$fieldDescription->setAssociationMapping($metadata->associationMappings[$fieldDescription->getName()]);
}
}
if (!$fieldDescription->getType()) {
throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
}
$fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
$fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
if (!$fieldDescription->getTemplate()) {
$fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType()));
if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_ONE) {
$fieldDescription->setTemplate('SonataDoctrinePhpcrAdminBundle:CRUD:show_phpcr_many_to_one.html.twig');
}
if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_MANY) {
$fieldDescription->setTemplate('SonataDoctrinePhpcrAdminBundle:CRUD:show_phpcr_many_to_many.html.twig');
}
}
switch ($fieldDescription->getMappingType()) {
case ClassMetadata::MANY_TO_ONE:
case ClassMetadata::MANY_TO_MANY:
$admin->attachAdminClass($fieldDescription);
break;
}
}
示例3: getDefaultOptions
/**
* {@inheritdoc}
*/
public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
{
$options = array();
$options['sonata_field_description'] = $fieldDescription;
if ($type == 'sonata_type_model' || $type == 'sonata_type_model_list') {
if ($fieldDescription->getOption('edit') == 'list') {
throw new \LogicException('The ``sonata_type_model`` type does not accept an ``edit`` option anymore, please review the UPGRADE-2.1.md file from the SonataAdminBundle');
}
$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
} elseif ($type == 'sonata_type_admin') {
if (!$fieldDescription->getAssociationAdmin()) {
throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity()));
}
$options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass();
$fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));
} elseif ($type == 'sonata_type_collection') {
if (!$fieldDescription->getAssociationAdmin()) {
throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity()));
}
$options['type'] = 'sonata_type_admin';
$options['modifiable'] = true;
$options['type_options'] = array('sonata_field_description' => $fieldDescription, 'data_class' => $fieldDescription->getAssociationAdmin()->getClass());
}
return $options;
}
示例4: __construct
public function __construct(FieldDescriptionInterface $fieldDescription)
{
$this->name = $fieldDescription->getName();
$this->fieldDescription = $fieldDescription;
$this->options = array_replace(
$this->getDefaultOptions(),
$this->fieldDescription->getOption('filter_options', array())
);
}
示例5: fixFieldDescription
/**
* {@inheritdoc}
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
$fieldDescription->setTemplate('YnloAdminBundle::CRUD/list_enum.html.twig');
/** @var ModelManager $modelManager */
$modelManager = $admin->getModelManager();
if (null === $fieldDescription->getOption('enum_type') && $modelManager->hasMetadata($admin->getClass())) {
$mapping = $modelManager->getMetadata($admin->getClass())->getFieldMapping($fieldDescription->getName());
$fieldDescription->setOption('enum_type', $mapping['type']);
}
}
示例6: getTemplate
/**
* @param FieldDescriptionInterface $fieldDescription
* @param string $defaultTemplate
*
* @return \Twig_TemplateInterface
*/
protected function getTemplate(FieldDescriptionInterface $fieldDescription, $defaultTemplate)
{
$templateName = $fieldDescription->getTemplate() ?: $defaultTemplate;
try {
$template = $this->environment->loadTemplate($templateName);
} catch (\Twig_Error_Loader $e) {
$template = $this->environment->loadTemplate($defaultTemplate);
}
return $template;
}
示例7: getDefaultOptions
/**
* {@inheritdoc}
*/
public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
{
$options = array();
$options['sonata_field_description'] = $fieldDescription;
if ($type == 'sonata_type_model' || $type == 'sonata_type_model_list' || $type == 'sonata_type_model_hidden') {
if ($fieldDescription->getOption('edit') == 'list') {
throw new \LogicException('The ``sonata_type_model`` type does not accept an ``edit`` option anymore, please review the UPGRADE-2.1.md file from the SonataAdminBundle');
}
$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
} elseif ($type == 'sonata_type_admin') {
if (!$fieldDescription->getAssociationAdmin()) {
throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity()));
}
if (!in_array($fieldDescription->getMappingType(), array(ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE))) {
throw new \RuntimeException(sprintf('You are trying to add `sonata_type_admin` field `%s` which is not One-To-One or Many-To-One. Maybe you want `sonata_model_list` instead?', $fieldDescription->getName()));
}
$options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass();
$fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));
} elseif ($type == 'sonata_type_collection') {
if (!$fieldDescription->getAssociationAdmin()) {
throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity()));
}
$options['type'] = 'sonata_type_admin';
$options['modifiable'] = true;
$options['type_options'] = array('sonata_field_description' => $fieldDescription, 'data_class' => $fieldDescription->getAssociationAdmin()->getClass());
}
return $options;
}
示例8: fixFieldDescription
/**
* The method defines the correct default settings for the provided FieldDescription
*
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
*
* @return void
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
$fieldDescription->setAdmin($admin);
if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName());
$fieldDescription->setParentAssociationMappings($parentAssociationMappings);
// set the default field mapping
if (isset($metadata->fieldMappings[$lastPropertyName])) {
$fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]);
}
// set the default association mapping
if (isset($metadata->associationMappings[$lastPropertyName])) {
$fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]);
}
}
if (!$fieldDescription->getType()) {
throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
}
$fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
$fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
if (!$fieldDescription->getTemplate()) {
$fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType()));
if (!$fieldDescription->getTemplate()) {
switch ($fieldDescription->getMappingType()) {
case ClassMetadataInfo::MANY_TO_ONE:
$fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_many_to_one.html.twig');
break;
case ClassMetadataInfo::ONE_TO_ONE:
$fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_one_to_one.html.twig');
break;
case ClassMetadataInfo::ONE_TO_MANY:
$fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_one_to_many.html.twig');
break;
case ClassMetadataInfo::MANY_TO_MANY:
$fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_many_to_many.html.twig');
break;
}
}
}
switch ($fieldDescription->getMappingType()) {
case ClassMetadataInfo::MANY_TO_ONE:
case ClassMetadataInfo::ONE_TO_ONE:
case ClassMetadataInfo::ONE_TO_MANY:
case ClassMetadataInfo::MANY_TO_MANY:
$admin->attachAdminClass($fieldDescription);
break;
}
}
示例9: addNewInstance
/**
* {@inheritdoc}
*/
public function addNewInstance($object, FieldDescriptionInterface $fieldDescription)
{
$instance = $fieldDescription->getAssociationAdmin()->getNewInstance();
foreach ($this->newLayoutBlockParameters as $attr => $value) {
$method = sprintf('set%s', $this->camelize($attr));
$instance->{$method}($value);
}
$mapping = $fieldDescription->getAssociationMapping();
$method = sprintf('add%s', $this->camelize($mapping['fieldName']));
if (!method_exists($object, $method)) {
$method = rtrim($method, 's');
if (!method_exists($object, $method)) {
throw new \RuntimeException(sprintf('Please add a method %s in the %s class!', $method, get_class($object)));
}
}
$object->{$method}($instance);
}
示例10: getDefaultOptions
/**
* @param $type
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @return array
*/
public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
{
$options = array();
$options['sonata_field_description'] = $fieldDescription;
if ($type == 'doctrine_phpcr_type_tree_model') {
$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
}
if ($type == 'sonata_type_model') {
$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
switch ($fieldDescription->getMappingType()) {
case ClassMetadata::ONE_TO_MANY:
case ClassMetadata::MANY_TO_MANY:
$options['multiple'] = true;
$options['parent'] = 'choice';
break;
case ClassMetadata::MANY_TO_ONE:
case ClassMetadata::ONE_TO_ONE:
break;
}
if ($fieldDescription->getOption('edit') == 'list') {
$options['parent'] = 'text';
if (!array_key_exists('required', $options)) {
$options['required'] = false;
}
}
} else {
if ($type == 'sonata_type_admin') {
// nothing here ...
$options['edit'] = 'inline';
} else {
if ($type == 'sonata_type_collection') {
$options['type'] = 'sonata_type_admin';
$options['modifiable'] = true;
$options['type_options'] = array('sonata_field_description' => $fieldDescription, 'data_class' => $fieldDescription->getAssociationAdmin()->getClass());
}
}
}
return $options;
}
示例11: fixFieldDescription
/**
* The method defines the correct default settings for the provided FieldDescription
*
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
*
* @return void
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
$fieldDescription->setAdmin($admin);
if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName());
$fieldDescription->setParentAssociationMappings($parentAssociationMappings);
// set the default field mapping
if (isset($metadata->fieldMappings[$lastPropertyName])) {
$fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]);
}
// set the default association mapping
if (isset($metadata->associationMappings[$lastPropertyName])) {
$fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]);
}
}
if (!$fieldDescription->getType()) {
throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
}
$fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
$fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
if (!$fieldDescription->getTemplate()) {
if ($fieldDescription->getType() == 'id') {
$fieldDescription->setType('string');
}
if ($fieldDescription->getType() == 'int') {
$fieldDescription->setType('integer');
}
$template = $this->getTemplate($fieldDescription->getType());
if ($template === null) {
if ($fieldDescription->getMappingType() == ClassMetadataInfo::ONE) {
$template = 'SonataDoctrineMongoDBAdminBundle:CRUD:show_mongo_one.html.twig';
} elseif ($fieldDescription->getMappingType() == ClassMetadataInfo::MANY) {
$template = 'SonataDoctrineMongoDBAdminBundle:CRUD:show_mongo_many.html.twig';
}
}
$fieldDescription->setTemplate($template);
}
if (in_array($fieldDescription->getMappingType(), array(ClassMetadataInfo::ONE, ClassMetadataInfo::MANY))) {
$admin->attachAdminClass($fieldDescription);
}
}
示例12: buildActionFieldDescription
/**
* @param FieldDescriptionInterface $fieldDescription
*
* @return FieldDescriptionInterface
*/
public function buildActionFieldDescription(FieldDescriptionInterface $fieldDescription)
{
if (null === $fieldDescription->getTemplate()) {
$fieldDescription->setTemplate('SonataAdminBundle:CRUD:list__action.html.twig');
}
if (null === $fieldDescription->getType()) {
$fieldDescription->setType('action');
}
if (null === $fieldDescription->getOption('name')) {
$fieldDescription->setOption('name', 'Action');
}
if (null === $fieldDescription->getOption('code')) {
$fieldDescription->setOption('code', 'Action');
}
if (null !== $fieldDescription->getOption('actions')) {
$actions = $fieldDescription->getOption('actions');
foreach ($actions as $k => $action) {
if (!isset($action['template'])) {
$actions[$k]['template'] = sprintf('SonataAdminBundle:CRUD:list__action_%s.html.twig', $k);
}
}
$fieldDescription->setOption('actions', $actions);
}
return $fieldDescription;
}
示例13: addFilter
/**
* @param \Sonata\AdminBundle\Datagrid\DatagridInterface $datagrid
* @param null $type
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @return \Sonata\AdminBundle\Filter\FilterInterface
*/
public function addFilter(DatagridInterface $datagrid, $type = null, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
{
if ($type == null) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName());
$type = $guessType->getType();
$fieldDescription->setType($type);
$options = $guessType->getOptions();
foreach ($options as $name => $value) {
if (is_array($value)) {
$fieldDescription->setOption($name, array_merge($value, $fieldDescription->getOption($name, array())));
} else {
$fieldDescription->setOption($name, $fieldDescription->getOption($name, $value));
}
}
} else {
$fieldDescription->setType($type);
}
$this->fixFieldDescription($admin, $fieldDescription);
$admin->addFilterFieldDescription($fieldDescription->getName(), $fieldDescription);
$fieldDescription->mergeOption('field_options', array('required' => false));
$filter = $this->filterFactory->create($fieldDescription->getName(), $type, $fieldDescription->getOptions());
$datagrid->addFilter($filter);
return $datagrid->addFilter($filter);
}
示例14: fixFieldDescription
/**
* {@inheritdoc}
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
if (null === $fieldDescription->getTemplate()) {
$fieldDescription->setTemplate('SonataAdminBundle:CRUD:list__action.html.twig');
}
if (null === $fieldDescription->getType()) {
$fieldDescription->setType('action');
}
if (null === $fieldDescription->getOption('name')) {
$fieldDescription->setOption('name', 'Action');
}
if (null === $fieldDescription->getOption('code')) {
$fieldDescription->setOption('code', 'Action');
}
if (null === $fieldDescription->getOption('header_style') && $fieldDescription->getOption('dropdown')) {
$fieldDescription->setOption('header_style', 'width:40px');
}
if (null !== $fieldDescription->getOption('actions')) {
$actions = $fieldDescription->getOption('actions');
foreach ($actions as $k => &$action) {
//only set the template if really exists
//set to default any template that not exists
if (!isset($action['template'])) {
if ($fieldDescription->getOption('dropdown')) {
$template = sprintf('SonataAdminBundle:CRUD:list__action_dropdown_%s.html.twig', $k);
} else {
$template = sprintf('SonataAdminBundle:CRUD:list__action_%s.html.twig', $k);
}
try {
$this->twig->loadTemplate($template);
} catch (\Twig_Error_Loader $e) {
if ($fieldDescription->getOption('dropdown')) {
$template = 'YnloAdminBundle::CRUD/list__action_dropdown_default.html.twig';
} else {
$template = 'YnloAdminBundle::CRUD/list__action_default.html.twig';
}
}
$action['template'] = $template;
}
//set default role
if (!isset($action['role'])) {
$role = strtoupper($k);
$action['role'] = $role === 'SHOW' ? 'VIEW' : $role;
}
//set default visibility
if (!isset($action['visible'])) {
$action['visible'] = true;
}
}
$fieldDescription->setOption('actions', $actions);
}
//hide default label
if (in_array($fieldDescription->getOption('label'), ['_action', 'Action'])) {
$fieldDescription->setOption('label', ' ');
}
return $fieldDescription;
}
示例15: getSortParameters
/**
* {@inheritdoc}
*/
public function getSortParameters(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid)
{
$values = $datagrid->getValues();
if ($fieldDescription->getName() == $values['_sort_by']->getName() || $values['_sort_by']->getName() === $fieldDescription->getOption('sortable')) {
if ($values['_sort_order'] == 'ASC') {
$values['_sort_order'] = 'DESC';
} else {
$values['_sort_order'] = 'ASC';
}
} else {
$values['_sort_order'] = 'ASC';
}
$values['_sort_by'] = is_string($fieldDescription->getOption('sortable')) ? $fieldDescription->getOption('sortable') : $fieldDescription->getName();
return array('filter' => $values);
}