-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e3f8a45
Showing
7 changed files
with
301 additions
and
0 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,7 @@ | ||
Copyright 2018 Mateusz Bieniek | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,23 @@ | ||
# ezplatform-page-builder-multisite-siteaccess-picker | ||
## Description | ||
The bundle provides an alternative way of selecting SiteAccess for PageBuilder when Landing Page | ||
is edited by clicking on the "Edit" button. | ||
By default last used SiteAccess is taken and this Bundle changes this behavior so it | ||
is better suited for the Multisite setup. | ||
|
||
If Landing Page is outside of last used SiteAccess Subtree, first SiteAccess that shares | ||
Subtree with Landing Page will be used. | ||
|
||
## Installation | ||
**Requires eZ Platform Enterprise Edition 2.5 LTS** | ||
|
||
### 1. Enable `EzPlatformPageBuilderMultisiteSiteaccessPickerBundle` | ||
Edit `app/AppKernel.php`, and add | ||
``` | ||
new MateuszBieniek\EzPlatformPageBuilderMultisiteSiteaccessPickerBundle\EzPlatformPageBuilderMultisiteSiteaccessPickerBundle(), | ||
``` | ||
at the end of the `$bundles` array. | ||
### 2. Install `mateuszbieniek/ezplatform-page-builder-multisite-siteaccess-picker` | ||
``` | ||
composer require mateuszbieniek/ezplatform-page-builder-multisite-siteaccess-picker | ||
``` |
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,29 @@ | ||
{ | ||
"name": "mateuszbieniek/ezplatform-page-builder-multisite-siteaccess-picker", | ||
"license": "MIT", | ||
"type": "ezplatform-bundle", | ||
"description": "The bundle provides an alternative way of selecting SiteAccess for PageBuilder when Landing Page is edited by clicking on the \"Edit\" button", | ||
"repositories": [ | ||
{ | ||
"type": "composer", | ||
"url": "https://updates.ez.no/ttl" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"MateuszBieniek\\EzPlatformPageBuilderMultisiteSiteaccessPickerBundle\\": "src/bundle/" | ||
} | ||
}, | ||
"require": { | ||
"php": ">=7.1", | ||
"ezsystems/ezpublish-kernel": "^7.5", | ||
"ezsystems/ezplatform-page-builder": "^1.3" | ||
}, | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "2.7.*", | ||
"phpunit/phpunit": "~7.0" | ||
}, | ||
"scripts": { | ||
"fix-cs": "@php ./vendor/bin/php-cs-fixer fix -v --show-progress=estimating" | ||
} | ||
} |
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,187 @@ | ||
<?php | ||
|
||
namespace MateuszBieniek\EzPlatformPageBuilderMultisiteSiteaccessPickerBundle\Controller; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Location; | ||
use EzSystems\EzPlatformAdminUi\View\ContentTranslateView; | ||
use EzSystems\EzPlatformAdminUiBundle\Controller\Controller; | ||
use EzSystems\EzPlatformPageBuilder\Siteaccess\SiteaccessService; | ||
use EzSystems\EzPlatformPageBuilder\View\PageView; | ||
use EzSystems\EzPlatformPageBuilderBundle\Controller\PageController as PageBuilderPageController; | ||
use EzSystems\EzPlatformPageBuilderBundle\DependencyInjection\EzPlatformPageBuilderExtension; | ||
use EzSystems\RepositoryForms\Content\View\ContentCreateView; | ||
use EzSystems\RepositoryForms\Content\View\ContentEditView; | ||
use http\Exception\RuntimeException; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use EzSystems\EzPlatformPageBuilder\PageBuilder; | ||
use Symfony\Component\HttpFoundation\Session\Session; | ||
|
||
class PageController extends Controller | ||
{ | ||
/** @var PageBuilderPageController */ | ||
private $pageController; | ||
|
||
/** @var \EzSystems\EzPlatformPageBuilder\PageBuilder\PermissionAwareConfigurationResolver */ | ||
private $pageBuilderPermissionAwareConfigurationResolver; | ||
|
||
/** @var \Symfony\Component\HttpFoundation\Session\Session */ | ||
private $session; | ||
|
||
/** @var \EzSystems\EzPlatformPageBuilder\Siteaccess\SiteaccessService */ | ||
private $siteaccessService; | ||
|
||
public function __construct( | ||
PageBuilderPageController $pageController, | ||
PageBuilder\ConfigurationResolverInterface $pageBuilderPermissionAwareConfigurationResolver, | ||
Session $session, | ||
SiteaccessService $siteaccessService | ||
) { | ||
$this->pageController = $pageController; | ||
$this->pageBuilderPermissionAwareConfigurationResolver = $pageBuilderPermissionAwareConfigurationResolver; | ||
$this->session = $session; | ||
$this->siteaccessService = $siteaccessService; | ||
} | ||
|
||
public function previewAction(Request $request) | ||
{ | ||
return $this->pageController->previewAction($request); | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* @param int $locationId | ||
* @param int|null $versionNo | ||
* @param string|null $siteaccessName | ||
* | ||
* @return \EzSystems\EzPlatformPageBuilder\View\PageView | ||
* | ||
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException | ||
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException | ||
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException | ||
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException | ||
* @throws \Exception | ||
*/ | ||
public function locationViewAction( | ||
Request $request, | ||
int $locationId, | ||
?int $versionNo = null, | ||
?string $siteaccessName = null | ||
): PageView { | ||
return $this->pageController->locationViewAction($request, $locationId, $versionNo, $siteaccessName); | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* @param string $url | ||
* | ||
* @return \EzSystems\EzPlatformPageBuilder\View\PageView | ||
* | ||
* @throws \eZ\Publish\Core\MVC\Exception\InvalidSiteAccessException | ||
* @throws \Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException | ||
* @throws \Symfony\Component\Translation\Exception\InvalidArgumentException | ||
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException | ||
* @throws \Exception | ||
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException | ||
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException | ||
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException | ||
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType | ||
*/ | ||
public function urlViewAction(Request $request, string $url): PageView | ||
{ | ||
return $this->pageController->urlViewAction($request, $url); | ||
} | ||
|
||
/** | ||
* @param \EzSystems\RepositoryForms\Content\View\ContentEditView $view | ||
* | ||
* @return \EzSystems\RepositoryForms\Content\View\ContentEditView | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function editAction(Request $request, ContentEditView $view): ContentEditView | ||
{ | ||
$location = $view->getLocation(); | ||
$siteaccesses = $this->pageBuilderPermissionAwareConfigurationResolver->getSiteaccessList(); | ||
$currentSiteaccess = $this->session->get(EzPlatformPageBuilderExtension::SESSION_KEY_SITEACCESS, reset($siteaccesses)); | ||
|
||
if (!$this->isLocationInSiteaccessSubTree($currentSiteaccess, $location)) { | ||
$currentSiteaccess = null; | ||
|
||
foreach ($siteaccesses as $availableSiteaccess) { | ||
if ($this->isLocationInSiteaccessSubTree($availableSiteaccess, $location)) { | ||
$currentSiteaccess = $availableSiteaccess; | ||
|
||
break; | ||
} | ||
} | ||
} | ||
|
||
if (!$currentSiteaccess) { | ||
throw new RuntimeException('No siteaccess available for this Page'); | ||
} | ||
|
||
$this->session->set(EzPlatformPageBuilderExtension::SESSION_KEY_SITEACCESS, $currentSiteaccess); | ||
|
||
return $this->pageController->editAction($request, $view); | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* @param \EzSystems\RepositoryForms\Content\View\ContentCreateView $view | ||
* | ||
* @return \EzSystems\RepositoryForms\Content\View\ContentCreateView | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function createAction(Request $request, ContentCreateView $view): ContentCreateView | ||
{ | ||
return $this->pageController->createAction($request, $view); | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* @param int $locationId | ||
* @param string|null $siteaccessName | ||
* | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
public function createDraftAction( | ||
Request $request, | ||
int $locationId, | ||
?string $siteaccessName = null | ||
): Response { | ||
return $this->pageController->createDraftAction($request, $locationId, $siteaccessName); | ||
} | ||
|
||
/** | ||
* @param \EzSystems\EzPlatformAdminUi\View\ContentTranslateView $view | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* | ||
* @return \EzSystems\EzPlatformAdminUi\View\ContentTranslateView | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function translateAction(ContentTranslateView $view, Request $request): ContentTranslateView | ||
{ | ||
return $this->pageController->translateAction($view, $request); | ||
} | ||
|
||
/** | ||
* @param string $siteaccess | ||
* @param \eZ\Publish\API\Repository\Values\Content\Location $location | ||
* | ||
* @return boolean | ||
* | ||
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException | ||
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException | ||
*/ | ||
private function isLocationInSiteaccessSubTree(string $siteaccess, Location $location): bool | ||
{ | ||
$rootLocation = $this->siteaccessService->getRootLocation($siteaccess); | ||
|
||
return false !== strpos($location->pathString, $rootLocation->pathString) | ||
? true | ||
: false; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/bundle/DependencyInjection/EzPlatformPageBuilderMultisiteSiteaccessPickerExtension.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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MateuszBieniek\EzPlatformPageBuilderMultisiteSiteaccessPickerBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
class EzPlatformPageBuilderMultisiteSiteaccessPickerExtension extends Extension | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$loader = new YamlFileLoader( | ||
$container, | ||
new FileLocator(__DIR__ . '/../Resources/config') | ||
); | ||
|
||
$loader->load('services.yml'); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/bundle/EzPlatformPageBuilderMultisiteSiteaccessPickerBundle.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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MateuszBieniek\EzPlatformPageBuilderMultisiteSiteaccessPickerBundle; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class EzPlatformPageBuilderMultisiteSiteaccessPickerBundle extends Bundle | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function build(ContainerBuilder $container): 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,9 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
MateuszBieniek\EzPlatformPageBuilderMultisiteSiteaccessPickerBundle\Controller\PageController: | ||
decorates: EzSystems\EzPlatformPageBuilderBundle\Controller\PageController | ||
arguments: ['@MateuszBieniek\EzPlatformPageBuilderMultisiteSiteaccessPickerBundle\Controller\PageController.inner'] |