-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Additional Webspaces Field to Settings Tab #213
Draft
alexander-schranz
wants to merge
2
commits into
sulu:0.9
Choose a base branch
from
alexander-schranz:feature/additional-webspace-settings
base: 0.9
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
Content/Application/ContentDataMapper/DataMapper/WebspaceDataMapper.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,83 @@ | ||
<?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\Application\ContentDataMapper\DataMapper; | ||
|
||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WebspaceInterface; | ||
use Sulu\Component\Webspace\Manager\WebspaceManagerInterface; | ||
|
||
class WebspaceDataMapper implements DataMapperInterface | ||
{ | ||
/** | ||
* @var WebspaceManagerInterface | ||
*/ | ||
private $webspaceManager; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $defaultWebspaceKey; | ||
|
||
public function __construct(WebspaceManagerInterface $webspaceManager) | ||
{ | ||
$this->webspaceManager = $webspaceManager; | ||
} | ||
|
||
public function map( | ||
DimensionContentInterface $unlocalizedDimensionContent, | ||
DimensionContentInterface $localizedDimensionContent, | ||
array $data | ||
): void { | ||
if (!$localizedDimensionContent instanceof WebspaceInterface) { | ||
return; | ||
} | ||
|
||
$this->setWebspaceData($localizedDimensionContent, $data); | ||
} | ||
|
||
/** | ||
* @param mixed[] $data | ||
*/ | ||
private function setWebspaceData(WebspaceInterface $dimensionContent, array $data): void | ||
{ | ||
// TODO allow to configure another webspace with `<tag name="sulu_content.default_main_webspace" value="example" />` | ||
// on the template itself which will be injected with ["type" => ["template-key" => "webspace-key"]] into this service. | ||
if (\array_key_exists('mainWebspace', $data)) { | ||
$dimensionContent->setMainWebspace($data['mainWebspace']); | ||
} | ||
|
||
if (!$dimensionContent->getMainWebspace()) { | ||
// if no main webspace is yet set a default webspace will be set | ||
$dimensionContent->setMainWebspace($this->getDefaultWebspaceKey()); | ||
} | ||
|
||
if (\array_key_exists('additionalWebspaces', $data)) { | ||
$dimensionContent->setAdditionalWebspaces($data['additionalWebspaces'] ?: []); | ||
} | ||
} | ||
|
||
private function getDefaultWebspaceKey(): ?string | ||
{ | ||
if (!$this->defaultWebspaceKey) { | ||
$webspaces = $this->webspaceManager->getWebspaceCollection()->getWebspaces(); | ||
$webspace = \reset($webspaces); | ||
|
||
if ($webspace) { | ||
$this->defaultWebspaceKey = $webspace->getKey(); | ||
} | ||
} | ||
|
||
return $this->defaultWebspaceKey; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Content/Application/ContentMerger/Merger/WebspaceMerger.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,38 @@ | ||
<?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\Application\ContentMerger\Merger; | ||
|
||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WebspaceInterface; | ||
|
||
class WebspaceMerger implements MergerInterface | ||
{ | ||
public function merge(object $targetObject, object $sourceObject): void | ||
{ | ||
if (!$targetObject instanceof WebspaceInterface) { | ||
return; | ||
} | ||
|
||
if (!$sourceObject instanceof WebspaceInterface) { | ||
return; | ||
} | ||
|
||
if ($mainWebspace = $sourceObject->getMainWebspace()) { | ||
$targetObject->setMainWebspace($mainWebspace); | ||
} | ||
|
||
if ($additionalWebspaces = $sourceObject->getAdditionalWebspaces()) { | ||
$targetObject->setAdditionalWebspaces($additionalWebspaces); | ||
} | ||
} | ||
} |
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,31 @@ | ||
<?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; | ||
|
||
interface WebspaceInterface | ||
{ | ||
public function getMainWebspace(): ?string; | ||
|
||
public function setMainWebspace(?string $mainWebspace): void; | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getAdditionalWebspaces(): array; | ||
|
||
/** | ||
* @param string[] $additionalWebspaces | ||
*/ | ||
public function setAdditionalWebspaces(array $additionalWebspaces): void; | ||
} |
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,63 @@ | ||
<?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 WebspaceTrait | ||
{ | ||
/** | ||
* @var string|null | ||
*/ | ||
protected $mainWebspace; | ||
|
||
/** | ||
* @var string[]|null | ||
*/ | ||
protected $additionalWebspaces; | ||
|
||
public function getMainWebspace(): ?string | ||
{ | ||
return $this->mainWebspace; | ||
} | ||
|
||
public function setMainWebspace(?string $mainWebspace): void | ||
{ | ||
$this->mainWebspace = $mainWebspace; | ||
|
||
if ($mainWebspace && !\in_array($mainWebspace, $this->additionalWebspaces ?: [], true)) { | ||
// additional webspace always include also the main webspace to make query simpler | ||
$this->additionalWebspaces = \array_merge($this->additionalWebspaces ?: [], [$mainWebspace]); | ||
} | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getAdditionalWebspaces(): array | ||
{ | ||
return $this->additionalWebspaces ?: []; | ||
} | ||
|
||
/** | ||
* @param string[] $additionalWebspaces | ||
*/ | ||
public function setAdditionalWebspaces(array $additionalWebspaces): void | ||
{ | ||
if ($this->mainWebspace && !\in_array($this->mainWebspace, $additionalWebspaces, true)) { | ||
// additional webspace always include also the main webspace to make query simpler | ||
$additionalWebspaces[] = $this->mainWebspace; | ||
} | ||
|
||
$this->additionalWebspaces = $additionalWebspaces; | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
Content/Infrastructure/Sulu/Page/Select/WebspaceSelect.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,45 @@ | ||
<?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\Infrastructure\Sulu\Page\Select; | ||
|
||
use Sulu\Component\Webspace\Manager\WebspaceManagerInterface; | ||
|
||
class WebspaceSelect | ||
{ | ||
/** | ||
* @var WebspaceManagerInterface | ||
*/ | ||
private $webspaceManager; | ||
|
||
public function __construct(WebspaceManagerInterface $webspaceManager) | ||
{ | ||
$this->webspaceManager = $webspaceManager; | ||
} | ||
|
||
/** | ||
* @return array<array{name: string, title: string}> | ||
*/ | ||
public function getValues(): array | ||
{ | ||
$values = []; | ||
foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) { | ||
$values[] = [ | ||
'name' => $webspace->getKey(), | ||
'title' => $webspace->getName(), | ||
]; | ||
} | ||
|
||
return $values; | ||
} | ||
} |
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,47 @@ | ||
<?xml version="1.0" ?> | ||
<form xmlns="http://schemas.sulu.io/template/template" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/form-1.0.xsd" | ||
> | ||
<key>content_settings_webspace</key> | ||
|
||
<tag name="sulu_content.content_settings_form" instanceOf="Sulu\Bundle\ContentBundle\Content\Domain\Model\WebspaceInterface" priority="-30"/> | ||
|
||
<properties> | ||
<section name="webspace"> | ||
<meta> | ||
<title>sulu_content.webspace</title> | ||
</meta> | ||
|
||
<properties> | ||
<property name="mainWebspace" type="single_select" colspan="6"> | ||
<meta> | ||
<title>sulu_content.main_webspace</title> | ||
</meta> | ||
|
||
<params> | ||
<param | ||
name="values" | ||
type="expression" | ||
value="service('sulu_content.webspace_select').getValues()" | ||
/> | ||
</params> | ||
</property> | ||
|
||
<property name="additionalWebspaces" type="select" colspan="6"> | ||
<meta> | ||
<title>sulu_content.additional_webspaces</title> | ||
</meta> | ||
|
||
<params> | ||
<param | ||
name="values" | ||
type="expression" | ||
value="service('sulu_content.webspace_select').getValues()" | ||
/> | ||
</params> | ||
</property> | ||
</properties> | ||
</section> | ||
</properties> | ||
</form> |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed with @chirimoya we will go with a
one-to-many
relation.The content bundle will provide also a
AdditionalWebspaceTrait
content bundle so a article bundle for example has then 3 entities:The
ArticleDimensionContentWebspace
will haveid
,dimensionContent
andwebspace
field./cc @TheCadien do you want to have a look at this?