Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Show remaining maxitems in page module #121

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
53 changes: 53 additions & 0 deletions Classes/ViewHelpers/MaxitemsViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace IchHabRecht\ContentDefender\ViewHelpers;

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

class MaxitemsViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

public function initializeArguments()
{
parent::initializeArguments();

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

public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$maxitems = -1;

/** @var GridColumn $column */
$column = $arguments['column'];
$pageId = $column->getContext()->getPageId();
$colPos = $column->getColumnNumber();
$language = $column->getContext()->getSiteLanguage()->getLanguageId();

$identifier = implode('_', [$pageId, $language, $colPos]);

$viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
if ($viewHelperVariableContainer->exists(self::class, $identifier)) {
return $viewHelperVariableContainer->get(self::class, $identifier);
}

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

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

$viewHelperVariableContainer->add(self::class, $identifier, $maxitems);

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
9 changes: 9 additions & 0 deletions Configuration/TCA/Overrides/pages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

defined('TYPO3') || die('Access denied.');

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerPageTSConfigFile(
'content_defender',
'Configuration/TSconfig/Page/maxitems.tsconfig',
'EXT:content_defender :: Enable maxitems view in page module'
);
9 changes: 9 additions & 0 deletions Configuration/TCA/Overrides/sys_template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

defined('TYPO3') || die('Access denied.');

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
'content_defender',
'Configuration/TypoScript',
'EXT:content_defender :: Enable maxitems view in page module'
);
2 changes: 2 additions & 0 deletions Configuration/TSconfig/Page/maxitems.tsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

templates.typo3/cms-backend.100 = ichhabrecht/content-defender:Resources/Private/
10 changes: 10 additions & 0 deletions Configuration/TypoScript/constants.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.tx_contentdefender {
view {
# cat=plugin.tx_contentdefender/file; type=string; label=Path to template root
templateRootPath = EXT:content_defender/Resources/Private/Templates/Backend/
# cat=plugin.tx_contentdefender/file; type=string; label=Path to template partials
partialRootPath = EXT:content_defender/Resources/Private/Partials/Backend/
# cat=plugin.tx_contentdefender/file; type=string; label=Path to template layouts
layoutRootPath = EXT:content_defender/Resources/Private/Layouts/Backend/
}
}
2 changes: 2 additions & 0 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

module.tx_backend.view.partialRootPaths.100 = {$module.tx_contentdefender.view.partialRootPath}
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ columns {
}
```

**Enable maxitems count in page module (*!experimental!*)**

- To show the count of remaiing content elements that can be created in a column, you can enable an integration of
content_defender in the page module
- Please understand that this feature is very experimental and does not have high priority for bug fixing

*TYPO3 10 and 11*

- Add the provided TypoScript template

*TYPO3 12 and above*

- Add the provided Page TSconfig in your page.tsconfig_includes field

## Community

- Thanks to [b13](https://b13.com) that sponsored the maintenance of this extension with a sponsorship
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<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">

<f:be.pageRenderer includeCssFiles="{0: 'EXT:content_defender/Resources/Public/Css/backend.css'}" />

<cd:extendPartial>
<f:alias map="{maxitems: '{cd:maxitems(column: column)}'}">
<div class="t3-cd-badge-container" data-maxitems="{maxitems}">
<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:render partial="PageLayout/Grid/ColumnHeader" arguments="{_all}" />
</div>
</f:alias>
</cd:extendPartial>

</html>
11 changes: 11 additions & 0 deletions Resources/Private/Partials/Backend/PageLayout/Record.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<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>
<f:alias map="{maxitems: '{cd:maxitems(column: column)}'}">
<div class="t3-cd-badge-container" data-maxitems="{maxitems}">
<f:render partial="PageLayout/Record" arguments="{_all}" />
</div>
</f:alias>
</cd:extendPartial>
</html>
34 changes: 34 additions & 0 deletions Resources/Public/Css/backend.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@charset "UTF-8";

.t3-cd-badge-container {
position: relative;
}

.t3-cd-badge-container[data-maxitems="0"] .t3-page-ce .t3js-page-new-ce,
.t3-cd-badge-container[data-maxitems="0"] .t3-page-ce .t3-page-ce-dropzone {
display: none;
}

.t3-cd-badge {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, 0);
background-color: #ff0000;
z-index: 100;
}

.t3-cd-badge.text-bg-success {
background-color: #107c10;
color: #ffffff;
}

.t3-cd-badge.text-bg-warning {
background-color: #e8a33d;
color: #ffffff;
}

.t3-cd-badge.text-bg-danger {
background-color: #ff0000;
color: #ffffff;
}