Skip to content

Commit

Permalink
Add Symfony 2.8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Dec 5, 2015
1 parent c4f3185 commit 0a76966
Showing 1 changed file with 47 additions and 36 deletions.
83 changes: 47 additions & 36 deletions Builder/FormContractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,42 +103,53 @@ 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();
} elseif ($type == 'sonata_type_admin') {
if (!$fieldDescription->getAssociationAdmin()) {
throw $this->getAssociationAdminException($fieldDescription);
}

$options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass();
$fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));
} elseif ($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 0a76966

Please sign in to comment.