本文整理汇总了PHP中Sonata\AdminBundle\Admin\FieldDescriptionInterface::getTargetEntity方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldDescriptionInterface::getTargetEntity方法的具体用法?PHP FieldDescriptionInterface::getTargetEntity怎么用?PHP FieldDescriptionInterface::getTargetEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\AdminBundle\Admin\FieldDescriptionInterface
的用法示例。
在下文中一共展示了FieldDescriptionInterface::getTargetEntity方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: getDefaultOptions
/**
* @param string $type
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
*
* @return array
*/
public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
{
$options = array('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;
}
示例3: 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;
}
示例4: attachAdminClass
/**
* {@inheritdoc}
*/
public function attachAdminClass(FieldDescriptionInterface $fieldDescription)
{
$pool = $this->getConfigurationPool();
$adminCode = $fieldDescription->getOption('admin_code');
if ($adminCode !== null) {
$admin = $pool->getAdminByAdminCode($adminCode);
} else {
$admin = $pool->getAdminByClass($fieldDescription->getTargetEntity());
}
if (!$admin) {
return;
}
if ($this->hasRequest()) {
$admin->setRequest($this->getRequest());
}
$fieldDescription->setAssociationAdmin($admin);
}
示例5: attachAdminClass
/**
* attach an admin instance to the given FieldDescription
*
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
*/
public function attachAdminClass(FieldDescriptionInterface $fieldDescription)
{
$pool = $this->getConfigurationPool();
$admin = $pool->getAdminByClass($fieldDescription->getTargetEntity());
if (!$admin) {
return;
}
$fieldDescription->setAssociationAdmin($admin);
}
示例6: getChoices
/**
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @return array
*/
public function getChoices(FieldDescriptionInterface $fieldDescription)
{
$modelManager = $fieldDescription->getAdmin()->getModelManager();
$targets = $modelManager->getEntityManager()
->createQueryBuilder()
->select('t')
->from($fieldDescription->getTargetEntity(), 't')
->getQuery()
->execute();
$choices = array();
foreach ($targets as $target) {
// todo : puts this into a configuration option and use reflection
foreach (array('getTitle', 'getName', '__toString') as $getter) {
if (method_exists($target, $getter)) {
$choices[$modelManager->getNormalizedIdentifier($target)] = $target->$getter();
break;
}
}
}
return $choices;
}
示例7: attachAdminClass
/**
* attach an admin instance to the given FieldDescription
*
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
*/
public function attachAdminClass(FieldDescriptionInterface $fieldDescription)
{
$pool = $this->getConfigurationPool();
$admin = $pool->getAdminByClass($fieldDescription->getTargetEntity());
if (!$admin) {
throw new \RuntimeException(sprintf('You must define an Admin class for the `%s` field (targetEntity=%s)', $fieldDescription->getFieldName(), $fieldDescription->getTargetEntity()));
}
$fieldDescription->setAssociationAdmin($admin);
}
示例8: getAssociationAdminException
/**
* @param FieldDescriptionInterface $fieldDescription
*
* @return \LogicException
*/
protected function getAssociationAdminException(FieldDescriptionInterface $fieldDescription)
{
$msg = sprintf('The current field `%s` is not linked to an admin. Please create one', $fieldDescription->getName());
if (in_array($fieldDescription->getMappingType(), array(ClassMetadata::MANY_TO_ONE, ClassMetadata::MANY_TO_MANY, 'referrers'))) {
if ($fieldDescription->getTargetEntity()) {
$msg .= " for the target document: `{$fieldDescription->getTargetEntity()}`";
}
$msg .= ', specify the `targetDocument` in the Reference, or the `referringDocument` in the Referrers or use the option `admin_code` to link it.';
} else {
$msg .= ' and use the option `admin_code` to link it.';
}
return new \LogicException($msg);
}
示例9: defineManyToManyField
/**
* @param \Symfony\Component\Form\FormBuilder $formBuilder
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @return \Symfony\Component\Form\Type\FormTypeInterface
*/
protected function defineManyToManyField(FormBuilder $formBuilder, FieldDescriptionInterface $fieldDescription)
{
$type = $fieldDescription->getOption('form_field_type', 'sonata_type_model');
$options = $fieldDescription->getOption('form_field_options', array());
if ($type == 'sonata_type_model') {
$options['class'] = $fieldDescription->getTargetEntity();
$options['multiple'] = true;
$options['field_description'] = $fieldDescription;
$options['parent'] = 'choice';
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
}
$formBuilder->add($fieldDescription->getName(), $type, $options);
}
示例10: getDefaultOptions
/**
* @param $type
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @param array $options
* @return array
*/
public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
{
$options = array();
$options['sonata_field_description'] = $fieldDescription;
if ($type == 'sonata_type_model') {
$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
switch ($fieldDescription->getMappingType()) {
case ClassMetadataInfo::ONE_TO_MANY:
case ClassMetadataInfo::MANY_TO_MANY:
$options['multiple'] = true;
$options['parent'] = 'choice';
break;
case ClassMetadataInfo::MANY_TO_ONE:
case ClassMetadataInfo::ONE_TO_ONE:
break;
}
} 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;
}