Skip to content

Commit

Permalink
[FEATURE] Show remaining maxitems in page module
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabRecht committed Jan 25, 2023
1 parent d83c159 commit b5bc804
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Classes/ViewHelpers/ExtendPartialViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace IchHabRecht\ContentDefender\ViewHelpers;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

class ExtendPartialViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

protected $escapeOutput = false;

public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$packagePath = GeneralUtility::getFileAbsFileName('EXT:content_defender/Resources/Private/');
$partialPaths = $renderingContext->getTemplatePaths()->getPartialRootPaths();
$newPartialPaths = array_filter($partialPaths, function ($path) use ($packagePath) {
return strpos($path, $packagePath) === false;
});
$renderingContext->getTemplatePaths()->setPartialRootPaths($newPartialPaths);
$content = $renderChildrenClosure();
$renderingContext->getTemplatePaths()->setPartialRootPaths($partialPaths);

return $content;
}
}
36 changes: 36 additions & 0 deletions Classes/ViewHelpers/MaxitemsViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace IchHabRecht\ContentDefender\ViewHelpers;

use IchHabRecht\ContentDefender\BackendLayout\BackendLayoutConfiguration;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

class MaxitemsViewHelper extends AbstractViewHelper
{
public function initializeArguments()
{
parent::initializeArguments();

$this->registerArgument('column', 'TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn', 'Current column object', true);
}

public function render()
{
$maxitems = -1;

/** @var GridColumn $column */
$column = $this->arguments['column'];
$pageId = $column->getContext()->getPageId();

$backendLayoutConfiguration = BackendLayoutConfiguration::createFromPageId($pageId);
$columnConfiguration = $backendLayoutConfiguration->getConfigurationByColPos($column->getColumnNumber());

if (!empty($columnConfiguration['maxitems'])) {
$maxitems = $columnConfiguration['maxitems'] - count($column->getItems());
}

return $maxitems;

}
}
3 changes: 3 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ services:
autoconfigure: true
public: false

IchHabRecht\ContentDefender\:
resource: '../Classes/*'

IchHabRecht\ContentDefender\Hooks\WizardItemsHook:
tags:
- name: event.listener
Expand Down
38 changes: 38 additions & 0 deletions Resources/Private/Partials/PageLayout/Grid/ColumnHeader.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:cd="http://typo3.org/ns/IchHabRecht/ContentDefender/ViewHelpers"
data-namespace-typo3-fluid="true">
<cd:extendPartial>
<style>
.t3-cd-badge-container {
position: relative;
margin-top: 20px
}

.t3-cd-badge {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
background-color: #ff0000;
z-index: 100;
}
</style>
<div class="t3-cd-badge-container">
<f:alias map="{maxitems: '{cd:maxitems(column: column)}'}">
<f:switch expression="{maxitems}">
<f:case value="-1"></f:case>
<f:case value="1">
<span class="badge text-bg-warning t3-cd-badge">{maxitems}</span>
</f:case>
<f:case value="0">
<span class="badge text-bg-danger t3-cd-badge">{maxitems}</span>
</f:case>
<f:defaultCase>
<span class="badge text-bg-success t3-cd-badge">{maxitems}</span>
</f:defaultCase>
</f:switch>
</f:alias>
</div>
<f:render partial="PageLayout/Grid/ColumnHeader" arguments="{_all}" />
</cd:extendPartial>
</html>

0 comments on commit b5bc804

Please sign in to comment.