Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/3.x' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Jul 29, 2020
2 parents 09a6160 + 8bb0c21 commit 3c6f726
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 13 deletions.
3 changes: 3 additions & 0 deletions docs/getting_started/installation.rst
Expand Up @@ -44,6 +44,9 @@ line in `bundles.php` file of your project::
Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true],
Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true],
Sonata\AdminBundle\SonataAdminBundle::class => ['all' => true],
Sonata\Doctrine\Bridge\Symfony\SonataDoctrineBundle::class => ['all' => true],
Sonata\Form\Bridge\Symfony\SonataFormBundle::class => ['all' => true],
Sonata\Twig\Bridge\Symfony\SonataTwigBundle::class => ['all' => true],
];

Configure the Installed Bundles
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/action_list.rst
Expand Up @@ -581,9 +581,9 @@ Checkbox range selection
Displaying a non-model field
----------------------------

.. versionadded:: 3.x
.. versionadded:: 3.73

Support for displaying fields not part of the model class was introduced in version 3.x.
Support for displaying fields not part of the model class was introduced in version 3.73.

The list view can also display fields that are not part of the model class.

Expand Down
12 changes: 3 additions & 9 deletions docs/reference/child_admin.rst
Expand Up @@ -61,20 +61,14 @@ class::
$admin = $this->isChild() ? $this->getParent() : $this;
$id = $admin->getRequest()->get('id');

$menu->addChild('View Playlist', [
'uri' => $admin->generateUrl('show', ['id' => $id])
]);
$menu->addChild('View Playlist', $admin->generateMenuUrl('show', ['id' => $id]));

if ($this->isGranted('EDIT')) {
$menu->addChild('Edit Playlist', [
'uri' => $admin->generateUrl('edit', ['id' => $id])
]);
$menu->addChild('Edit Playlist', $admin->generateMenuUrl('edit', ['id' => $id]));
}

if ($this->isGranted('LIST')) {
$menu->addChild('Manage Videos', [
'uri' => $admin->generateUrl('App\Admin\VideoAdmin.list', ['id' => $id])
]);
$menu->addChild('Manage Videos', $admin->generateMenuUrl('App\Admin\VideoAdmin.list', ['id' => $id]));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model/ModelManagerInterface.php
Expand Up @@ -85,7 +85,7 @@ public function batchDelete($class, ProxyQueryInterface $queryProxy);
/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/admin-bundle 3.x. To be removed in 4.0.
* @deprecated since sonata-project/admin-bundle 3.73. To be removed in 4.0.
* Use AdminInterface::getParentFieldDescription instead.
*
* @param array $parentAssociationMapping
Expand Down
1 change: 1 addition & 0 deletions src/Translator/Extractor/AdminExtractor.php
Expand Up @@ -96,6 +96,7 @@ public function extract($resource, MessageCatalogue $catalogue)
}

$admin->setLabelTranslatorStrategy($this);
$admin->setSubject($admin->getNewInstance());

foreach (self::PUBLIC_ADMIN_METHODS as $method) {
$admin->$method();
Expand Down
43 changes: 43 additions & 0 deletions tests/App/Admin/TranslatedAdmin.php
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\AdminBundle\Tests\App\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Templating\TemplateRegistry;
use Symfony\Component\Form\Extension\Core\Type\TextType;

final class TranslatedAdmin extends AbstractAdmin
{
protected function configureListFields(ListMapper $list): void
{
$list->add('name_list', TemplateRegistry::TYPE_STRING);
}

protected function configureFormFields(FormMapper $form): void
{
$form
->add('name_form', TextType::class, ['help' => 'Help me!'])
->ifTrue($this->getSubject()->isPublished)
->add('datePublished')
->ifEnd();
}

protected function configureShowFields(ShowMapper $show): void
{
$show->add('name_show', TemplateRegistry::TYPE_STRING);
}
}
3 changes: 3 additions & 0 deletions tests/App/AppKernel.php
Expand Up @@ -87,6 +87,9 @@ protected function configureContainer(ContainerBuilder $containerBuilder, Loader
'session' => ['handler_id' => 'session.handler.native_file', 'storage_id' => 'session.storage.mock_file', 'name' => 'MOCKSESSID'],
'assets' => null,
'test' => true,
'translator' => [
'default_path' => '%kernel.project_dir%/translations',
],
]);

$containerBuilder->loadFromExtension('security', [
Expand Down
7 changes: 6 additions & 1 deletion tests/App/Model/ModelManager.php
Expand Up @@ -116,7 +116,12 @@ public function getUrlSafeIdentifier($model)

public function getModelInstance($class)
{
return new Foo('test_id', 'foo_name');
switch ($class) {
case Translated::class:
return new Translated();
default:
return new Foo('test_id', 'foo_name');
}
}

public function getModelCollectionInstance($class)
Expand Down
21 changes: 21 additions & 0 deletions tests/App/Model/Translated.php
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\AdminBundle\Tests\App\Model;

final class Translated
{
public $nameForm;
public $isPublished = true;
public $datePublished;
}
5 changes: 5 additions & 0 deletions tests/App/config/services.yml
Expand Up @@ -43,3 +43,8 @@ services:
arguments: [~, Sonata\AdminBundle\Tests\App\Model\Foo, ~]
tags:
- {name: sonata.admin, manager_type: test, label: Empty}

Sonata\AdminBundle\Tests\App\Admin\TranslatedAdmin:
arguments: [~, Sonata\AdminBundle\Tests\App\Model\Translated, ~]
tags:
- {name: sonata.admin, manager_type: test, group: 'group_label', label: 'admin_label'}
48 changes: 48 additions & 0 deletions tests/Functional/Translator/Extractor/AdminExtractorTest.php
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\AdminBundle\Tests\Functional\Translator\Extractor;

use Sonata\AdminBundle\Tests\App\AppKernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;

final class AdminExtractorTest extends KernelTestCase
{
public function testDebugMissingMessages(): void
{
$tester = $this->createCommandTester();
$tester->execute(['locale' => 'en']);

$this->assertRegExp('/group_label/', $tester->getDisplay());
$this->assertRegExp('/admin_label/', $tester->getDisplay());
$this->assertRegExp('/Name Show/', $tester->getDisplay());
$this->assertRegExp('/Name List/', $tester->getDisplay());
$this->assertRegExp('/Name Form/', $tester->getDisplay());
$this->assertRegExp('/Date Published/', $tester->getDisplay());
}

protected static function getKernelClass(): string
{
return AppKernel::class;
}

private function createCommandTester(): CommandTester
{
$kernel = static::createKernel();
$application = new Application($kernel);

return new CommandTester($application->find('debug:translation'));
}
}
14 changes: 14 additions & 0 deletions tests/Translator/Extractor/AdminExtractorTest.php
Expand Up @@ -121,4 +121,18 @@ public function testExtractCallsBreadcrumbs(): void

$this->adminExtractor->extract([], $catalogue);
}

public function testExtractSetsSubject(): void
{
$this->fooAdmin
->expects($this->exactly(1))
->method('setSubject');
$this->fooAdmin
->expects($this->exactly(1))
->method('getNewInstance');

$catalogue = new MessageCatalogue('en');

$this->adminExtractor->extract([], $catalogue);
}
}

0 comments on commit 3c6f726

Please sign in to comment.