-
Notifications
You must be signed in to change notification settings - Fork 60
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
Showing
9 changed files
with
213 additions
and
18 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
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
88 changes: 88 additions & 0 deletions
88
src/lib/Form/Type/ChoiceList/Loader/SiteAccessChoiceLoader.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,88 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Loader; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Location; | ||
use EzSystems\EzPlatformAdminUi\Siteaccess\NonAdminSiteaccessResolver; | ||
use Symfony\Component\Form\ChoiceList\ArrayChoiceList; | ||
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface; | ||
|
||
class SiteAccessChoiceLoader implements ChoiceLoaderInterface | ||
{ | ||
/** @var \EzSystems\EzPlatformAdminUi\Siteaccess\NonAdminSiteaccessResolver */ | ||
private $nonAdminSiteaccessResolver; | ||
|
||
/** @var \eZ\Publish\API\Repository\Values\Content\Location|null */ | ||
private $location; | ||
|
||
public function __construct( | ||
NonAdminSiteaccessResolver $nonAdminSiteaccessResolver, | ||
?Location $location = null | ||
) { | ||
$this->nonAdminSiteaccessResolver = $nonAdminSiteaccessResolver; | ||
$this->location = $location; | ||
} | ||
|
||
/** | ||
* Provides data in format: | ||
* [ | ||
* site_access => location_id, | ||
* ... | ||
* ]. | ||
* | ||
* @return int[] | ||
*/ | ||
public function getChoiceList(): array | ||
{ | ||
$siteAccesses = $this->location === null | ||
? $this->nonAdminSiteaccessResolver->getSiteaccesses() | ||
: $this->nonAdminSiteaccessResolver->getSiteaccessesForLocation($this->location); | ||
|
||
$data = []; | ||
foreach ($siteAccesses as $siteAccess) { | ||
$data[$siteAccess] = $siteAccess; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
public function loadChoiceList($value = null) | ||
{ | ||
$choices = $this->getChoiceList(); | ||
|
||
return new ArrayChoiceList($choices, $value); | ||
} | ||
|
||
public function loadChoicesForValues(array $values, $value = null) | ||
{ | ||
// Optimize | ||
$values = array_filter($values); | ||
if (empty($values)) { | ||
return []; | ||
} | ||
|
||
return $this->loadChoiceList($value)->getChoicesForValues($values); | ||
} | ||
|
||
public function loadValuesForChoices(array $choices, $value = null) | ||
{ | ||
// Optimize | ||
$choices = array_filter($choices); | ||
if (empty($choices)) { | ||
return []; | ||
} | ||
|
||
// If no callable is set, choices are the same as values | ||
if (null === $value) { | ||
return $choices; | ||
} | ||
|
||
return $this->loadChoiceList($value)->getValuesForChoices($choices); | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
src/lib/Tests/Form/Data/Content/CustomUrl/CustomUrlAddDataTest.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,32 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformAdminUi\Tests\Form\Data\Content\CustomUrl; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Language; | ||
use eZ\Publish\Core\Repository\Values\Content\Location; | ||
use EzSystems\EzPlatformAdminUi\Form\Data\Content\CustomUrl\CustomUrlAddData; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CustomUrlAddDataTest extends TestCase | ||
{ | ||
public function testConstruct(): void | ||
{ | ||
$location = new Location(['id' => 2]); | ||
$language = new Language(['languageCode' => 'eng-GB']); | ||
$path = '/test'; | ||
$siteAccess = 'site3'; | ||
|
||
$data = new CustomUrlAddData($location, $path, $language, false, true, $siteAccess); | ||
|
||
$this->assertSame($location, $data->getLocation()); | ||
$this->assertSame($language, $data->getLanguage()); | ||
$this->assertSame($path, $data->getPath()); | ||
$this->assertSame($siteAccess, $data->getSiteAccess()); | ||
} | ||
} |