本文整理汇总了PHP中Sonata\AdminBundle\Admin\FieldDescriptionInterface::getValue方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldDescriptionInterface::getValue方法的具体用法?PHP FieldDescriptionInterface::getValue怎么用?PHP FieldDescriptionInterface::getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\AdminBundle\Admin\FieldDescriptionInterface
的用法示例。
在下文中一共展示了FieldDescriptionInterface::getValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getValueFromFieldDescription
/**
* return the value related to FieldDescription, if the associated object does no
* exists => a temporary one is created
*
* @param object $object
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @param array $params
* @return mixed
*/
public function getValueFromFieldDescription($object, FieldDescriptionInterface $fieldDescription, array $params = array())
{
if (isset($params['loop']) && $object instanceof \ArrayAccess) {
throw new \RuntimeException('remove the loop requirement');
}
$value = $fieldDescription->getValue($object);
// no value defined, check if the fieldDescription point to an association
// if so, create an empty object instance
// fixme: not sure this is the best place to do that
if (!$value && $fieldDescription->getAssociationAdmin()) {
$value = $fieldDescription->getAssociationAdmin()->getNewInstance();
}
return $value;
}
示例2: getValueFromFieldDescription
/**
* return the value related to FieldDescription, if the associated object does no
* exists => a temporary one is created.
*
* @param object $object
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
*
* @return mixed
*/
public function getValueFromFieldDescription($object, FieldDescriptionInterface $fieldDescription)
{
$value = null;
if (!$object) {
return $value;
}
try {
$value = $fieldDescription->getValue($object);
} catch (NoValueException $e) {
if ($fieldDescription->getAssociationAdmin()) {
$value = $fieldDescription->getAssociationAdmin()->getNewInstance();
}
}
return $value;
}
示例3: getValueFromFieldDescription
/**
* return the value related to FieldDescription, if the associated object does no
* exists => a temporary one is created.
*
* @param object $object
* @param FieldDescriptionInterface $fieldDescription
* @param array $params
*
* @throws \RuntimeException
*
* @return mixed
*/
public function getValueFromFieldDescription($object, FieldDescriptionInterface $fieldDescription, array $params = array())
{
if (isset($params['loop']) && $object instanceof \ArrayAccess) {
throw new \RuntimeException('remove the loop requirement');
}
$value = null;
try {
$value = $fieldDescription->getValue($object);
} catch (NoValueException $e) {
if ($fieldDescription->getAssociationAdmin()) {
$value = $fieldDescription->getAssociationAdmin()->getNewInstance();
}
}
return $value;
}
示例4: addField
/**
* Add a new field type into the provided FormBuilder
*
* @param \Symfony\Component\Form\FormBuilder $formBuilder
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @return void
*/
public function addField(FormBuilder $formBuilder, FieldDescriptionInterface $fieldDescription)
{
// There is a bug in the GraphWalker, so for now we always load related associations
// for more information : https://github.com/symfony/symfony/pull/1056
if ($formBuilder->getData() && in_array($fieldDescription->getType(), array(ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY, ClassMetadataInfo::MANY_TO_ONE, ClassMetadataInfo::ONE_TO_ONE))) {
$value = $fieldDescription->getValue($formBuilder->getData());
$infos = $fieldDescription->getAssociationMapping();
if ($value instanceof $infos['targetEntity'] && $value instanceof \Doctrine\ORM\Proxy\Proxy) {
$relatedId = 'get' . current($fieldDescription->getAdmin()->getModelManager()->getIdentifierFieldNames($infos['targetEntity']));
$value->{$relatedId}();
// force to load the lazy loading method __load in the proxy methode
}
}
switch ($fieldDescription->getType()) {
case ClassMetadataInfo::ONE_TO_MANY:
$this->getOneToManyField($formBuilder, $fieldDescription);
break;
case ClassMetadataInfo::MANY_TO_MANY:
$this->defineManyToManyField($formBuilder, $fieldDescription);
break;
case ClassMetadataInfo::MANY_TO_ONE:
case ClassMetadataInfo::ONE_TO_ONE:
$this->defineOneToOneField($formBuilder, $fieldDescription);
break;
default:
list($type, $default_options) = $this->getFormTypeName($fieldDescription);
$formBuilder->add($fieldDescription->getFieldName(), $type, array_merge($default_options, $fieldDescription->getOption('form_field_options', array())));
}
}