Skip to content

Commit

Permalink
Merge 47bd527 into 8910ac8
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Nov 10, 2019
2 parents 8910ac8 + 47bd527 commit 2f90ef3
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 86 deletions.
18 changes: 9 additions & 9 deletions composer.json
Expand Up @@ -29,15 +29,15 @@
"sonata-project/admin-bundle": "^3.29",
"sonata-project/core-bundle": "^3.14",
"sonata-project/exporter": "^1.11.0 || ^2.0",
"symfony/config": "^2.8 || ^3.2 || ^4.0",
"symfony/console": "^2.8 || ^3.2 || ^4.0",
"symfony/dependency-injection": "^2.8 || ^3.2 || ^4.0",
"symfony/doctrine-bridge": "^2.8 || ^3.2 || ^4.0",
"symfony/form": "^2.8 || ^3.2 || ^4.0",
"symfony/framework-bundle": "^2.8 || ^3.2 || ^4.0",
"symfony/http-foundation": "^2.8 || ^3.2 || ^4.0",
"symfony/http-kernel": "^2.8 || ^3.2 || ^4.0",
"symfony/options-resolver": "^2.8 || ^3.2 || ^4.0",
"symfony/config": "^3.4 || ^4.2",
"symfony/console": "^3.4 || ^4.2",
"symfony/dependency-injection": "^3.4 || ^4.2",
"symfony/doctrine-bridge": "^3.4 || ^4.2",
"symfony/form": "^3.4 || ^4.2",
"symfony/framework-bundle": "^3.4 || ^4.2",
"symfony/http-foundation": "^3.4 || ^4.2",
"symfony/http-kernel": "^3.4 || ^4.2",
"symfony/options-resolver": "^3.4 || ^4.2",
"symfony/security-acl": "^2.8 || ^3.0"
},
"conflict": {
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/filter_field_definition.rst
Expand Up @@ -69,9 +69,9 @@ Example
doctrine_orm_model_autocomplete
-------------------------------

This filter type uses ``sonata_type_model_autocomplete`` form type. It renders an input with select2 autocomplete feature.
This filter type uses ``Sonata\AdminBundle\Form\Type\ModelAutocompleteType`` form type. It renders an input with select2 autocomplete feature.
Can be used as replacement of ``doctrine_orm_model`` to handle too many related items that cannot be loaded into memory.
This form type requires ``property`` option. See documentation of ``sonata_type_model_autocomplete`` for all available options for this form type::
This form type requires ``property`` option. See documentation of ``Sonata\AdminBundle\Form\Type\ModelAutocompleteType`` for all available options for this form type::

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
Expand Down
24 changes: 14 additions & 10 deletions docs/reference/form_field_definition.rst
Expand Up @@ -14,14 +14,15 @@ Example
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelListType;
use Sonata\CoreBundle\Validator\ErrorElement;
final class PostAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('author', 'sonata_type_model_list', [])
->add('author', ModelListType::class, [])
->add('enabled')
->add('title')
->add('abstract', null, ['required' => false])
Expand Down Expand Up @@ -80,6 +81,7 @@ you can use the corresponding option in the form field definition::

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelListType;

final class PostAdmin extends AbstractAdmin
{
Expand All @@ -88,7 +90,7 @@ you can use the corresponding option in the form field definition::
$formMapper
->with('General')
->add('enabled', null, ['required' => false])
->add('author', 'sonata_type_model_list', [], [
->add('author', ModelListType::class, [], [
'placeholder' => 'No author selected',
]);
}
Expand Down Expand Up @@ -139,15 +141,17 @@ If you have many ``Post`` linked to one ``User``, then the ``Post`` form should

The AdminBundle provides 2 options:

* ``sonata_type_model``: the ``User`` list is set in a select widget with an `Add` button to create a new ``User``,
* ``sonata_type_model_list``: the ``User`` list is set in a model where you can search, select and delete a ``User``.
* ``\Sonata\AdminBundle\Form\Type\ModelType``: the ``User`` list is set in a select widget with an `Add` button to create a new ``User``,
* ``\Sonata\AdminBundle\Form\Type\ModelListType``: the ``User`` list is set in a model where you can search, select and delete a ``User``.

.. code-block:: php
namespace Sonata\NewsBundle\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelListType;
use Sonata\AdminBundle\Form\Type\ModelType;
final class PostAdmin extends AbstractAdmin
{
Expand All @@ -156,7 +160,7 @@ The AdminBundle provides 2 options:
$formMapper
->with('General')
->add('enabled', null, ['required' => false])
->add('author', 'sonata_type_model_list', [
->add('author', ModelListType::class, [
'btn_add' => 'Add author', //Specify a custom label
'btn_list' => 'button.list', //which will be translated
'btn_delete' => false, //or hide the button.
Expand All @@ -170,7 +174,7 @@ The AdminBundle provides 2 options:
->add('content')
->end()
->with('Tags')
->add('tags', 'sonata_type_model', ['expanded' => true])
->add('tags', ModelType::class, ['expanded' => true])
->end()
->with('Options', ['collapsed' => true])
->add('commentsCloseAt')
Expand Down Expand Up @@ -221,11 +225,11 @@ You can easily add a new ``Media`` row by defining one of these options:
]);
}
}
.. note::
.. note::

You have to define the ``setMedias`` method into your ``Gallery`` class and manually attach each ``media`` to the current ``gallery`` and define cascading persistence for the relationship from media to gallery.

By default, position row will be rendered. If you want to hide it, you will need to alter child admin class and add hidden position field.
Use code like::

Expand All @@ -243,6 +247,6 @@ To render child help messages you must use 'sonata_help' instead of 'help'::
{
$formMapper
->add('image', 'file', [
'sonata_help' => 'help message rendered in parent sonata_type_collection'
'sonata_help' => 'help message rendered in parent CollectionType'
]);
}
18 changes: 10 additions & 8 deletions docs/reference/form_types_and_transformers.rst
Expand Up @@ -10,13 +10,13 @@ The `AdminBundle` is shipped with custom form types and data transfomers in orde
Form types
----------

* ``sonata_type_admin``: this type is linked to an `Admin` class and the field construction is delegated to an Admin class,
* ``sonata_type_collection``: this type works like the native ``CollectionType`` but contains two extra features:
* ``\Sonata\AdminBundle\Form\Type\AdminType``: this type is linked to an `Admin` class and the field construction is delegated to an Admin class,
* ``\Sonata\Form\Type\CollectionType``: this type works like the native ``CollectionType`` but contains two extra features:

* the data layer is abstracted to work with any implemented layer,
* a delete option is added so a collection entry can be deleted.
* ``sonata_type_model``: this type works like the native ``EntityType`` but this internal is abstracted to work with any implemented layer.
* ``sonata_type_immutable_array``: this type allows to edit a fixed array, like a settings array.
* ``\Sonata\AdminBundle\Form\Type\ModelType``: this type works like the native ``EntityType`` but this internal is abstracted to work with any implemented layer.
* ``\Sonata\Form\Type\ImmutableArrayType``: this type allows to edit a fixed array, like a settings array.

Let's say, the object has settings properties::

Expand All @@ -35,14 +35,15 @@ Now you can edit the settings array with::

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\Form\Type\ImmutableArrayType;

final class PageAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('enabled')
->add('settings', 'sonata_type_immutable_array', [
->add('settings', ImmutableArrayType::class, [
'keys' => [
['content', 'textarea', []],
['public', 'checkbox', []],
Expand All @@ -63,6 +64,7 @@ Other options::

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelType;

use Application\Sonata\NewsBundle\Entity\Comment;

Expand All @@ -73,13 +75,13 @@ Other options::
$formMapper
->with('General')
->add('enabled', null, ['required' => false])
->add('author', 'sonata_type_model', [], ['edit' => 'list'])
->add('author', ModelType::class, [], ['edit' => 'list'])
->add('title')
->add('abstract')
->add('content')
->end()
->with('Tags')
->add('tags', 'sonata_type_model', ['expanded' => true])
->add('tags', ModelType::class, ['expanded' => true])
->end()
->with('Options', ['collapsed' => true])
->add('commentsCloseAt')
Expand All @@ -97,4 +99,4 @@ DataTransformer

* ``ArrayToModelTransformer``: transform an array to an object,
* ``ModelsToArrayTransformer``: transform a collection of array into a collection of object,
* ``ModelToIdTransformater``: transform an ``id`` into an object.
* ``ModelToIdTransformater``: transform an ``id`` into an object.
Expand Up @@ -22,6 +22,7 @@ First, you need to create an `Admin/PostAdmin.php` file::
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\Type\ModelType;
use Sonata\AdminBundle\Show\ShowMapper;

use Knp\Menu\ItemInterface as MenuItemInterface;
Expand Down Expand Up @@ -51,10 +52,10 @@ First, you need to create an `Admin/PostAdmin.php` file::
->add('content')
->end()
->with('Tags')
->add('tags', 'sonata_type_model', ['expanded' => true, 'multiple' => true])
->add('tags', ModelType::class, ['expanded' => true, 'multiple' => true])
->end()
->with('Comments')
->add('comments', 'sonata_type_model', ['multiple' => true])
->add('comments', ModelType::class, ['multiple' => true])
->end()
->with('System Information', ['collapsed' => true])
->add('created_at')
Expand Down Expand Up @@ -195,6 +196,7 @@ Tweak the CommentAdmin class
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelType;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
Expand All @@ -207,7 +209,7 @@ Tweak the CommentAdmin class
protected function configureFormFields(FormMapper $formMapper)
{
if (!$this->isChild()) {
$formMapper->add('post', 'sonata_type_model', [], ['edit' => 'list']);
$formMapper->add('post', ModelType::class, [], ['edit' => 'list']);
}
$formMapper
Expand Down
2 changes: 1 addition & 1 deletion src/Block/AuditBlockService.php
Expand Up @@ -49,7 +49,7 @@ public function execute(BlockContextInterface $blockContext, Response $response
foreach ($this->auditReader->findRevisionHistory($blockContext->getSetting('limit'), 0) as $revision) {
$revisions[] = [
'revision' => $revision,
'entities' => $this->auditReader->findEntitesChangedAtRevision($revision->getRev()),
'entities' => $this->auditReader->findEntitiesChangedAtRevision($revision->getRev()),
];
}

Expand Down
3 changes: 1 addition & 2 deletions src/Builder/DatagridBuilder.php
Expand Up @@ -156,8 +156,7 @@ public function addFilter(DatagridInterface $datagrid, $type, FieldDescriptionIn

$fieldDescription->mergeOption('field_options', ['required' => false]);

// NEXT_MAJOR: Check only against FQCNs when dropping support for Symfony 2.8
if ('doctrine_orm_model_autocomplete' === $type || ModelAutocompleteFilter::class === $type) {
if (ModelAutocompleteFilter::class === $type) {
$fieldDescription->mergeOption('field_options', [
'class' => $fieldDescription->getTargetEntity(),
'model_manager' => $fieldDescription->getAdmin()->getModelManager(),
Expand Down
23 changes: 7 additions & 16 deletions src/Builder/FormContractor.php
Expand Up @@ -99,13 +99,7 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
$options = [];
$options['sonata_field_description'] = $fieldDescription;

// NEXT_MAJOR: Check only against FQCNs when dropping support for Symfony 2.8
if (\in_array($type, [
'sonata_type_model',
'sonata_type_model_list',
'sonata_type_model_hidden',
'sonata_type_model_autocomplete',
], true) || $this->checkFormClass($type, [
if ($this->checkFormClass($type, [
ModelType::class,
ModelTypeList::class,
ModelListType::class,
Expand All @@ -114,16 +108,15 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
])) {
if ('list' === $fieldDescription->getOption('edit')) {
throw new \LogicException(
'The `sonata_type_model` type does not accept an `edit` option anymore,'
'The `\Sonata\AdminBundle\Form\Type\ModelType` 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();

// NEXT_MAJOR: Check only against FQCNs when dropping support for Symfony 2.8
if ('sonata_type_model_autocomplete' === $type || $this->checkFormClass($type, [ModelAutocompleteType::class])) {
if ($this->checkFormClass($type, [ModelAutocompleteType::class])) {
if (!$fieldDescription->getAssociationAdmin()) {
throw new \RuntimeException(sprintf(
'The current field `%s` is not linked to an admin.'
Expand All @@ -133,8 +126,7 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
));
}
}
// NEXT_MAJOR: Check only against FQCNs when dropping support for Symfony 2.8
} elseif ('sonata_type_admin' === $type || $this->checkFormClass($type, [AdminType::class])) {
} elseif ($this->checkFormClass($type, [AdminType::class])) {
if (!$fieldDescription->getAssociationAdmin()) {
throw new \RuntimeException(sprintf(
'The current field `%s` is not linked to an admin.'
Expand All @@ -149,8 +141,8 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
ClassMetadata::MANY_TO_ONE,
], true)) {
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_type_collection` instead?',
'You are trying to add `Sonata\AdminBundle\Form\Type\AdminType` field `%s` which is not One-To-One or Many-To-One.'
.' Maybe you want `Sonata\Form\Type\CollectionType` instead?',
$fieldDescription->getName()
));
}
Expand All @@ -164,8 +156,7 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
return $fieldDescription->getAssociationAdmin()->getNewInstance();
};
$fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));
// NEXT_MAJOR: Check only against FQCNs when dropping support for Symfony 2.8
} elseif ('sonata_type_collection' === $type || $this->checkFormClass($type, [CollectionType::class, DeprecatedCollectionType::class])) {
} elseif ($this->checkFormClass($type, [CollectionType::class, DeprecatedCollectionType::class])) {
if (!$fieldDescription->getAssociationAdmin()) {
throw new \RuntimeException(sprintf(
'The current field `%s` is not linked to an admin.'
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/Form/form_admin_fields.html.twig
Expand Up @@ -171,6 +171,6 @@ file that was distributed with this source code.
{% elseif sonata_admin.field_description.mappingtype == constant('Doctrine\\ORM\\Mapping\\ClassMetadataInfo::MANY_TO_MANY') %}
{{ block('sonata_admin_orm_many_to_many_widget') }}
{% else %}
INVALID MODE : {{ id }} - type : sonata_type_collection - mapping : {{ sonata_admin.field_description.mappingtype }}
INVALID MODE : {{ id }} - type : CollectionType - mapping : {{ sonata_admin.field_description.mappingtype }}
{% endif %}
{% endblock %}
2 changes: 1 addition & 1 deletion tests/Block/AuditBlockServiceTest.php
Expand Up @@ -55,7 +55,7 @@ public function testExecute(): void
->willReturn([$revision = new Revision('test', '123', 'test')])
->shouldBeCalledTimes(1);

$this->simpleThingsAuditReader->findEntitesChangedAtRevision(Argument::cetera())
$this->simpleThingsAuditReader->findEntitiesChangedAtRevision(Argument::cetera())
->willReturn([])
->shouldBeCalledTimes(1);

Expand Down
9 changes: 1 addition & 8 deletions tests/Builder/FormContractorTest.php
Expand Up @@ -79,23 +79,16 @@ public function testDefaultOptionsForSonataFormTypes(): void
$fieldDescription->method('getAssociationAdmin')->willReturn($admin);
$admin->method('getNewInstance')->willReturn($model);

// NEXT_MAJOR: Use only FQCNs when dropping support for Symfony 2.8
$modelTypes = [
'sonata_type_model',
'sonata_type_model_list',
'sonata_type_model_hidden',
'sonata_type_model_autocomplete',
ModelType::class,
ModelListType::class,
ModelHiddenType::class,
ModelAutocompleteType::class,
];
$adminTypes = [
'sonata_type_admin',
AdminType::class,
];
$collectionTypes = [
'sonata_type_collection',
DeprecatedCollectionType::class,
];

Expand Down Expand Up @@ -146,7 +139,7 @@ public function testAdminClassAttachForNotMappedField(): void

$fieldDescription = $this->createMock(FieldDescriptionInterface::class);
$fieldDescription->method('getMappingType')->willReturn('simple');
$fieldDescription->method('getType')->willReturn('sonata_type_model_list');
$fieldDescription->method('getType')->willReturn(ModelListType::class);
$fieldDescription->method('getOption')->with($this->logicalOr(
$this->equalTo('edit'),
$this->equalTo('admin_code')
Expand Down

0 comments on commit 2f90ef3

Please sign in to comment.