-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Shadow Locale to Settings Tab (#238)
* Add Shadow Locale to Settings Tab * Apply suggestions from code review Co-authored-by: Prokyonn <daniel.mathis@sector8.eu> --------- Co-authored-by: Prokyonn <daniel.mathis@sector8.eu>
- Loading branch information
1 parent
32470e1
commit 29f27a7
Showing
29 changed files
with
742 additions
and
2 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
Content/Application/ContentDataMapper/DataMapper/ShadowDataMapper.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,43 @@ | ||
<?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\ShadowInterface; | ||
|
||
class ShadowDataMapper implements DataMapperInterface | ||
{ | ||
public function map( | ||
DimensionContentInterface $unlocalizedDimensionContent, | ||
DimensionContentInterface $localizedDimensionContent, | ||
array $data | ||
): void { | ||
if (!$localizedDimensionContent instanceof ShadowInterface) { | ||
return; | ||
} | ||
|
||
if (\array_key_exists('shadowOn', $data) || \array_key_exists('shadowLocale', $data)) { | ||
/** @var bool $shadowOn */ | ||
$shadowOn = $data['shadowOn'] ?? false; | ||
/** @var string|null $shadowLocale */ | ||
$shadowLocale = $data['shadowLocale'] ?? null; | ||
|
||
$localizedDimensionContent->setShadowLocale( | ||
$shadowOn | ||
? $shadowLocale | ||
: null | ||
); | ||
} | ||
} | ||
} |
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 | ||
|
||
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\ShadowInterface; | ||
|
||
/** | ||
* @internal This class should not be instantiated by a project. | ||
* Create your own merger instead. | ||
*/ | ||
final class ShadowMerger implements MergerInterface | ||
{ | ||
public function merge(object $targetObject, object $sourceObject): void | ||
{ | ||
if (!$targetObject instanceof ShadowInterface) { | ||
return; | ||
} | ||
|
||
if (!$sourceObject instanceof ShadowInterface) { | ||
return; | ||
} | ||
|
||
if ($shadowLocale = $sourceObject->getShadowLocale()) { | ||
$targetObject->setShadowLocale($shadowLocale); | ||
} | ||
|
||
foreach ($sourceObject->getShadowLocales() ?: [] as $locale => $shadowLocale) { | ||
$targetObject->addShadowLocale($locale, $shadowLocale); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
Content/Application/ContentNormalizer/Normalizer/ShadowNormalizer.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\Application\ContentNormalizer\Normalizer; | ||
|
||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ShadowInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
class ShadowNormalizer implements NormalizerInterface | ||
{ | ||
public function enhance(object $object, array $normalizedData): array | ||
{ | ||
if (!$object instanceof ShadowInterface) { | ||
return $normalizedData; | ||
} | ||
|
||
Assert::isInstanceOf($object, DimensionContentInterface::class); | ||
|
||
$normalizedData['shadowOn'] = null !== $object->getShadowLocale(); | ||
$normalizedData['shadowLocales'] = $normalizedData['shadowLocales'] ?? []; | ||
$normalizedData['contentLocales'] = $object->getAvailableLocales() ?? []; // TODO should be changed in Sulu Core (PageSettingsShadowLocaleSelect.js) | ||
|
||
return $normalizedData; | ||
} | ||
|
||
public function getIgnoredAttributes(object $object): array | ||
{ | ||
if (!$object instanceof ShadowInterface) { | ||
return []; | ||
} | ||
|
||
return []; | ||
} | ||
} |
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,39 @@ | ||
<?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 ShadowInterface | ||
{ | ||
/** | ||
* @internal should only be set by content bundle services not from outside | ||
*/ | ||
public function setShadowLocale(?string $shadowLocale): void; | ||
|
||
public function getShadowLocale(): ?string; | ||
|
||
/** | ||
* @internal should only be set by content bundle services not from outside | ||
*/ | ||
public function addShadowLocale(string $locale, string $shadowLocale): void; | ||
|
||
/** | ||
* @internal should only be set by content bundle services not from outside | ||
*/ | ||
public function removeShadowLocale(string $locale): void; | ||
|
||
/** | ||
* @return array<string, string>|null | ||
*/ | ||
public function getShadowLocales(): ?array; | ||
} |
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,68 @@ | ||
<?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 ShadowTrait | ||
{ | ||
/** | ||
* @var string|null | ||
*/ | ||
protected $shadowLocale; | ||
|
||
/** | ||
* @var string[]|null | ||
*/ | ||
protected $shadowLocales = null; | ||
|
||
/** | ||
* @internal should only be set by content bundle services not from outside | ||
*/ | ||
public function setShadowLocale(?string $shadowLocale): void | ||
{ | ||
$this->shadowLocale = $shadowLocale; | ||
} | ||
|
||
public function getShadowLocale(): ?string | ||
{ | ||
return $this->shadowLocale; | ||
} | ||
|
||
/** | ||
* @internal should only be set by content bundle services not from outside | ||
*/ | ||
public function addShadowLocale(string $locale, string $shadowLocale): void | ||
{ | ||
if (null === $this->shadowLocales) { | ||
$this->shadowLocales = []; | ||
} | ||
|
||
$this->shadowLocales[$locale] = $shadowLocale; | ||
} | ||
|
||
/** | ||
* @internal should only be set by content bundle services not from outside | ||
*/ | ||
public function removeShadowLocale(string $locale): void | ||
{ | ||
unset($this->shadowLocales[$locale]); | ||
} | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
public function getShadowLocales(): ?array | ||
{ | ||
return $this->shadowLocales; | ||
} | ||
} |
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,40 @@ | ||
<?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_shadow</key> | ||
|
||
<tag name="sulu_content.content_settings_form" instanceOf="Sulu\Bundle\ContentBundle\Content\Domain\Model\ShadowInterface" priority="-40"/> | ||
|
||
<properties> | ||
<section name="shadow"> | ||
<meta> | ||
<title>sulu_content.shadow_page</title> | ||
</meta> | ||
|
||
<properties> | ||
<property name="shadowOn" type="checkbox" disabledCondition="shadowLocales and __locale in shadowLocales|values"> | ||
<meta> | ||
<info_text>sulu_content.enable_shadow_page_info_text</info_text> | ||
</meta> | ||
|
||
<params> | ||
<param name="type" value="toggler" /> | ||
<param name="label"> | ||
<meta> | ||
<title>sulu_content.enable_shadow_page</title> | ||
</meta> | ||
</param> | ||
</params> | ||
</property> | ||
|
||
<property name="shadowLocale" type="page_settings_shadow_locale_select" colspan="6" visibleCondition="shadowOn == true"> | ||
<meta> | ||
<title>sulu_content.shadow_locale</title> | ||
</meta> | ||
</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
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.