diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 348c1d7ec..5dd991c3a 100644 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -16,7 +16,7 @@ Thelia\Controller\Admin\HomeController::defaultAction - + Thelia\Controller\Admin\HomeController::getLatestTheliaVersion diff --git a/core/lib/Thelia/Controller/Admin/FileController.php b/core/lib/Thelia/Controller/Admin/FileController.php index 01bbad521..3b8bd0507 100644 --- a/core/lib/Thelia/Controller/Admin/FileController.php +++ b/core/lib/Thelia/Controller/Admin/FileController.php @@ -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(); diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 162b5a814..41fa50067 100644 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -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 diff --git a/core/lib/Thelia/Model/Breadcrumb/BreadcrumbInterface.php b/core/lib/Thelia/Model/Breadcrumb/BreadcrumbInterface.php new file mode 100644 index 000000000..9be24e173 --- /dev/null +++ b/core/lib/Thelia/Model/Breadcrumb/BreadcrumbInterface.php @@ -0,0 +1,28 @@ +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; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Model/CategoryDocument.php b/core/lib/Thelia/Model/CategoryDocument.php index a8cb463b7..4b20d8a59 100644 --- a/core/lib/Thelia/Model/CategoryDocument.php +++ b/core/lib/Thelia/Model/CategoryDocument.php @@ -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); + } } diff --git a/core/lib/Thelia/Model/CategoryImage.php b/core/lib/Thelia/Model/CategoryImage.php index f21a6d37c..5c277eba6 100644 --- a/core/lib/Thelia/Model/CategoryImage.php +++ b/core/lib/Thelia/Model/CategoryImage.php @@ -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); + } } diff --git a/core/lib/Thelia/Model/ProductDocument.php b/core/lib/Thelia/Model/ProductDocument.php index 3e72a0d2b..cd00bdb1b 100644 --- a/core/lib/Thelia/Model/ProductDocument.php +++ b/core/lib/Thelia/Model/ProductDocument.php @@ -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); + } } diff --git a/core/lib/Thelia/Model/ProductImage.php b/core/lib/Thelia/Model/ProductImage.php index 24cfee695..981642efa 100644 --- a/core/lib/Thelia/Model/ProductImage.php +++ b/core/lib/Thelia/Model/ProductImage.php @@ -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); + } } diff --git a/templates/backOffice/default/document-edit.html b/templates/backOffice/default/document-edit.html index f8caa97aa..7d7e12cf8 100644 --- a/templates/backOffice/default/document-edit.html +++ b/templates/backOffice/default/document-edit.html @@ -11,8 +11,9 @@ {loop type="document" name="document_edit" source="{$documentType}" id="{$documentId}" backend_context="1" lang="$edit_language_id"} diff --git a/templates/backOffice/default/image-edit.html b/templates/backOffice/default/image-edit.html index 0461ce1a8..464e3a9ad 100644 --- a/templates/backOffice/default/image-edit.html +++ b/templates/backOffice/default/image-edit.html @@ -11,8 +11,9 @@ {loop type="image" name="image_edit" source="{$imageType}" id="{$imageId}" width="580" backend_context="1" lang="$edit_language_id"}