Commit 19879d04 authored by Tino Goratsch's avatar Tino Goratsch

- refactored the Breadcrumb so that it provides a far better extensible

parent 4047ad0a
<?php
namespace ACP3\Core;
use ACP3\Core\Breadcrumb\Title;
use ACP3\Core\Controller\AreaEnum;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\I18n\Translator;
......@@ -16,15 +17,6 @@ class Breadcrumb
*/
protected $steps = [];
/**
* @var array
*/
protected $title = [
'separator' => '-',
'prefix' => '',
'postfix' => ''
];
/**
* @var array
*/
......@@ -46,6 +38,10 @@ class Breadcrumb
* @var \ACP3\Core\RouterInterface
*/
protected $router;
/**
* @var \ACP3\Core\Breadcrumb\Title
*/
protected $title;
/**
* Breadcrumb constructor.
......@@ -54,37 +50,28 @@ class Breadcrumb
* @param \ACP3\Core\I18n\Translator $translator
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\RouterInterface $router
* @param \ACP3\Core\Breadcrumb\Title $title
*/
public function __construct(
ContainerInterface $container,
Translator $translator,
RequestInterface $request,
RouterInterface $router
RouterInterface $router,
Title $title
) {
$this->container = $container;
$this->translator = $translator;
$this->request = $request;
$this->router = $router;
}
/**
* @param string $value
*
* @return $this
*/
public function setTitleSeparator($value)
{
$this->title['separator'] = $value;
return $this;
$this->title = $title;
}
/**
* @return string
*/
public function getTitleSeparator()
public function getPageTitleSeparator()
{
return ' ' . $this->title['separator'] . ' ';
return $this->title->getPageTitleSeparator();
}
/**
......@@ -92,47 +79,25 @@ class Breadcrumb
*
* @return $this
*/
public function setTitlePrefix($value)
public function setPageTitlePostfix($value)
{
$this->title['prefix'] = $value;
$this->title->setPageTitlePostfix($value);
return $this;
}
/**
* Ersetzt die aktuell letzte Brotkrume mit neuen Werten
*
* @param string $title
* @param string $path
* @param bool $dbSteps
* @param string $value
*
* @return $this
*/
public function replaceAncestor($title, $path = '', $dbSteps = false)
public function setPageTitlePrefix($value)
{
if ($dbSteps === false) {
$index = count($this->steps) - (!empty($this->steps) ? 1 : 0);
$this->steps[$index]['title'] = $title;
$this->steps[$index]['uri'] = !empty($path) ? $this->router->route($path) : '';
}
$this->title->setPageTitlePrefix($value);
return $this;
}
/**
* Returns the breadcrumb
*
* @return array
*/
public function getBreadcrumb()
{
if (empty($this->breadcrumbCache)) {
$this->setBreadcrumbCache();
}
return $this->breadcrumbCache;
}
/**
* Returns the site title
*
......@@ -140,7 +105,7 @@ class Breadcrumb
*/
public function getSiteTitle()
{
return '';
return $this->title->getSiteTitle();
}
/**
......@@ -154,7 +119,7 @@ class Breadcrumb
$this->setBreadcrumbCache();
}
return $this->breadcrumbCache[count($this->breadcrumbCache) - 1]['title'];
return $this->title->getPageTitle();
}
/**
......@@ -164,18 +129,41 @@ class Breadcrumb
*/
public function getSiteAndPageTitle()
{
$title = $this->getPageTitle();
return $this->title->getSiteAndPageTitle();
}
$separator = ' ' . $this->title['separator'] . ' ';
if (!empty($this->title['prefix'])) {
$title = $this->title['prefix'] . $separator . $title;
/**
* Ersetzt die aktuell letzte Brotkrume mit neuen Werten
*
* @param string $title
* @param string $path
* @param bool $dbSteps
*
* @return $this
*/
public function replaceAncestor($title, $path = '', $dbSteps = false)
{
if ($dbSteps === false) {
$index = count($this->steps) - (!empty($this->steps) ? 1 : 0);
$this->steps[$index]['title'] = $title;
$this->steps[$index]['uri'] = !empty($path) ? $this->router->route($path) : '';
}
if (!empty($this->title['postfix'])) {
$title .= $separator . $this->title['postfix'];
return $this;
}
/**
* Returns the breadcrumb
*
* @return array
*/
public function getBreadcrumb()
{
if (empty($this->breadcrumbCache)) {
$this->setBreadcrumbCache();
}
$title .= ' | ' . $this->getSiteTitle();
return $title;
return $this->breadcrumbCache;
}
/**
......@@ -191,6 +179,8 @@ class Breadcrumb
// Mark the last breadcrumb
$this->breadcrumbCache[count($this->breadcrumbCache) - 1]['last'] = true;
$this->title->setPageTitle($this->breadcrumbCache[count($this->breadcrumbCache) - 1]['title']);
}
/**
......@@ -200,12 +190,14 @@ class Breadcrumb
{
if ($this->request->getModule() !== 'acp') {
// An postfix for the page title has been already set
if (!empty($this->title['postfix'])) {
$this->setTitlePostfix(
$this->title['postfix'] . $this->getTitleSeparator() . $this->translator->t('system', 'acp')
if (!empty($this->title->getPageTitlePostfix())) {
$this->setPageTitlePostfix(
$this->title->getPageTitlePostfix()
. $this->getPageTitleSeparator()
. $this->translator->t('system', 'acp')
);
} else {
$this->setTitlePostfix($this->translator->t('system', 'acp'));
$this->setPageTitlePostfix($this->translator->t('system', 'acp'));
}
}
......@@ -215,10 +207,7 @@ class Breadcrumb
if ($this->request->getModule() !== 'acp') {
$this->append(
$this->translator->t(
$this->request->getModule(),
$this->request->getModule()
),
$this->translator->t($this->request->getModule(), $this->request->getModule()),
'acp/' . $this->request->getModule()
);
......@@ -227,10 +216,7 @@ class Breadcrumb
} else { // Prepend breadcrumb steps, if there have been already some steps set
if ($this->request->getModule() !== 'acp') {
$this->prepend(
$this->translator->t(
$this->request->getModule(),
$this->request->getModule()
),
$this->translator->t($this->request->getModule(), $this->request->getModule()),
'acp/' . $this->request->getModule()
);
}
......@@ -240,18 +226,6 @@ class Breadcrumb
$this->breadcrumbCache = $this->steps;
}
/**
* @param string $value
*
* @return $this
*/
public function setTitlePostfix($value)
{
$this->title['postfix'] = $value;
return $this;
}
/**
* Zuweisung einer neuen Stufe zur Brotkrümelspur
*
......
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Breadcrumb;
/**
* Class Title
* @package ACP3\Core\Breadcrumb
*/
class Title
{
/**
* @var string
*/
protected $pageTitle = '';
/**
* @var string
*/
protected $pageTitlePostfix = '';
/**
* @var string
*/
protected $pageTitlePrefix = '';
/**
* @var string
*/
protected $pageTitleSeparator = '-';
/**
* @var string
*/
protected $siteTitle = '';
/**
* @return string
*/
public function getSiteTitle()
{
return $this->siteTitle;
}
/**
* @return string
*/
public function getPageTitle()
{
return $this->pageTitle;
}
/**
* @param string $title
*
* @return $this
*/
public function setPageTitle($title)
{
$this->pageTitle = $title;
return $this;
}
/**
* @return string
*/
public function getPageTitlePostfix()
{
return $this->pageTitlePostfix;
}
/**
* @param string $value
*
* @return $this
*/
public function setPageTitlePostfix($value)
{
$this->pageTitlePostfix = $value;
return $this;
}
/**
* @param string $value
*
* @return $this
*/
public function setPageTitlePrefix($value)
{
$this->pageTitlePrefix = $value;
return $this;
}
/**
* @return string
*/
public function getPageTitleSeparator()
{
return ' ' . $this->pageTitleSeparator . ' ';
}
/**
* @param string $value
*
* @return $this
*/
public function setPageTitleSeparator($value)
{
$this->pageTitleSeparator = $value;
return $this;
}
/**
* Returns the title of the current page + the site title
*
* @return string
*/
public function getSiteAndPageTitle()
{
$title = $this->getPageTitle();
$separator = $this->getPageTitleSeparator();
if (!empty($this->pageTitlePrefix)) {
$title = $this->pageTitlePrefix . $separator . $title;
}
if (!empty($this->pageTitlePostfix)) {
$title .= $separator . $this->pageTitlePostfix;
}
$title .= ' | ' . $this->getSiteTitle();
return $title;
}
}
......@@ -83,7 +83,7 @@ class TableOfContents
$toc[$i]['selected'] = $this->isCurrentPage($customUris, $page, $pageNumber, $i);
if ($toc[$i]['selected'] === true) {
$this->breadcrumb->setTitlePostfix($toc[$i]['title']);
$this->breadcrumb->setPageTitlePostfix($toc[$i]['title']);
}
++$i;
}
......
......@@ -177,7 +177,7 @@ class Pagination
{
if ($this->currentPage > 1) {
$postfix = $this->translator->t('system', 'page_x', ['%page%' => $this->currentPage]);
$this->breadcrumb->setTitlePostfix($postfix);
$this->breadcrumb->setPageTitlePostfix($postfix);
}
}
......
services:
core.breadcrumb:
class: ACP3\Core\Breadcrumb
arguments:
- '@service_container'
- '@core.lang'
- '@core.request'
- '@core.router'
- '@core.breadcrumb.title'
core.breadcrumb.title:
class: ACP3\Core\Breadcrumb\Title
......@@ -38,14 +38,6 @@ services:
- '@core.request'
- '@service_container'
core.breadcrumb:
class: ACP3\Core\Breadcrumb
arguments:
- '@service_container'
- '@core.lang'
- '@core.request'
- '@core.router'
core.cache.system:
class: ACP3\Core\Cache
arguments:
......
......@@ -125,7 +125,7 @@ class Edit extends AbstractFormAction
$article = $this->articleRepository->getOneById($id);
if (empty($article) === false) {
$this->breadcrumb->setTitlePostfix($article['title']);
$this->breadcrumb->setPageTitlePostfix($article['title']);
if ($this->request->getPost()->isEmpty() === false) {
return $this->executePost($this->request->getPost()->all(), $id);
......
......@@ -65,7 +65,7 @@ class Edit extends Core\Controller\AdminAction
$category = $this->categoryRepository->getOneById($id);
if (empty($category) === false) {
$this->breadcrumb->setTitlePostfix($category['title']);
$this->breadcrumb->setPageTitlePostfix($category['title']);
if ($this->request->getPost()->isEmpty() === false) {
return $this->executePost($this->request->getPost()->all(), $category, $id);
......
......@@ -91,7 +91,7 @@ class Edit extends Core\Controller\AdminAction
'acp/comments/details/index/id_' . $comment['module_id']
)
->append($this->translator->t('comments', 'admin_details_edit'))
->setTitlePostfix($comment['name']);
->setPageTitlePostfix($comment['name']);
if ($this->request->getPost()->isEmpty() === false) {
return $this->executePost(
......
......@@ -92,7 +92,7 @@ class Edit extends AbstractFormAction
if (empty($file) === false) {
$settings = $this->config->getSettings('files');
$this->breadcrumb->setTitlePostfix($file['title']);
$this->breadcrumb->setPageTitlePostfix($file['title']);
if ($this->request->getPost()->isEmpty() === false) {
return $this->executePost($this->request->getPost()->all(), $settings, $file, $id);
......
......@@ -100,7 +100,7 @@ class Edit extends AbstractFormAction
if ($this->galleryRepository->galleryExists($id) === true) {
$gallery = $this->galleryRepository->getGalleryById($id);
$this->breadcrumb->setTitlePostfix($gallery['title']);
$this->breadcrumb->setPageTitlePostfix($gallery['title']);
if ($this->request->getPost()->isEmpty() === false) {
return $this->executePost($this->request->getPost()->all(), $id);
......
......@@ -79,9 +79,9 @@ class Edit extends AbstractFormAction
$this->breadcrumb
->append($picture['title'], 'acp/gallery/index/edit/id_' . $picture['gallery_id'])
->append($this->translator->t('gallery', 'admin_pictures_edit'))
->setTitlePostfix(
->setPageTitlePostfix(
$picture['title']
. $this->breadcrumb->getTitleSeparator()
. $this->breadcrumb->getPageTitleSeparator()
. $this->translator->t('gallery', 'picture_x', ['%picture%' => $picture['pic']])
);
......
......@@ -81,8 +81,8 @@ class Details extends Core\Controller\FrontendAction
->append($this->translator->t('gallery', 'gallery'), 'gallery')
->append($picture['title'], 'gallery/index/pics/id_' . $picture['gallery_id'])
->append($this->translator->t('gallery', 'details'))
->setTitlePrefix($picture['title'])
->setTitlePostfix($this->translator->t('gallery', 'picture_x', ['%picture%' => $picture['pic']]));
->setPageTitlePrefix($picture['title'])
->setPageTitlePostfix($this->translator->t('gallery', 'picture_x', ['%picture%' => $picture['pic']]));
$picture = $this->calculatePictureDimensions($picture);
......
......@@ -85,7 +85,7 @@ class Edit extends Core\Controller\AdminAction
if (empty($guestbook) === false) {
$settings = $this->config->getSettings('guestbook');
$this->breadcrumb->setTitlePostfix($guestbook['name']);
$this->breadcrumb->setPageTitlePostfix($guestbook['name']);
if ($this->request->getPost()->isEmpty() === false) {
return $this->executePost($this->request->getPost()->all(), $settings, $id);
......
......@@ -67,7 +67,7 @@ class Edit extends Core\Controller\AdminAction
$menu = $this->menuRepository->getOneById($id);
if (empty($menu) === false) {
$this->breadcrumb->setTitlePostfix($menu['title']);
$this->breadcrumb->setPageTitlePostfix($menu['title']);
if ($this->request->getPost()->isEmpty() === false) {
return $this->executePost($this->request->getPost()->all(), $id);
......
......@@ -91,7 +91,7 @@ class Edit extends AbstractFormAction
$menuItem = $this->menuItemRepository->getOneMenuItemById($id);
if (empty($menuItem) === false) {
$this->breadcrumb->setTitlePostfix($menuItem['title']);
$this->breadcrumb->setPageTitlePostfix($menuItem['title']);
$menuItem['alias'] = $menuItem['mode'] == 2 || $menuItem['mode'] == 4 ? $this->aliases->getUriAlias($menuItem['uri'],
true) : '';
......
......@@ -13,9 +13,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class Breadcrumb extends Core\Breadcrumb
{
/**
* Enthält alle Schritte der Brotkrümelspur,
* welche sich aus der Navigationsstruktur der Website ergeben
*
* @var array
*/
protected $stepsFromDb = [];
......@@ -32,6 +29,7 @@ class Breadcrumb extends Core\Breadcrumb
* @param \ACP3\Core\I18n\Translator $translator
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\RouterInterface $router
* @param \ACP3\Core\Breadcrumb\Title $title
* @param \ACP3\Modules\ACP3\Menus\Model\MenuItemRepository $menuItemRepository
*/
public function __construct(
......@@ -39,9 +37,10 @@ class Breadcrumb extends Core\Breadcrumb
Core\I18n\Translator $translator,
RequestInterface $request,
Core\RouterInterface $router,
Core\Breadcrumb\Title $title,
Menus\Model\MenuItemRepository $menuItemRepository
) {
parent::__construct($container, $translator, $request, $router);
parent::__construct($container, $translator, $request, $router, $title);
$this->menuItemRepository = $menuItemRepository;
......@@ -76,9 +75,7 @@ class Breadcrumb extends Core\Breadcrumb
* Zuweisung einer neuen Stufe zur Brotkrümelspur
*
* @param string $title
* Bezeichnung der jeweiligen Stufe der Brotkrume
* @param string $path
* Die zum $title zugehörige ACP3-interne URI
*
* @return $this
*/
......@@ -96,9 +93,7 @@ class Breadcrumb extends Core\Breadcrumb
* Ersetzt die aktuell letzte Brotkrume mit neuen Werten
*
* @param string $title
* Bezeichnung der jeweiligen Stufe der Brotkrume
* @param string $path
* Die zum $title zugehörige ACP3-interne URI
* @param bool $dbSteps
*
* @return $this
......
......@@ -9,4 +9,5 @@ services:
- '@core.lang'
- '@core.request'
- '@core.router'
- '@core.breadcrumb.title'
- '@menus.model.menuitemrepository'
......@@ -82,7 +82,7 @@ class Edit extends AbstractFormAction
$news = $this->newsRepository->getOneById($id);
if (empty($news) === false) {
$this->breadcrumb->setTitlePostfix($news['title']);
$this->breadcrumb->setPageTitlePostfix($news['title']);
$settings = $this->config->getSettings('news');
......
......@@ -75,7 +75,7 @@ class Edit extends AbstractFormAction
$newsletter = $this->newsletterRepository->getOneById($id);
if (empty($newsletter) === false) {
$this->breadcrumb->setTitlePostfix($newsletter['title']);
$this->breadcrumb->setPageTitlePostfix($newsletter['title']);
$settings = $this->config->getSettings('newsletter');
......
......@@ -74,7 +74,7 @@ class Edit extends AbstractFormAction
$role = $this->roleRepository->getRoleById($id);
if (!empty($role)) {
$this->breadcrumb->setTitlePostfix($role['name']);
$this->breadcrumb->setPageTitlePostfix($role['name']);
if ($this->request->getPost()->isEmpty() === false) {
return $this->executePost($this->request->getPost()->all(), $id);
......
......@@ -70,7 +70,7 @@ class Edit extends AbstractFormAction
$poll = $this->pollRepository->getOneById($id);
if (empty($poll) === false) {
$this->breadcrumb->setTitlePostfix($poll['title']);
$this->breadcrumb->setPageTitlePostfix($poll['title']);
if ($this->request->getPost()->has('submit')) {
return $this->executePost($this->request->getPost()->all(), $id);
......
......@@ -74,7 +74,7 @@ class Edit extends Core\Controller\AdminAction
$seo = $this->seoRepository->getOneById($id);
if (empty($seo) === false) {
$this->breadcrumb->setTitlePostfix($seo['alias']);
$this->breadcrumb->setPageTitlePostfix($seo['alias']);
if ($this->request->getPost()->isEmpty() === false) {
return $this->executePost($this->request->getPost()->all(), $seo['uri'], $id);
......
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\Seo\Core;
use ACP3\Core\Config;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\I18n\Translator;
use ACP3\Core\RouterInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class Breadcrumb
* @package ACP3\Modules\ACP3\Seo\Core
*/
class Breadcrumb extends \ACP3\Core\Breadcrumb
{
/**
* @var \ACP3\Core\Config
*/
protected $config;
/**
* Breadcrumb constructor.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* @param \ACP3\Core\I18n\Translator $translator
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\RouterInterface $router
* @param \ACP3\Core\Config $config
*/
public function __construct(
ContainerInterface $container,
Translator $translator,
RequestInterface $request,
RouterInterface $router,
Config $config
) {
parent::__construct($container, $translator, $request, $router);
$this->config = $config;
}
/**
* @inheritdoc
*/
public function getSiteTitle()
{
return $this->config->getSettings('seo')['title'];
}
}