Skip to content

Commit

Permalink
Merge 3.x into 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Dec 6, 2021
2 parents c44f13b + f4a8392 commit 82913f3
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 176 deletions.
29 changes: 14 additions & 15 deletions docs/reference/custom_action.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ Add new route to your Admin
.. code-block:: php
// src/Admin/QuestionnaireAdmin.php
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
final class QuestionnaireAdmin extends AbstractAdmin
{
protected function configureRoutes(RouteCollection $collection)
protected function configureRoutes(RouteCollectionInterface $collection): void
{
$collection
->add('show_question_answer', sprintf('%s/show_question_answer', $this->getRouterIdParameter()))
Expand All @@ -51,25 +51,25 @@ First update your admin configuration to point to a custom controller:
.. code-block:: yaml
# config/services.yaml
admin.questionnaire:
class: App\Admin\QuestionnaireAdmin
arguments: [~, App\Entity\Questionnaire, App:Admin/Questionnaire]
tags:
- { name: sonata.admin, manager_type: orm, label: 'dashboard.label_questionnaire' }
.. code-block:: xml
<!-- config/services.xml -->
<service id="admin.questionnaire" class="App\Admin\QuestionnaireAdmin">
<argument/>
<argument>App\Entity\Questionnaire</argument>
<argument>App:Admin/Questionnaire</argument>
<tag name="sonata.admin" manager_type="orm" label="dashboard.label_questionnaire"/>
</service>
Then implement your controller.
Then implement your controller.

To benefit from Sonata powerful feature, we need to extend the class ``CRUDController`` and load our current
object the same way as Sonata does in edit or show action::
Expand All @@ -85,19 +85,19 @@ object the same way as Sonata does in edit or show action::
{
/** @var App\Entity\Questionnaire $questionnaire */
$questionnaire = $this->admin->getSubject($id);

if (!$questionnaire) {
$id = $request->get($this->admin->getIdParameter());
throw $this->createNotFoundException(sprintf(
'Unable to find the object with id : %s',
$id
));
}

return $this->render('admin/questionnaire/show_question_answer.html.twig', [
'questionnaire' => $questionnaire,
]);
}
}
}

Add locale switcher block
Expand All @@ -107,9 +107,9 @@ As we are implementing a 'show' actions type, your template should extend your a
If you are working on an edit action you should work with the edit block instead.

.. code-block:: jinja
{# templates/admin/questionnaire/show_question_answer.html.twig #}
{% extends ':admin:layout.html.twig' %}
{% block show %}
Expand All @@ -124,8 +124,7 @@ If you are working on an edit action you should work with the edit block instead
At this point, you should have a working locale switcher in your actions.

.. note::

You had noticed that I don't use ``$object`` variable in my custom action like it's the case in ``CRUDController``.
This is made on purpose cause we are not in a generic action and if your actions manipulate several kind of objects
you will notice that it's really meaningful to do it this way.

60 changes: 13 additions & 47 deletions docs/reference/orm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ Example for configure search filter
final class FAQCategoryAdmin extends AbstractAdmin
{
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
protected function configureDatagridFilters(DatagridMapper $filter): void
{
$datagridMapper
$filter
->add('title', TranslationFieldFilter::class, [
// if not specified, it will default to the value
// you set in `default_filter_mode`
Expand Down Expand Up @@ -185,61 +185,40 @@ of Doctrine Behavior does not work. For more background on that topic, see this
use TranslatableTrait;

/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
private int $id;

/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $nonTranslatedField;
private string $nonTranslatedField;

/**
* @return integer
*/
public function getId()
public function getId(): int
{
return $this->id;
}

/**
* @return string
*/
public function getNonTranslatableField()
public function getNonTranslatableField(): string
{
return $this->nonTranslatedField;
}

/**
* @param string $nonTranslatedField
*
* @return TranslatableEntity
*/
public function setNonTranslatableField($nonTranslatedField)
public function setNonTranslatableField(string $nonTranslatedField): TranslatableEntity
{
$this->nonTranslatedField = $nonTranslatedField;

return $this;
}

/**
* @return mixed
*/
public function getName()
public function getName(): string
{
return $this->translate(null, false)->getName();
}

/**
* @param string $name
*/
public function setName($name)
public function setName(string $name): TranslatableEntity
{
$this->translate(null, false)->setName($name);

Expand Down Expand Up @@ -270,34 +249,21 @@ Here is an example::
use TranslationTrait;

/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $name;
private string $name;

/**
* @return integer
*/
public function getId()
public function getId(): int
{
return $this->id;
}

/**
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}

/**
* @param string $name
*
* @return TranslatableEntityTranslation
*/
public function setName($name)
public function setName(string $name): TranslatableEntityTranslation
{
$this->name = $name;

Expand Down
8 changes: 0 additions & 8 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<!-- NEXT_MAJOR: Remove this issueHandlers -->
<issueHandlers>
<DeprecatedClass>
<errorLevel type="suppress">
<referencedClass name="Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface"/>
</errorLevel>
</DeprecatedClass>
</issueHandlers>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
<pluginClass class="Weirdan\DoctrinePsalmPlugin\Plugin"/>
Expand Down
37 changes: 1 addition & 36 deletions src/Admin/Extension/Gedmo/TranslatableAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\TranslationBundle\Admin\Extension\AbstractTranslatableAdminExtension;
use Sonata\TranslationBundle\Checker\TranslatableChecker;
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface;
use Sonata\TranslationBundle\Provider\LocaleProviderInterface;

/**
* @author Nicolas Bastien <nbastien.pro@gmail.com>
*
* @phpstan-extends AbstractTranslatableAdminExtension<TranslatableInterface>
* @phpstan-extends AbstractTranslatableAdminExtension<Translatable>
*
* @internal
*/
Expand All @@ -52,21 +51,6 @@ public function __construct(

public function alterNewInstance(AdminInterface $admin, object $object): void
{
// NEXT_MAJOR: Remove the entire "if" block.
if ($object instanceof TranslatableInterface) {
@trigger_error(sprintf(
'Implementing "%s" for entities using gedmo/doctrine-extensions is deprecated'
.' since sonata-project/translation-bundle 2.10 and will not work in 3.0. You MUST implement "%s"'
.' instead.',
TranslatableInterface::class,
Translatable::class,
), \E_USER_DEPRECATED);

$object->setLocale($this->getTranslatableLocale());

return;
}

if (!$this->getTranslatableChecker()->isTranslatable($object)) {
return;
}
Expand All @@ -84,25 +68,6 @@ public function alterObject(AdminInterface $admin, object $object): void

\assert($objectManager instanceof ObjectManager);

// NEXT_MAJOR: Remove the entire "if" block.
if ($object instanceof TranslatableInterface) {
@trigger_error(sprintf(
'Implementing "%s" for entities using gedmo/doctrine-extensions is deprecated'
.' since sonata-project/translation-bundle 2.10 and will not work in 3.0. You MUST implement "%s"'
.' instead.',
TranslatableInterface::class,
Translatable::class,
), \E_USER_DEPRECATED);

$this->translatableListener->setTranslatableLocale($this->getTranslatableLocale());
$this->translatableListener->setTranslationFallback(false);

$objectManager->refresh($object);
$object->setLocale($this->getTranslatableLocale());

return;
}

$objectManager->refresh($object);
$this->setLocale($object);
}
Expand Down
3 changes: 0 additions & 3 deletions src/DependencyInjection/SonataTranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Gedmo\Translatable\Translatable as GedmoTranslatable;
use Gedmo\Translatable\TranslatableListener;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface as KNPTranslatableInterface;
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface as GedmoTranslatableInterface;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -68,8 +67,6 @@ public function load(array $configs, ContainerBuilder $container): void
*/
$listOfInterfaces = array_merge(
[
// NEXT_MAJOR: Remove next line.
GedmoTranslatableInterface::class,
GedmoTranslatable::class,
],
$config['gedmo']['implements']
Expand Down
27 changes: 0 additions & 27 deletions src/Model/Gedmo/TranslatableInterface.php

This file was deleted.

24 changes: 0 additions & 24 deletions src/Model/TranslatableInterface.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\TranslationBundle\Admin\Extension\AbstractTranslatableAdminExtension;
use Sonata\TranslationBundle\Checker\TranslatableChecker;
use Sonata\TranslationBundle\Model\TranslatableInterface;
use Sonata\TranslationBundle\Provider\LocaleProviderInterface;

final class AbstractTranslatableAdminExtensionTest extends TestCase
Expand All @@ -35,9 +34,6 @@ final class AbstractTranslatableAdminExtensionTest extends TestCase
protected function setUp(): void
{
$this->translatableChecker = new TranslatableChecker();
$this->translatableChecker->setSupportedInterfaces([
TranslatableInterface::class,
]);

$localeProvider = new class() implements LocaleProviderInterface {
public function get(): string
Expand Down

0 comments on commit 82913f3

Please sign in to comment.