Skip to content

Commit

Permalink
Symfony4-compatibility only
Browse files Browse the repository at this point in the history
  • Loading branch information
prgTW committed Feb 19, 2024
1 parent c648d52 commit f3a5d13
Show file tree
Hide file tree
Showing 21 changed files with 92 additions and 35 deletions.
12 changes: 8 additions & 4 deletions Builder/FormContractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Builder\FormContractorInterface;
use Sonata\AdminBundle\Form\Type\AdminType;
use Sonata\AdminBundle\Form\Type\CollectionType;
use Sonata\AdminBundle\Form\Type\ModelListType;
use Sonata\AdminBundle\Form\Type\ModelType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormFactoryInterface;
Expand Down Expand Up @@ -78,26 +82,26 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
'sonata_field_description' => $fieldDescription,
);

if ($type == 'sonata_type_model' || $type == 'sonata_type_model_list') {
if ($type == ModelType::class || $type == ModelListType::class) {
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') {
} elseif ($type == AdminType::class) {
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') {
} elseif ($type == CollectionType::class) {
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['type'] = AdminType::class;
$options['modifiable'] = true;
$options['type_options'] = array(
'sonata_field_description' => $fieldDescription,
Expand Down
33 changes: 33 additions & 0 deletions Exporter/Source/PropelCollectionSourceIterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Sonata\PropelAdminBundle\Exporter\Source;

use Propel\Runtime\Collection\Collection;
use Sonata\Exporter\Source\AbstractPropertySourceIterator;

class PropelCollectionSourceIterator extends AbstractPropertySourceIterator
{
private Collection $collection;

/**
* @param array<string> $fields Fields to export
*/
public function __construct(Collection $collection, array $fields, string $dateTimeFormat = 'r')
{
$this->collection = clone $collection;

parent::__construct($fields, $dateTimeFormat);
}

public function rewind(): void
{
if (null === $this->iterator) {
$this->iterator = $this->collection->getIterator();
}

$this->iterator->rewind();
}
}

9 changes: 9 additions & 0 deletions Filter/AbstractDateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Form\Type\Filter\DateRangeType;
use Sonata\AdminBundle\Form\Type\Filter\DateTimeRangeType;
use Sonata\AdminBundle\Form\Type\Filter\DateTimeType;
use Sonata\AdminBundle\Form\Type\Filter\DateType;

/**
Expand Down Expand Up @@ -138,6 +140,13 @@ public function getRenderSettings()
$name .= '_range';
}

$name = [
'sonata_type_filter_date' => DateType::class,
'sonata_type_filter_datetime' => DateTimeType::class,
'sonata_type_filter_date_range' => DateRangeType::class,
'sonata_type_filter_datetime_range' => DateTimeRangeType::class,
][$name];

return array($name, array(
'field_type' => $this->getFieldType(),
'field_options' => $this->getFieldOptions(),
Expand Down
5 changes: 3 additions & 2 deletions Filter/BooleanFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

use Propel\Runtime\ActiveQuery\ModelCriteria;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\CoreBundle\Form\Type\BooleanType;
use Sonata\AdminBundle\Form\Type\Filter\DefaultType;
use Sonata\Form\Type\BooleanType;

/**
* @author Kévin Gomez <[email protected]>
Expand Down Expand Up @@ -44,7 +45,7 @@ public function filter(ProxyQueryInterface $query, $alias, $field, $value)
*/
public function getRenderSettings()
{
return array('sonata_type_filter_default', array(
return array(DefaultType::class, array(
'field_type' => $this->getFieldType(),
'field_options' => $this->getFieldOptions(),
'label' => $this->getLabel(),
Expand Down
3 changes: 2 additions & 1 deletion Filter/CallbackFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Form\Type\Filter\ChoiceType;
use Sonata\AdminBundle\Form\Type\Filter\DefaultType;

class CallbackFilter extends AbstractFilter
{
Expand Down Expand Up @@ -55,7 +56,7 @@ public function getDefaultOptions()
*/
public function getRenderSettings()
{
return array('sonata_type_filter_default', array(
return array(DefaultType::class, array(
'field_type' => $this->getFieldType(),
'field_options' => $this->getFieldOptions(),
'operator_type' => $this->getOption('operator_type'),
Expand Down
3 changes: 2 additions & 1 deletion Filter/ModelFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Propel\Runtime\Collection\ObjectCollection;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Form\Type\Filter\ChoiceType;
use Sonata\AdminBundle\Form\Type\Filter\DefaultType;

/**
* @author Toni Uebernickel <[email protected]>
Expand Down Expand Up @@ -63,7 +64,7 @@ protected function getCriteriaMap()
*/
public function getRenderSettings()
{
return array('sonata_type_filter_default', array(
return array(DefaultType::class, array(
'operator_type' => 'sonata_type_equal',
'field_type' => 'model',
'field_options' => $this->getFieldOptions(),
Expand Down
2 changes: 1 addition & 1 deletion Filter/NumberFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class NumberFilter extends AbstractFilter
*/
public function getRenderSettings()
{
return array('sonata_type_filter_number', array(
return array(NumberType::class, array(
'field_type' => $this->getFieldType(),
'field_options' => $this->getFieldOptions(),
'label' => $this->getLabel(),
Expand Down
2 changes: 1 addition & 1 deletion Filter/StringFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function filter(ProxyQueryInterface $query, $alias, $field, $value)
*/
public function getRenderSettings()
{
return array('sonata_type_filter_choice', array(
return array(ChoiceType::class, array(
'field_type' => $this->getFieldType(),
'field_options' => $this->getFieldOptions(),
'label' => $this->getLabel(),
Expand Down
2 changes: 1 addition & 1 deletion Model/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Sonata\PropelAdminBundle\Model;

use Exporter\Source\PropelCollectionSourceIterator;
use Sonata\PropelAdminBundle\Exporter\Source\PropelCollectionSourceIterator;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
use Propel\Runtime\Collection\ObjectCollection;
Expand Down
2 changes: 2 additions & 0 deletions Tests/Admin/FieldDescriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function testGetValue(): void
->willReturn('myMethodValue');

$field = new FieldDescription();
$field->setName('irrelevant');
$field->setOption('code', 'myMethod');

self::assertEquals('myMethodValue', $field->getValue($mockedObject));
Expand All @@ -140,6 +141,7 @@ public function testGetValueWhenCannotRetrieve(): void
->willReturn('myMethodValue');

$field = new FieldDescription();
$field->setName('irrelevant');

self::assertEquals('myMethodValue', $field->getValue($mockedObject));
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Builder/ListBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function optionsProvider(): array
array(
$field,
array('sortable' => true),
array('sortable' => true, 'sort_field_mapping' => null, 'sort_parent_association_mappings' => array()),
array('sortable' => true, 'sort_field_mapping' => array(), 'sort_parent_association_mappings' => array()),
),
array(
$field,
Expand Down
2 changes: 1 addition & 1 deletion Tests/Filter/BooleanFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Sonata\PropelAdminBundle\Tests\Filter;

use Propel\Runtime\ActiveQuery\ModelCriteria;
use Sonata\CoreBundle\Form\Type\BooleanType;
use Sonata\Form\Type\BooleanType;
use Sonata\PropelAdminBundle\Filter\BooleanFilter;

/**
Expand Down
3 changes: 2 additions & 1 deletion Tests/Filter/DateFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Sonata\PropelAdminBundle\Tests\Filter;

use Sonata\AdminBundle\Form\Type\Filter\DateType;
use Sonata\PropelAdminBundle\Filter\DateFilter;

/**
Expand All @@ -28,6 +29,6 @@ protected function getFilterClass(): string
public function testRenderSettingsHasRightName()
{
$settings = $this->filter->getRenderSettings();
self::assertEquals('sonata_type_filter_date', $settings[0]);
self::assertEquals(DateType::class, $settings[0]);
}
}
4 changes: 3 additions & 1 deletion Tests/Filter/DateRangeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Sonata\PropelAdminBundle\Tests\Filter;

use Sonata\AdminBundle\Form\Type\Filter\DateRangeType;

/**
* DateRangeFilter tests.
*
Expand All @@ -26,6 +28,6 @@ protected function getFilterClass()
public function testRenderSettingsHasRightName()
{
$settings = $this->filter->getRenderSettings();
self::assertEquals('sonata_type_filter_date_range', $settings[0]);
self::assertEquals(DateRangeType::class, $settings[0]);
}
}
3 changes: 2 additions & 1 deletion Tests/Filter/DateTimeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Sonata\PropelAdminBundle\Tests\Filter;

use Sonata\AdminBundle\Form\Type\Filter\DateTimeType;
use Sonata\PropelAdminBundle\Filter\DateTimeFilter;

/**
Expand All @@ -28,6 +29,6 @@ protected function getFilterClass(): string
public function testRenderSettingsHasRightName()
{
$settings = $this->filter->getRenderSettings();
self::assertEquals('sonata_type_filter_datetime', $settings[0]);
self::assertEquals(DateTimeType::class, $settings[0]);
}
}
4 changes: 3 additions & 1 deletion Tests/Filter/DateTimeRangeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Sonata\PropelAdminBundle\Tests\Filter;

use Sonata\AdminBundle\Form\Type\Filter\DateTimeRangeType;

/**
* DateTimeRangeFilter tests.
*
Expand All @@ -26,6 +28,6 @@ protected function getFilterClass()
public function testRenderSettingsHasRightName()
{
$settings = $this->filter->getRenderSettings();
self::assertEquals('sonata_type_filter_datetime_range', $settings[0]);
self::assertEquals(DateTimeRangeType::class, $settings[0]);
}
}
5 changes: 4 additions & 1 deletion Tests/Fixtures/App/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public function registerBundles()

new Propel\Bundle\PropelBundle\PropelBundle(),

new Sonata\CoreBundle\SonataCoreBundle(),
new \Sonata\Twig\Bridge\Symfony\SonataTwigBundle(),
new \Sonata\Doctrine\Bridge\Symfony\SonataDoctrineBundle(),
new \Sonata\Form\Bridge\Symfony\SonataFormBundle(),
new \Sonata\Exporter\Bridge\Symfony\SonataExporterBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
Expand Down
1 change: 0 additions & 1 deletion Tests/Fixtures/App/app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ propel:
charset: utf8

paths:
# phpDir: "%kernel.root_dir%/../src/Sonata/TestBundle/Model"
sqlDir: '%kernel.cache_dir%/propel/sql/'
schemaDir: '%kernel.root_dir%/../src/Sonata/TestBundle/Resources/config/'
loaderScriptDir: '%kernel.cache_dir%/propel/generated-conf/'
Expand Down
2 changes: 0 additions & 2 deletions Tests/Functional/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public function testExportLinksWork(): void
foreach ($this->expected_formats as $format) {
$link = $crawler->selectLink($format)->link();

$this->markTestIncomplete('sonata-project/exporter is having issues with autoloading PropelCollectionSourceIterator class');

// as Sonata\AdminBundle\Export\Exporter writes directly to php://output
// the exported data is displayed in the console
ob_start();
Expand Down
2 changes: 1 addition & 1 deletion Tests/Model/ModelManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function testGetDataSourceIterator(): void
//
// // and finally test it!
// $collectionIterator = $manager->getDataSourceIterator($datagrid, $fields, $firstResult, $maxResults);
// self::assertInstanceOf('\Exporter\Source\PropelCollectionSourceIterator', $collectionIterator);
// self::assertInstanceOf('\Sonata\Exporter\Source\PropelCollectionSourceIterator', $collectionIterator);
// self::assertSame(array(
// array('title' => 'Super!'),
// array('title' => 'Foo'),
Expand Down
26 changes: 13 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
],
"require": {
"php": "^7.4 || ^8.0",
"doctrine/persistence": "^1.0",
"propel/propel": "^2.0.0-beta1",
"sonata-project/admin-bundle": "~3.0",
"sonata-project/block-bundle": "~3.0",
"sonata-project/core-bundle": "3.17.2",
"sonata-project/exporter": "1.x-dev#7ea2008067c70b8caa70b9be72da40bea7104056",
"symfony/form": "^3.4 || ^4.0",
"symfony/framework-bundle": "^3.4 || ^4.0"
"sonata-project/admin-bundle": "^3.107.3",
"sonata-project/block-bundle": "^3.20",
"sonata-project/exporter": "^2",
"symfony/form": "^4.0",
"symfony/framework-bundle": "^4.0"
},
"require-dev": {
"knplabs/knp-menu-bundle": ">=1.1.0,<3.0.0",
"knplabs/knp-menu-bundle": "^3",
"phpunit/phpunit": "^9",
"skyfox/propel-bundle": "~5.0.2@dev",
"symfony/browser-kit": "^3.4 || ^4.0",
"symfony/console": "^3.4 || ^4.0",
"symfony/css-selector": "^3.4 || ^4.0",
"symfony/phpunit-bridge": "^3.4 || ^4.0",
"symfony/browser-kit": "^4.0",
"symfony/console": "^4.0",
"symfony/css-selector": "^4.0",
"symfony/phpunit-bridge": "^4.0",
"symfony/security-bundle": "^4.0",
"symfony/twig-bundle": "^3.4 || ^4.0",
"symfony/var-dumper": "^3.4 || ^4.0"
"symfony/twig-bundle": "^4.0",
"symfony/var-dumper": "^4.0"
},
"conflict": {
"doctrine/annotations": ">1"
Expand Down

0 comments on commit f3a5d13

Please sign in to comment.