Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #351 from WouterJ/backport
Browse files Browse the repository at this point in the history
Backport "Add Symfony 2.8 support"
  • Loading branch information
dbu committed Dec 19, 2015
2 parents f2d2b02 + 5aa1b96 commit bcbcccb
Showing 1 changed file with 48 additions and 40 deletions.
88 changes: 48 additions & 40 deletions Builder/FormContractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,46 +107,54 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
$options = array();
$options['sonata_field_description'] = $fieldDescription;

if ($type == 'doctrine_phpcr_odm_tree') {
$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
}

if ($type == 'sonata_type_model' || $type == 'sonata_type_model_list') {
if (!$fieldDescription->getTargetEntity()) {
throw new \LogicException(sprintf(
'The field "%s" in class "%s" does not have a target model defined. ' .
'Please specify the "targetDocument" attribute in the mapping for this class.',
$fieldDescription->getName(),
$fieldDescription->getAdmin()->getClass()
));
}

$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();

} else if ($type == 'sonata_type_admin') {

if (!$fieldDescription->getAssociationAdmin()) {
throw $this->getAssociationAdminException($fieldDescription);
}

$options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass();
$fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));

} else if ($type == 'sonata_type_collection') {

if (!$fieldDescription->getAssociationAdmin()) {
throw $this->getAssociationAdminException($fieldDescription);
}

$options['type'] = 'sonata_type_admin';
$options['modifiable'] = true;
$options['type_options'] = array(
'sonata_field_description' => $fieldDescription,
'data_class' => $fieldDescription->getAssociationAdmin()->getClass()
);

switch ($type) {
case 'Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType':
case 'doctrine_phpcr_odm_tree':
$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();

break;
case 'Sonata\AdminBundle\Form\Type\Modeltype':
case 'sonata_type_model':
case 'Sonata\AdminBundle\Form\Type\ModelTypeList':
case 'sonata_type_model_list':
if (!$fieldDescription->getTargetEntity()) {
throw new \LogicException(sprintf(
'The field "%s" in class "%s" does not have a target model defined. ' .
'Please specify the "targetDocument" attribute in the mapping for this class.',
$fieldDescription->getName(),
$fieldDescription->getAdmin()->getClass()
));
}

$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();

break;
case 'Sonata\AdminBundle\Form\Type\AdminType':
case 'sonata_type_admin':
if (!$fieldDescription->getAssociationAdmin()) {
throw $this->getAssociationAdminException($fieldDescription);
}

$options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass();
$fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));

break;
case 'Sonata\AdminBundle\Form\Type\CollectionType':
case 'sonata_type_collection':
if (!$fieldDescription->getAssociationAdmin()) {
throw $this->getAssociationAdminException($fieldDescription);
}

$options['type'] = 'sonata_type_admin';
$options['modifiable'] = true;
$options['type_options'] = array(
'sonata_field_description' => $fieldDescription,
'data_class' => $fieldDescription->getAssociationAdmin()->getClass()
);

break;
}

return $options;
Expand Down

0 comments on commit bcbcccb

Please sign in to comment.