Skip to content

Commit

Permalink
Add Webspace select to Settings Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Oct 14, 2021
1 parent 0343c4c commit 2c887c0
Show file tree
Hide file tree
Showing 26 changed files with 630 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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;

class WebspaceDataMapper implements DataMapperInterface
{
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
{
if (\array_key_exists('mainWebspace', $data)) {
$dimensionContent->setMainWebspace($data['mainWebspace']);
}

if (\array_key_exists('additionalWebspaces', $data)) {
$dimensionContent->setAdditionalWebspaces($data['additionalWebspaces'] ?: []);
}
}
}
38 changes: 38 additions & 0 deletions Content/Application/ContentMerger/Merger/WebspaceMerger.php
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);
}
}
}
25 changes: 25 additions & 0 deletions Content/Domain/Model/WebspaceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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;

public function getAdditionalWebspaces(): array;

public function setAdditionalWebspaces(array $additionalWebspaces): void;
}
53 changes: 53 additions & 0 deletions Content/Domain/Model/WebspaceTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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;
}

/**
* @return string[]
*/
public function getAdditionalWebspaces(): array
{
return $this->additionalWebspaces ?: [];
}

/**
* @param string[]
*/
public function setAdditionalWebspaces(array $additionalWebspaces): void
{
$this->additionalWebspaces = $additionalWebspaces;
}
}
6 changes: 6 additions & 0 deletions Content/Infrastructure/Doctrine/MetadataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ExcerptInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WebspaceInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface;
use Sulu\Bundle\MediaBundle\Entity\MediaInterface;
use Sulu\Bundle\TagBundle\Tag\TagInterface;
Expand Down Expand Up @@ -94,6 +95,11 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
$this->addManyToMany($event, $metadata, 'excerptCategories', CategoryInterface::class, 'category_id');
}

if ($reflection->implementsInterface(WebspaceInterface::class)) {
$this->addField($metadata, 'mainWebspace', 'string', ['nullable' => true]);
$this->addField($metadata, 'additionalWebspaces', 'json', ['nullable' => true]);
}

if ($reflection->implementsInterface(AuthorInterface::class)) {
$this->addField($metadata, 'authored', 'datetime_immutable', ['nullable' => true]);
$this->addManyToOne($event, $metadata, 'author', ContactInterface::class, true);
Expand Down
42 changes: 42 additions & 0 deletions Content/Infrastructure/Sulu/Page/Select/WebspaceSelect.php
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\Infrastructure\Sulu\Page\Select;

use Sulu\Component\Webspace\Manager\WebspaceManagerInterface;

class WebspaceSelect
{
/**
* @var WebspaceManagerInterface
*/
private $webspaceManager;

public function __construct(WebspaceManagerInterface $webspaceManager)
{
$this->webspaceManager = $webspaceManager;
}

public function getValues(): array
{
$values = [];
foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
$values[] = [
'name' => $webspace->getKey(),
'title' => $webspace->getName(),
];
}

return $values;
}
}
4 changes: 4 additions & 0 deletions Resources/config/data-mapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
</service>

<service id="sulu_content.workflow_data_mapper" class="Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper\WorkflowDataMapper">
<tag name="sulu_content.data_mapper" priority="24"/>
</service>

<service id="sulu_content.webspace_data_mapper" class="Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper\WebspaceDataMapper">
<tag name="sulu_content.data_mapper" priority="16"/>
</service>

Expand Down
3 changes: 2 additions & 1 deletion Resources/config/forms/content_settings_author.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
>
<key>content_settings_author</key>

<tag name="sulu_content.content_settings_form" instanceOf="Sulu\Bundle\ContentBundle\Content\Domain\Model\AuthorInterface" priority="50"/>
<tag name="sulu_content.content_settings_form" instanceOf="Sulu\Bundle\ContentBundle\Content\Domain\Model\AuthorInterface" priority="50"/>

<properties>
<section name="author">
Expand All @@ -18,6 +18,7 @@
<title>sulu_content.authored_date</title>
</meta>
</property>

<property name="author" type="single_contact_selection" colspan="6">
<meta>
<title>sulu_content.author</title>
Expand Down
47 changes: 47 additions & 0 deletions Resources/config/forms/content_settings_webspace.xml
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="10"/>

<properties>
<section name="webspace">
<meta>
<title>sulu_content.main_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>
4 changes: 4 additions & 0 deletions Resources/config/merger.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
</service>

<service id="sulu_content.seo_merger" class="Sulu\Bundle\ContentBundle\Content\Application\ContentMerger\Merger\SeoMerger">
<tag name="sulu_content.merger" priority="24"/>
</service>

<service id="sulu_content.webspace_merger" class="Sulu\Bundle\ContentBundle\Content\Application\ContentMerger\Merger\WebspaceMerger">
<tag name="sulu_content.merger" priority="16"/>
</service>

Expand Down
7 changes: 7 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
</service>

<service id="Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Admin\ContentViewBuilderFactoryInterface" alias="sulu_content.content_view_builder_factory"/>
<service
id="sulu_content.webspace_select"
class="Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Page\Select\WebspaceSelect"
public="true"
>
<argument type="service" id="sulu_core.webspace.webspace_manager"/>
</service>

<!-- ContentMerger -->
<service id="sulu_content.content_merger" class="Sulu\Bundle\ContentBundle\Content\Application\ContentMerger\ContentMerger">
Expand Down
6 changes: 4 additions & 2 deletions Resources/translations/admin.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"sulu_content.excerpt": "Auszug & Taxonomien",
"sulu_content.content": "Inhalt",
"sulu_content.published": "Veröffentlicht am",
"sulu_content.author": "Author",
"sulu_page.authored_date": "Authored Date"
"sulu_content.author": "Autor",
"sulu_content.authored_date": "Verfasst am",
"sulu_content.main_webspace": "Hauptwebspace",
"sulu_content.additional_webspaces": "Weitere Webspaces"
}
6 changes: 4 additions & 2 deletions Resources/translations/admin.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"sulu_content.excerpt": "Excerpt & Taxonomies",
"sulu_content.content": "Content",
"sulu_content.published": "Published on",
"sulu_content.author": "Autor",
"sulu_content.authored_date": "Verfasst am"
"sulu_content.author": "Author",
"sulu_content.authored_date": "Authored Date",
"sulu_content.main_webspace": "Main Webspace",
"sulu_content.additional_webspaces": "Weitere Webspaces"
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoTrait;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateTrait;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WebspaceInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WebspaceTrait;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowTrait;

class ExampleDimensionContent implements DimensionContentInterface, ExcerptInterface, SeoInterface, TemplateInterface, RoutableInterface, WorkflowInterface, AuthorInterface
class ExampleDimensionContent implements DimensionContentInterface, ExcerptInterface, SeoInterface, TemplateInterface, RoutableInterface, WorkflowInterface, AuthorInterface, WebspaceInterface
{
use AuthorTrait;
use DimensionContentTrait;
Expand All @@ -39,6 +41,7 @@ class ExampleDimensionContent implements DimensionContentInterface, ExcerptInter
use TemplateTrait {
setTemplateData as parentSetTemplateData;
}
use WebspaceTrait;
use WorkflowTrait;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(array $filters, int $code = 0, \Throwable $previous
$criteriaMessages = [];
foreach ($filters as $key => $value) {
if (\is_object($value)) {
$value = \get_debug_type($value);
$value = get_debug_type($value);
} else {
$value = \json_encode($value);
}
Expand Down
Loading

0 comments on commit 2c887c0

Please sign in to comment.