This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-29106: Show author name in version list / draft conflict dialog (#…
…964)
- Loading branch information
Showing
17 changed files
with
407 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformUIBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Compiler pass for the ezsystems.platformui.value_object_visitor tag used to | ||
* map an fully qualified class to a value object visitor. | ||
*/ | ||
class ValueObjectVisitorPass implements CompilerPassInterface | ||
{ | ||
const TAG_NAME = 'ezsystems.platformui.value_object_visitor'; | ||
const DISPATCHER_DEFINITION_ID = 'ezsystems.platformui.rest.output.value_object_visitor.dispatcher'; | ||
|
||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition(self::DISPATCHER_DEFINITION_ID)) { | ||
return; | ||
} | ||
|
||
$definition = $container->getDefinition(self::DISPATCHER_DEFINITION_ID); | ||
foreach ($container->findTaggedServiceIds(self::TAG_NAME) as $id => $attributes) { | ||
foreach ($attributes as $attribute) { | ||
if (!isset($attribute['type'])) { | ||
throw new \LogicException(self::TAG_NAME . ' service tag needs a "type" attribute to identify the field type. None given.'); | ||
} | ||
|
||
$definition->addMethodCall( | ||
'addVisitor', | ||
[$attribute['type'], new Reference($id)] | ||
); | ||
} | ||
} | ||
} | ||
} |
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
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
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,17 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformUIBundle\Rest\Generator; | ||
|
||
use eZ\Publish\Core\REST\Common\Output\Generator\Json as BaseJson; | ||
|
||
class Json extends BaseJson | ||
{ | ||
protected function generateMediaType($name, $type) | ||
{ | ||
return "application/vnd.ez.platformui.{$name}+{$type}"; | ||
} | ||
} |
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,55 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformUIBundle\Rest\ValueObjectVisitor; | ||
|
||
use eZ\Publish\API\Repository\Exceptions\NotFoundException; | ||
use eZ\Publish\API\Repository\Repository; | ||
use eZ\Publish\Core\REST\Common\Output\Generator; | ||
use eZ\Publish\Core\REST\Common\Output\Visitor; | ||
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\VersionInfo as BaseVersionInfo; | ||
use eZ\Publish\API\Repository\Values\Content\VersionInfo as APIVersionInfo; | ||
|
||
/** | ||
* VersionInfo value object visitor. | ||
*/ | ||
class VersionInfo extends BaseVersionInfo | ||
{ | ||
/** @var \eZ\Publish\API\Repository\Repository */ | ||
private $repository; | ||
|
||
/** | ||
* VersionInfo constructor. | ||
* | ||
* @param \eZ\Publish\API\Repository\Repository $repository | ||
*/ | ||
public function __construct(Repository $repository) | ||
{ | ||
$this->repository = $repository; | ||
} | ||
|
||
protected function visitVersionInfoAttributes(Visitor $visitor, Generator $generator, APIVersionInfo $versionInfo) | ||
{ | ||
parent::visitVersionInfoAttributes($visitor, $generator, $versionInfo); | ||
|
||
$this->visitCreatorName($visitor, $generator, $versionInfo); | ||
} | ||
|
||
protected function visitCreatorName(Visitor $visitor, Generator $generator, APIVersionInfo $versionInfo) | ||
{ | ||
/** @var \eZ\Publish\API\Repository\Values\User\User $user */ | ||
$user = $this->repository->sudo(function (Repository $repository) use ($versionInfo) { | ||
try { | ||
return $repository->getUserService()->loadUser($versionInfo->creatorId); | ||
} catch (NotFoundException $e) { | ||
return null; | ||
} | ||
}); | ||
|
||
$generator->startValueElement('creatorName', $user ? $user->getName() : '-'); | ||
$generator->endValueElement('creatorName'); | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformUIBundle\Rest; | ||
|
||
use eZ\Publish\Core\REST\Common\Output\Generator; | ||
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher as BaseValueObjectVisitorDispatcher; | ||
use eZ\Publish\Core\REST\Common\Output\Exceptions\NoVisitorFoundException; | ||
use eZ\Publish\Core\REST\Common\Output\Visitor; | ||
|
||
class ValueObjectVisitorDispatcher extends BaseValueObjectVisitorDispatcher | ||
{ | ||
/** @var \eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher */ | ||
private $parentDispatcher; | ||
|
||
/** | ||
* ValueObjectVisitorDispatcher constructor. | ||
* | ||
* @param \eZ\Publish\Core\REST\Common\Output\ValueObjectVisitorDispatcher $parentDispatcher | ||
*/ | ||
public function __construct(BaseValueObjectVisitorDispatcher $parentDispatcher) | ||
{ | ||
$this->parentDispatcher = $parentDispatcher; | ||
} | ||
|
||
public function setOutputVisitor(Visitor $outputVisitor) | ||
{ | ||
parent::setOutputVisitor($outputVisitor); | ||
$this->parentDispatcher->setOutputVisitor($outputVisitor); | ||
} | ||
|
||
public function setOutputGenerator(Generator $outputGenerator) | ||
{ | ||
parent::setOutputGenerator($outputGenerator); | ||
$this->parentDispatcher->setOutputGenerator($outputGenerator); | ||
} | ||
|
||
public function visit($data) | ||
{ | ||
try { | ||
return parent::visit($data); | ||
} catch (NoVisitorFoundException $e) { | ||
return $this->parentDispatcher->visit($data); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
Tests/DependencyInjection/Compiler/ValueObjectVisitorPassTest.php
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,48 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformUIBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use EzSystems\PlatformUIBundle\DependencyInjection\Compiler\ValueObjectVisitorPass; | ||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class ValueObjectVisitorPassTest extends AbstractCompilerPassTestCase | ||
{ | ||
protected function registerCompilerPass(ContainerBuilder $container) | ||
{ | ||
$container->addCompilerPass(new ValueObjectVisitorPass()); | ||
} | ||
|
||
public function testProcess() | ||
{ | ||
$dispatcherDefinition = new Definition(); | ||
|
||
$visitorId = 'ezsystems.platformui.rest.output.value_object_visitor.test'; | ||
$visitorDefinition = new Definition(); | ||
$visitorDefinition->addTag(ValueObjectVisitorPass::TAG_NAME, [ | ||
'type' => 'test', ] | ||
); | ||
|
||
$containerBuilder = new ContainerBuilder(); | ||
$containerBuilder->addDefinitions([ | ||
ValueObjectVisitorPass::DISPATCHER_DEFINITION_ID => $dispatcherDefinition, | ||
$visitorId => $visitorDefinition, | ||
]); | ||
|
||
$compilerPass = new ValueObjectVisitorPass(); | ||
$compilerPass->process($containerBuilder); | ||
|
||
$dispatcherMethodCalls = $dispatcherDefinition->getMethodCalls(); | ||
|
||
$this->assertTrue(isset($dispatcherMethodCalls[0][0]), 'Failed asserting that dispatcher has a method call'); | ||
$this->assertEquals('addVisitor', $dispatcherMethodCalls[0][0], "Failed asserting that called method is 'addVisitor'"); | ||
$this->assertInstanceOf(Reference::class, $dispatcherMethodCalls[0][1][1], 'Failed asserting that method call is to a Reference object'); | ||
$this->assertEquals($visitorId, $dispatcherMethodCalls[0][1][1]->__toString(), "Failed asserting that Referenced service is '$visitorId'"); | ||
} | ||
} |
Oops, something went wrong.