Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Nov 19, 2019
1 parent effa69c commit 5341168
Show file tree
Hide file tree
Showing 11 changed files with 989 additions and 52 deletions.
21 changes: 16 additions & 5 deletions Content/Application/ContentDimensionFactory/Mapper/RouteMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDimensionFactory\Mapper;

use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentDimensionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Bundle\RouteBundle\Generator\RouteGeneratorInterface;
use Sulu\Bundle\RouteBundle\Manager\RouteManagerInterface;
use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface;
Expand Down Expand Up @@ -53,10 +53,14 @@ public function map(
object $contentDimension,
?object $localizedContentDimension = null
): void {
if (!$localizedContentDimension || !$localizedContentDimension instanceof RoutableInterface || !$localizedContentDimension instanceof ContentDimensionInterface) {
if (!$localizedContentDimension || !$localizedContentDimension instanceof RoutableInterface) {
return;
}

if (!$localizedContentDimension instanceof TemplateInterface) {
throw new \RuntimeException('ContentDimension needs to extend the TemplateInterface');
}

if (!isset($data['template'])) {
throw new \RuntimeException('Expected "template" to be set in the data array.');
}
Expand All @@ -80,13 +84,20 @@ public function map(
return;
}

$locale = $localizedContentDimension->getDimension()->getLocale();
$locale = $localizedContentDimension->getLocale();
if (!$locale) {
return;
}

$routePath = $data[$property->getName()] ?? null;
/** @var string $name */
$name = $property->getName();
if (!array_key_exists($name, $data)) {
return;
}

$routePath = $data[$name] ?? null;
if (!$routePath) {
// FIXME this should be handled directly in the form - see pages as an example
$routePath = $this->routeGenerator->generate(
$localizedContentDimension,
['route_schema' => '/{object.getTitle()}']
Expand All @@ -95,7 +106,7 @@ public function map(
$localizedContentDimension->setTemplateData(
array_merge(
$localizedContentDimension->getTemplateData(),
[$property->getName() => $routePath]
[$name => $routePath]
)
);
}
Expand Down
4 changes: 3 additions & 1 deletion Content/Domain/Model/RoutableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
/**
* Marker interface for autoloading the doctrine metadata for routables.
*/
interface RoutableInterface extends TemplateInterface
interface RoutableInterface
{
public function getContentClass(): string;

/**
* @return mixed
*/
public function getContentId();

public function getLocale(): ?string;
}
24 changes: 24 additions & 0 deletions Content/Domain/Model/RoutableTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ContentBundle\Content\Domain\Model;

trait RoutableTrait
{
public function getLocale(): ?string
{
return $this->getDimension()->getLocale();
}

abstract public function getDimension(): DimensionInterface;
}
22 changes: 12 additions & 10 deletions Content/Infrastructure/Sulu/Route/ContentDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Component\Content\Document\Behavior\ExtensionBehavior;

/**
* @codeCoverageIgnore
*/
class ContentDocument implements ExtensionBehavior
{
/**
Expand All @@ -39,6 +36,11 @@ public function __construct(TemplateInterface $content, string $locale)
$this->locale = $locale;
}

public function getContent(): TemplateInterface
{
return $this->content;
}

/**
* @return mixed[]
*/
Expand Down Expand Up @@ -76,12 +78,12 @@ public function getExtensionsData(): array

public function setExtensionsData($extensionData): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function setExtension($name, $data): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getLocale(): string
Expand All @@ -91,7 +93,7 @@ public function getLocale(): string

public function setLocale($locale): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getOriginalLocale(): string
Expand All @@ -101,7 +103,7 @@ public function getOriginalLocale(): string

public function setOriginalLocale($locale): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getStructureType(): ?string
Expand All @@ -111,17 +113,17 @@ public function getStructureType(): ?string

public function setStructureType($structureType): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getStructure()
{
return null;
}

protected function readOnlyException(string $method): void
protected function createReadOnlyException(string $method): \BadMethodCallException
{
throw new \BadMethodCallException(
return new \BadMethodCallException(
sprintf(
'Compatibility layer ContentDocument instances are readonly. Tried to call "%s"',
$method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ protected function loadEntity(string $entityClass, string $id, string $locale):
}

try {
// FIXME use the live workflow-stage when publishing is implemented

return $this->handle(
new LoadContentViewMessage($content, ['locale' => $locale, 'workflowStage' => 'draft'])
);
Expand Down
35 changes: 16 additions & 19 deletions Content/Infrastructure/Sulu/Route/ContentStructureBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
use Sulu\Component\Content\Metadata\PropertyMetadata;
use Sulu\Component\Content\Metadata\StructureMetadata;

/**
* @codeCoverageIgnore
*/
class ContentStructureBridge implements StructureInterface
{
/**
Expand Down Expand Up @@ -87,7 +84,7 @@ public function getContent(): TemplateInterface

public function setLanguageCode($locale): void
{
$this->locale = $locale;
throw $this->createReadOnlyException(__METHOD__);
}

public function getLanguageCode(): string
Expand All @@ -97,7 +94,7 @@ public function getLanguageCode(): string

public function setWebspaceKey($webspace): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getWebspaceKey(): ?string
Expand All @@ -115,7 +112,7 @@ public function getUuid()

public function setUuid($uuid): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getView(): ?string
Expand All @@ -130,7 +127,7 @@ public function getCreator(): ?int

public function setCreator($userId): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getChanger(): ?int
Expand All @@ -140,7 +137,7 @@ public function getChanger(): ?int

public function setChanger($userId): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getCreated(): ?\DateTimeInterface
Expand All @@ -150,7 +147,7 @@ public function getCreated(): ?\DateTimeInterface

public function setCreated(\DateTime $created)
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getChanged(): ?\DateTimeInterface
Expand All @@ -160,7 +157,7 @@ public function getChanged(): ?\DateTimeInterface

public function setChanged(\DateTime $changed)
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getKey()
Expand Down Expand Up @@ -205,7 +202,7 @@ public function getProperties($flatten = false)

public function setHasChildren($hasChildren): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getHasChildren(): bool
Expand All @@ -215,7 +212,7 @@ public function getHasChildren(): bool

public function setChildren($children): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getChildren(): array
Expand All @@ -230,7 +227,7 @@ public function getPublishedState(): bool

public function setPublished($published): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getPublished(): ?\DateTimeInterface
Expand All @@ -250,7 +247,7 @@ public function getPropertyNames()

public function setType($type): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getType(): ?StructureType
Expand All @@ -268,12 +265,12 @@ public function getPath()

public function setPath($path): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function setHasTranslation($hasTranslation): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getHasTranslation(): bool
Expand Down Expand Up @@ -341,7 +338,7 @@ public function getNodeState(): int

public function copyFrom(StructureInterface $structure): void
{
$this->readOnlyException(__METHOD__);
throw $this->createReadOnlyException(__METHOD__);
}

public function getInternal(): bool
Expand Down Expand Up @@ -401,9 +398,9 @@ public function __get($name)
return $this->getProperty($name)->getValue();
}

protected function readOnlyException(string $method): void
protected function createReadOnlyException(string $method): \BadMethodCallException
{
throw new \BadMethodCallException(
return new \BadMethodCallException(
sprintf(
'Compatibility layer StructureBridge instances are readonly. Tried to call "%s"',
$method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ExcerptInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ExcerptTrait;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableTrait;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoTrait;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
Expand All @@ -32,6 +33,7 @@ class ExampleDimension extends AbstractContentDimension implements ExcerptInterf
getTemplateData as parentGetTemplateData;
setTemplateData as parentSetTemplateData;
}
use RoutableTrait;

/**
* @var Example
Expand Down
Loading

0 comments on commit 5341168

Please sign in to comment.