dispatch event when generate new url
This commit is contained in:
60
core/lib/Thelia/Core/Event/GenerateRewrittenUrlEvent.php
Normal file
60
core/lib/Thelia/Core/Event/GenerateRewrittenUrlEvent.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
|
||||
|
||||
/**
|
||||
* Class GenerateRewrittenUrlEvent
|
||||
* @package Thelia\Core\Event
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class GenerateRewrittenUrlEvent extends ActionEvent {
|
||||
|
||||
protected $object;
|
||||
protected $locale;
|
||||
|
||||
protected $url;
|
||||
|
||||
public function __construct($object, $locale)
|
||||
{
|
||||
$this->object;
|
||||
$this->locale;
|
||||
}
|
||||
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function isRewritten()
|
||||
{
|
||||
return null !== $this->url;
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -441,4 +441,9 @@ final class TheliaEvents
|
||||
*/
|
||||
const MAILTRANSPORTER_CONFIG = 'action.mailertransporter.config';
|
||||
|
||||
/**
|
||||
* sent when Thelia try to generate a rewriten url
|
||||
*/
|
||||
const GENERATE_REWRITTENURL = 'action.generate_rewritenurl';
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
namespace Thelia\Model\Tools;
|
||||
|
||||
use Thelia\Core\Event\GenerateRewrittenUrlEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Exception\UrlRewritingException;
|
||||
use Thelia\Model\RewritingUrlQuery;
|
||||
use Thelia\Model\RewritingUrl;
|
||||
@@ -61,6 +63,16 @@ trait UrlRewritingTrait {
|
||||
|
||||
$this->setLocale($locale);
|
||||
|
||||
$generateEvent = new GenerateRewrittenUrlEvent($this, $locale);
|
||||
|
||||
$this->dispatchEvent(TheliaEvents::GENERATE_REWRITTENURL, $generateEvent);
|
||||
|
||||
|
||||
if($generateEvent->isRewritten())
|
||||
{
|
||||
return $generateEvent->getUrl();
|
||||
}
|
||||
|
||||
$title = $this->getTitle();
|
||||
|
||||
if(null == $title) {
|
||||
|
||||
Reference in New Issue
Block a user