-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1129 from Victoire/feature/add-permalink
Feature/add permalink
- Loading branch information
Showing
25 changed files
with
278 additions
and
31 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
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
11 changes: 11 additions & 0 deletions
11
Bundle/CoreBundle/Resources/translations/validators.en.xliff
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
<file source-language="en" target-language="en" datatype="plaintext" original="not.available"> | ||
<body> | ||
<trans-unit id="564432933783321f38899" resname="victoire.url.alreadyInUse"> | ||
<source>victoire.url.alreadyInUse</source> | ||
<target>The url is already in use.</target> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
11 changes: 11 additions & 0 deletions
11
Bundle/CoreBundle/Resources/translations/validators.es.xliff
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
<file source-language="en" target-language="es" datatype="plaintext" original="not.available"> | ||
<body> | ||
<trans-unit id="564432933783321f38899" resname="victoire.url.alreadyInUse"> | ||
<source>victoire.url.alreadyInUse</source> | ||
<target>La url ya está en uso.</target> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
11 changes: 11 additions & 0 deletions
11
Bundle/CoreBundle/Resources/translations/validators.fr.xliff
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
<file source-language="en" target-language="fr" datatype="plaintext" original="not.available"> | ||
<body> | ||
<trans-unit id="564432933783321f38899" resname="victoire.url.alreadyInUse"> | ||
<source>victoire.url.alreadyInUse</source> | ||
<target>L'url est déjà utilisée.</target> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
22 changes: 22 additions & 0 deletions
22
Bundle/CoreBundle/Validator/Constraints/UniquePermalink.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,22 @@ | ||
<?php | ||
|
||
namespace Victoire\Bundle\CoreBundle\Validator\Constraints; | ||
|
||
use Symfony\Component\Validator\Constraint; | ||
use Victoire\Bundle\CoreBundle\Validator\UniquePermalinkValidator; | ||
|
||
/** | ||
* @Annotation | ||
*/ | ||
class UniquePermalink extends Constraint | ||
{ | ||
public function validatedBy() | ||
{ | ||
return UniquePermalinkValidator::class; | ||
} | ||
|
||
public function getTargets() | ||
{ | ||
return self::CLASS_CONSTRAINT; | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
namespace Victoire\Bundle\CoreBundle\Validator; | ||
|
||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
use Victoire\Bundle\CoreBundle\Entity\WebViewInterface; | ||
use Victoire\Bundle\CoreBundle\Helper\UrlBuilder; | ||
use Victoire\Bundle\ViewReferenceBundle\Connector\ViewReferenceRepository; | ||
|
||
class UniquePermalinkValidator extends ConstraintValidator | ||
{ | ||
private $viewReferenceRepository; | ||
private $requestStack; | ||
private $urlBuilder; | ||
|
||
/** | ||
* UniquePermalinkValidator constructor. | ||
* | ||
* @param ViewReferenceRepository $viewReferenceRepository | ||
* @param RequestStack $requestStack | ||
* @param UrlBuilder $urlBuilder | ||
*/ | ||
public function __construct(ViewReferenceRepository $viewReferenceRepository, RequestStack $requestStack, UrlBuilder $urlBuilder) | ||
{ | ||
$this->viewReferenceRepository = $viewReferenceRepository; | ||
$this->requestStack = $requestStack; | ||
$this->urlBuilder = $urlBuilder; | ||
} | ||
|
||
/** | ||
* @param View $view | ||
* @param Constraint $constraint | ||
*/ | ||
public function validate($view, Constraint $constraint) | ||
{ | ||
if ($view instanceof WebViewInterface && ($url = $this->urlBuilder->buildUrl($view)) != '') { | ||
$viewReference = $this->viewReferenceRepository->getReferenceByUrl( | ||
$url, | ||
$this->requestStack->getCurrentRequest()->getLocale() | ||
); | ||
|
||
if ($viewReference && $viewReference->getViewId() != $view->getId()) { | ||
$this->context->buildViolation('victoire.url.alreadyInUse') | ||
->atPath('permalink') | ||
->addViolation(); | ||
} | ||
} | ||
} | ||
} |
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
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.