This repository has been archived by the owner on Nov 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added CollectionField - Support for storing collections in PHPCR-ODM - Added form extension.
- Loading branch information
Showing
33 changed files
with
1,227 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony CMF package. | ||
* | ||
* (c) 2011-2016 Symfony CMF | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Cmf\Component\ContentType\Field; | ||
|
||
use Symfony\Cmf\Component\ContentType\FieldInterface; | ||
use Symfony\Cmf\Component\ContentType\Form\Extension\Type\FieldCollectionType; | ||
use Symfony\Cmf\Component\ContentType\MappingBuilder; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class CollectionField implements FieldInterface | ||
{ | ||
public function getViewType() | ||
{ | ||
return CollectionView::class; | ||
} | ||
|
||
public function getFormType() | ||
{ | ||
return FieldCollectionType::class; | ||
} | ||
|
||
public function getMapping(MappingBuilder $builder) | ||
{ | ||
return $builder->collection(); | ||
} | ||
|
||
public function configureOptions(OptionsResolver $options) | ||
{ | ||
$options->setRequired([ | ||
'entry_type', | ||
'allow_add', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony CMF package. | ||
* | ||
* (c) 2011-2016 Symfony CMF | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Cmf\Component\ContentType\Form\Extension; | ||
|
||
use Metadata\MetadataFactoryInterface; | ||
use Symfony\Cmf\Component\ContentType\FieldRegistry; | ||
use Symfony\Cmf\Component\ContentType\Form\Extension\Type\FieldCollectionType; | ||
use Symfony\Cmf\Component\ContentType\Form\Extension\Type\SurrogateType; | ||
use Symfony\Component\Form\AbstractExtension; | ||
|
||
/** | ||
* Form type extension to provide form types for user content-type-managed | ||
* classes in addition to content-type component specific types. | ||
*/ | ||
class FieldExtension extends AbstractExtension | ||
{ | ||
/** | ||
* @var MetadataFactoryInterface | ||
*/ | ||
private $metadataFactory; | ||
|
||
/** | ||
* @var FieldRegistry | ||
*/ | ||
private $fieldRegistry; | ||
|
||
public function __construct( | ||
MetadataFactoryInterface $metadataFactory, | ||
FieldRegistry $fieldRegistry | ||
) { | ||
$this->metadataFactory = $metadataFactory; | ||
$this->fieldRegistry = $fieldRegistry; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function hasType($type) | ||
{ | ||
if ($this->metadataFactory->getMetadataForClass($type)) { | ||
return true; | ||
} | ||
|
||
return parent::hasType($type); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function loadTypes() | ||
{ | ||
return [ | ||
new FieldCollectionType($this->fieldRegistry), | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getType($type) | ||
{ | ||
if (parent::hasType($type)) { | ||
return parent::getType($type); | ||
} | ||
|
||
$metadata = $this->metadataFactory->getMetadataForClass($type); | ||
|
||
if (!$metadata) { | ||
throw new \InvalidArgumentException(sprintf( | ||
'The type "%s" cannot be loaded by this extension', | ||
$type | ||
)); | ||
} | ||
|
||
$surrogteType = new SurrogateType( | ||
$type, | ||
$this->fieldRegistry, | ||
$metadata | ||
); | ||
|
||
return $surrogteType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony CMF package. | ||
* | ||
* (c) 2011-2016 Symfony CMF | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Cmf\Component\ContentType\Form\Extension\Type; | ||
|
||
use Symfony\Cmf\Component\ContentType\FieldRegistry; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | ||
use Symfony\Component\OptionsResolver\Options; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class FieldCollectionType extends AbstractType | ||
{ | ||
private $registry; | ||
|
||
public function __construct(FieldRegistry $registry) | ||
{ | ||
$this->registry = $registry; | ||
} | ||
|
||
public function configureOptions(OptionsResolver $options) | ||
{ | ||
$options->setNormalizer('entry_type', function (Options $options, $value) { | ||
// get the field type | ||
$field = $this->registry->get($value); | ||
|
||
return $field->getFormType(); | ||
}); | ||
} | ||
|
||
public function getParent() | ||
{ | ||
return CollectionType::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony CMF package. | ||
* | ||
* (c) 2011-2016 Symfony CMF | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Cmf\Component\ContentType\Form\Extension\Type; | ||
|
||
use Symfony\Cmf\Component\ContentType\FieldRegistry; | ||
use Symfony\Cmf\Component\ContentType\Metadata\ClassMetadata; | ||
use Symfony\Cmf\Component\ContentType\OptionsResolver\FieldOptionsResolver; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* Surrogate type for virtual user "content" form types. | ||
* | ||
* For example, if the user manages an "Article" class with the content type | ||
* system, this class will act as its form type. | ||
*/ | ||
class SurrogateType extends AbstractType | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $contentFqn; | ||
|
||
/** | ||
* @var ClassMetadata | ||
*/ | ||
private $classMetadata; | ||
|
||
/** | ||
* @var FieldRegistry | ||
*/ | ||
private $fieldRegistry; | ||
|
||
public function __construct( | ||
$contentFqn, | ||
FieldRegistry $fieldRegistry, | ||
ClassMetadata $classMetadata | ||
) { | ||
$this->contentFqn = $contentFqn; | ||
$this->fieldRegistry = $fieldRegistry; | ||
$this->classMetadata = $classMetadata; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
foreach ($this->classMetadata->getPropertyMetadata() as $propertyMetadata) { | ||
$field = $this->fieldRegistry->get($propertyMetadata->getType()); | ||
$formOptions = $propertyMetadata->getOptions(); | ||
|
||
$resolver = new FieldOptionsResolver(); | ||
$field->configureOptions($resolver); | ||
$formOptions = $resolver->resolveFormOptions($formOptions); | ||
|
||
$builder->add( | ||
$propertyMetadata->getName(), | ||
$field->getFormType(), | ||
$formOptions | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefault('data_class', $this->contentFqn); | ||
} | ||
} |
Oops, something went wrong.