-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Configuration option for automatic embedding of a breadcrum…
…b in pages Resolves: #20
- Loading branch information
1 parent
f13648f
commit 40ea659
Showing
10 changed files
with
402 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Brotkrueml\Schema\Middleware; | ||
|
||
/* | ||
* This file is part of the "schema" extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
use Brotkrueml\Schema\Core\Model\AbstractType; | ||
use Brotkrueml\Schema\Manager\SchemaManager; | ||
use Brotkrueml\Schema\Model\Type; | ||
use Brotkrueml\Schema\Utility\Utility; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; | ||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; | ||
|
||
final class BreadcrumbList implements MiddlewareInterface | ||
{ | ||
/** @var TypoScriptFrontendController */ | ||
private $controller; | ||
|
||
/** @var SchemaManager */ | ||
private $schemaManager; | ||
|
||
/** @var ExtensionConfiguration */ | ||
private $configuration; | ||
|
||
/** @var object|ContentObjectRenderer */ | ||
private $contentObjectRenderer; | ||
|
||
public function __construct( | ||
TypoScriptFrontendController $controller = null, | ||
SchemaManager $schemaManager = null, | ||
ExtensionConfiguration $configuration = null, | ||
ContentObjectRenderer $contentObjectRenderer = null | ||
) { | ||
$this->controller = $controller ?: $GLOBALS['TSFE']; | ||
$this->schemaManager = $schemaManager ?: GeneralUtility::makeInstance(SchemaManager::class); | ||
$this->configuration = $configuration ?: GeneralUtility::makeInstance(ExtensionConfiguration::class); | ||
$this->contentObjectRenderer = $contentObjectRenderer ?: GeneralUtility::makeInstance(ContentObjectRenderer::class); | ||
} | ||
|
||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
/** @noinspection PhpUnhandledExceptionInspection */ | ||
$shouldEmbedBreadcrumbMarkup = (bool)$this->configuration->get('schema', 'automaticBreadcrumbSchemaGeneration'); | ||
|
||
if ($shouldEmbedBreadcrumbMarkup) { | ||
$rootLine = []; | ||
foreach ($this->controller->rootLine as $page) { | ||
if ($page['is_siteroot']) { | ||
break; | ||
} | ||
|
||
if ($page['nav_hide']) { | ||
continue; | ||
} | ||
|
||
$rootLine[] = $page; | ||
} | ||
|
||
if (!empty($rootLine)) { | ||
\sort($rootLine); | ||
$this->buildBreadCrumbList($rootLine); | ||
} | ||
} | ||
|
||
return $handler->handle($request); | ||
} | ||
|
||
private function buildBreadCrumbList(array $rootLine): void | ||
{ | ||
$breadcrumbList = (new Type\BreadcrumbList()); | ||
foreach ($rootLine as $index => $page) { | ||
$givenItemTypeClass = Utility::getNamespacedClassNameForType($page['tx_schema_webpagetype']); | ||
$webPageTypeClass = $givenItemTypeClass ?: Type\WebPage::class; | ||
|
||
/** @var AbstractType $itemType */ | ||
$itemType = new $webPageTypeClass(); | ||
|
||
$link = $this->contentObjectRenderer->typoLink_URL([ | ||
'parameter' => $page['uid'], | ||
'forceAbsoluteUrl' => true, | ||
]); | ||
|
||
$itemType->setId($link); | ||
|
||
$item = (new Type\ListItem())->setProperties([ | ||
'position' => $index + 1, | ||
'name' => $page['nav_title'] ?: $page['title'], | ||
'item' => $itemType, | ||
]); | ||
|
||
$breadcrumbList->addProperty('itemListElement', $item); | ||
} | ||
|
||
$this->schemaManager->addType($breadcrumbList); | ||
} | ||
} |
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
Binary file modified
BIN
+3.8 KB
(140%)
Documentation/Images/Configuration/ExtensionConfiguration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.