implement new breadcrumb on image and document edition in the catalog
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\HomeController::defaultAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.home.view" path="/admin/latest-thelia-version">
|
||||
<route id="admin.home.latestVersion" path="/admin/latest-thelia-version">
|
||||
<default key="_controller">Thelia\Controller\Admin\HomeController::getLatestTheliaVersion</default>
|
||||
</route>
|
||||
|
||||
|
||||
@@ -312,7 +312,8 @@ class FileController extends BaseAdminController
|
||||
'imageId' => $imageId,
|
||||
'imageType' => $parentType,
|
||||
'redirectUrl' => $redirectUrl,
|
||||
'formId' => $fileManager->getFormId($parentType, FileManager::FILE_TYPE_IMAGES)
|
||||
'formId' => $fileManager->getFormId($parentType, FileManager::FILE_TYPE_IMAGES),
|
||||
'breadcrumb' => $image->getBreadcrumb($this->getRouter($this->getCurrentRouter()), $this->container, 'images')
|
||||
));
|
||||
} catch (\Exception $e) {
|
||||
$this->pageNotFound();
|
||||
@@ -341,7 +342,8 @@ class FileController extends BaseAdminController
|
||||
'documentId' => $documentId,
|
||||
'documentType' => $parentType,
|
||||
'redirectUrl' => $redirectUrl,
|
||||
'formId' => $fileManager->getFormId($parentType, FileManager::FILE_TYPE_DOCUMENTS)
|
||||
'formId' => $fileManager->getFormId($parentType, FileManager::FILE_TYPE_DOCUMENTS),
|
||||
'breadcrumb' => $document->getBreadcrumb($this->getRouter($this->getCurrentRouter()), $this->container, 'documents')
|
||||
));
|
||||
} catch (\Exception $e) {
|
||||
$this->pageNotFound();
|
||||
|
||||
@@ -291,7 +291,7 @@ abstract class BaseController extends ContainerAware
|
||||
protected function getRouteFromRouter($routerName, $routeId, $parameters = array(), $referenceType = Router::ABSOLUTE_URL)
|
||||
{
|
||||
/** @var Router $router */
|
||||
$router = $this->container->get($routerName);
|
||||
$router = $this->getRouter($routerName);
|
||||
|
||||
if ($router == null) {
|
||||
throw new \InvalidArgumentException(sprintf("Router '%s' does not exists.", $routerName));
|
||||
@@ -300,6 +300,15 @@ abstract class BaseController extends ContainerAware
|
||||
return $router->generate($routeId, $parameters, $referenceType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $routerName
|
||||
* @return Router
|
||||
*/
|
||||
protected function getRouter($routerName)
|
||||
{
|
||||
return $this->container->get($routerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 404 error
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
||||
|
||||
28
core/lib/Thelia/Model/Breadcrumb/BreadcrumbInterface.php
Normal file
28
core/lib/Thelia/Model/Breadcrumb/BreadcrumbInterface.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Model\Breadcrumb;
|
||||
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Router;
|
||||
|
||||
interface BreadcrumbInterface {
|
||||
|
||||
/**
|
||||
*
|
||||
* return the complete breadcrumb for a given resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBreadcrumb(Router $router, ContainerInterface $container, $tab);
|
||||
}
|
||||
85
core/lib/Thelia/Model/Breadcrumb/CatalogBreadcrumbTrait.php
Normal file
85
core/lib/Thelia/Model/Breadcrumb/CatalogBreadcrumbTrait.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Model\Breadcrumb;
|
||||
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Core\Template\Loop\CategoryPath;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
trait CatalogBreadcrumbTrait {
|
||||
|
||||
public function getBaseBreadcrumb(Router $router, ContainerInterface $container, $categoryId, &$locale)
|
||||
{
|
||||
$translator = Translator::getInstance();
|
||||
$catalogUrl = $router->generate('admin.catalog', [], Router::ABSOLUTE_URL);
|
||||
$breadcrumb = [
|
||||
$translator->trans('Home', [], 'bo.default') => $router->generate('admin.home.view', [], Router::ABSOLUTE_URL),
|
||||
$translator->trans('Catalog', [], 'bo.default') => $catalogUrl,
|
||||
];
|
||||
|
||||
$categoryPath = new CategoryPath($container);
|
||||
$categoryPath->initializeArgs([
|
||||
'category' => $categoryId,
|
||||
'visible' => '*'
|
||||
]);
|
||||
|
||||
$results = $categoryPath->buildArray();
|
||||
|
||||
foreach ($results as $result) {
|
||||
$breadcrumb[$result['TITLE']] = sprintf("%s?category_id=%d",$catalogUrl, $result['ID']);
|
||||
}
|
||||
|
||||
$locale = $result['LOCALE'];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function getProductBreadcrumb(Router $router, ContainerInterface $container, $tab)
|
||||
{
|
||||
$product = $this->getProduct();
|
||||
$locale = null;
|
||||
|
||||
$breadcrumb = $this->getBaseBreadcrumb($router, $container, $product->getDefaultCategoryId(), $locale);
|
||||
|
||||
$product->setLocale($locale);
|
||||
|
||||
$request = $container->get('request');
|
||||
//$breadcrumb[$product->getTitle()] = $product->getUrl().'¤t_tab=images';
|
||||
$breadcrumb[$product->getTitle()] = sprintf("%s?product_id=%d¤t_tab=%s",
|
||||
$router->generate('admin.products.update', [], Router::ABSOLUTE_URL),
|
||||
$product->getId(),
|
||||
$tab
|
||||
);
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function getCategoryBreadcrumb(Router $router, ContainerInterface $container, $tab)
|
||||
{
|
||||
$locale = null;
|
||||
$category = $this->getCategory();
|
||||
$breadcrumb = $this->getBaseBreadcrumb($router, $container, $this->getParentId(), $locale);
|
||||
|
||||
$category->setLocale($locale);
|
||||
|
||||
$breadcrumb[$category->getTitle()] = sprintf("%s?category_id=%d¤t_tab=%s",
|
||||
$router->generate('admin.categories.update',[], Router::ABSOLUTE_URL),
|
||||
$category->getId(),
|
||||
$tab
|
||||
);
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,20 @@
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Model\Base\CategoryDocument as BaseCategoryDocument;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Thelia\Model\Breadcrumb\BreadcrumbInterface;
|
||||
use Thelia\Model\Breadcrumb\CatalogBreadcrumbTrait;
|
||||
use Thelia\Model\Tools\PositionManagementTrait;
|
||||
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
class CategoryDocument extends BaseCategoryDocument
|
||||
class CategoryDocument extends BaseCategoryDocument implements BreadcrumbInterface
|
||||
{
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
use ModelEventDispatcherTrait;
|
||||
use PositionManagementTrait;
|
||||
use CatalogBreadcrumbTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
@@ -62,4 +69,15 @@ class CategoryDocument extends BaseCategoryDocument
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* return the complete breadcrumb for a given resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBreadcrumb(Router $router, ContainerInterface $container, $tab)
|
||||
{
|
||||
return $this->getCategoryBreadcrumb($router, $container, $tab);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,20 @@
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Model\Base\CategoryImage as BaseCategoryImage;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Thelia\Model\Breadcrumb\BreadcrumbInterface;
|
||||
use Thelia\Model\Breadcrumb\CatalogBreadcrumbTrait;
|
||||
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
class CategoryImage extends BaseCategoryImage
|
||||
class CategoryImage extends BaseCategoryImage implements BreadcrumbInterface
|
||||
{
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
use ModelEventDispatcherTrait;
|
||||
use PositionManagementTrait;
|
||||
use CatalogBreadcrumbTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
@@ -62,4 +69,15 @@ class CategoryImage extends BaseCategoryImage
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* return the complete breadcrumb for a given resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBreadcrumb(Router $router, ContainerInterface $container, $tab)
|
||||
{
|
||||
return $this->getCategoryBreadcrumb($router, $container, $tab);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,20 @@
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Model\Base\ProductDocument as BaseProductDocument;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Thelia\Model\Breadcrumb\BreadcrumbInterface;
|
||||
use Thelia\Model\Breadcrumb\CatalogBreadcrumbTrait;
|
||||
use Thelia\Model\Tools\PositionManagementTrait;
|
||||
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
class ProductDocument extends BaseProductDocument
|
||||
class ProductDocument extends BaseProductDocument implements BreadcrumbInterface
|
||||
{
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
use ModelEventDispatcherTrait;
|
||||
use PositionManagementTrait;
|
||||
use CatalogBreadcrumbTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
@@ -63,4 +70,14 @@ class ProductDocument extends BaseProductDocument
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* return the complete breadcrumb for a given resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBreadcrumb(Router $router, ContainerInterface $container, $tab)
|
||||
{
|
||||
return $this->getProductBreadcrumb($router, $container, $tab);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,23 @@
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Core\Template\Loop\CategoryPath;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\Base\ProductImage as BaseProductImage;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Thelia\Model\Breadcrumb\BreadcrumbInterface;
|
||||
use Thelia\Model\Breadcrumb\CatalogBreadcrumbTrait;
|
||||
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use Thelia\Model\Tools\PositionManagementTrait;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
class ProductImage extends BaseProductImage
|
||||
class ProductImage extends BaseProductImage implements BreadcrumbInterface
|
||||
{
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
use ModelEventDispatcherTrait;
|
||||
use PositionManagementTrait;
|
||||
use CatalogBreadcrumbTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
@@ -62,4 +72,15 @@ class ProductImage extends BaseProductImage
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* return the complete breadcrumb for a given resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBreadcrumb(Router $router, ContainerInterface $container, $tab)
|
||||
{
|
||||
return $this->getProductBreadcrumb($router, $container, $tab);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
|
||||
{loop type="document" name="document_edit" source="{$documentType}" id="{$documentId}" backend_context="1" lang="$edit_language_id"}
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
|
||||
<li><a href="{url path="{$redirectUrl}"}">{intl l="Document"}</a></li>
|
||||
{foreach $breadcrumb as $label=>$link}
|
||||
<li><a href="{$link}">{$label}</a></li>
|
||||
{/foreach}
|
||||
<li>{intl l='Editing document "%name"' name="{$TITLE}"}</li>
|
||||
</ul>
|
||||
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
|
||||
{loop type="image" name="image_edit" source="{$imageType}" id="{$imageId}" width="580" backend_context="1" lang="$edit_language_id"}
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
|
||||
<li><a href="{url path="{$redirectUrl}"}">{intl l="Image"}</a></li>
|
||||
{foreach $breadcrumb as $label=>$link}
|
||||
<li><a href="{$link}">{$label}</a></li>
|
||||
{/foreach}
|
||||
<li>{intl l='Editing image "%name"' name={$TITLE}}</li>
|
||||
</ul>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user