Skip to content

Commit

Permalink
[FEATURE] Dynamic page based and content based exclusion from parsing
Browse files Browse the repository at this point in the history
solves #166
  • Loading branch information
linawolf authored and featdd committed Apr 10, 2023
1 parent d963a93 commit 8176d92
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Classes/Hook/ContentPostProcHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ protected function parseHtml(TypoScriptFrontendController $typoScriptFrontendCon
$isDisableParser = true;
}

if ((bool) $typoScriptFrontendController->page['tx_dpnglossary_disable_parser'] === true) {
$isDisableParser = true;
}

if (false === $isDisableParser) {
$parsedHTML = $this->parserService->pageParser($typoScriptFrontendController->content);

Expand Down
32 changes: 32 additions & 0 deletions Configuration/TCA/Overrides/pages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
defined('TYPO3_MODE') || die();

call_user_func(function () {

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('pages', [
'tx_dpnglossary_disable_parser' => [
'label' => 'LLL:EXT:dpn_glossary/Resources/Private/Language/locallang.xlf:pages.glossary_settings',
'exclude' => true,
'config' => [
'type' => 'check',
'renderType' => 'checkboxToggle',
'items' => [
[
0 => 'LLL:EXT:dpn_glossary/Resources/Private/Language/locallang.xlf:pages.parse_for_glossary',
1 => '',
'labelChecked' => 'Enabled',
'labelUnchecked' => 'Disabled',
'invertStateDisplay' => true,
],
],
],
],
]);

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'pages',
'tx_dpnglossary_disable_parser',
'',
'after:php_tree_stop'
);
});
28 changes: 28 additions & 0 deletions Configuration/TCA/Overrides/tt_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,33 @@ function () {

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($plugin, 'FILE:EXT:dpn_glossary' . $flexform);
}

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', [
'tx_dpnglossary_disable_parser' => [
'label' => 'LLL:EXT:dpn_glossary/Resources/Private/Language/locallang.xlf:tt_content.glossary_settings',
'exclude' => true,
'config' => [
'type' => 'check',
'renderType' => 'checkboxToggle',
'items' => [
[
0 => 'LLL:EXT:dpn_glossary/Resources/Private/Language/locallang.xlf:tt_content.parse_for_glossary',
1 => '',
'labelChecked' => 'Enabled',
'labelUnchecked' => 'Disabled',
'invertStateDisplay' => true,
],
],
],
],
]);

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tt_content',
'tx_dpnglossary_disable_parser',
'',
'after:linkToTop'
);

}
);
4 changes: 3 additions & 1 deletion Configuration/TypoScript/constants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ plugin.tx_dpnglossary {
# cat=dpn_glossary/settings/a; type=string; label=Classes which are not allowed for the parsing tag
forbiddenParsingTagClasses =
# cat=dpn_glossary/settings/a; type=string; label=Classes which are not allowed on any parent of the parsing tag
forbiddenParentClasses =
forbiddenParentClasses = tx_dpn_glossary_exclude
# cat=dpn_glossary/settings/a; type=options[normal,character,pagination]; label=Listmode: normal, character or paginated by characters
listmode = normal
# cat=dpn_glossary/settings/a; type=options[newest,random]; label=Previewmode: newest or random
Expand All @@ -51,5 +51,7 @@ plugin.tx_dpnglossary {
useTermForSynonymParsingDataWrap = 0
# cat=dpn_glossary/settings/a; type=boolean; label=Add the extension stylesheet (default: enabled)
addStylesheet = 1
# cat=dpn_glossary/settings/a; type=boolean; label=Override fluid styled content layout to enable dynamic exclusion via content properties (default: enabled)
overrideFluidStyledContentLayout = 0
}
}
9 changes: 9 additions & 0 deletions Configuration/TypoScript/setup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ module.tx_dpnglossary.settings < plugin.tx_dpnglossary.settings
page.includeCSS.dpnglossary = EXT:dpn_glossary/Resources/Public/css/styles.css
[global]

["{$plugin.tx_dpnglossary.settings.overrideFluidStyledContentLayout}" == "1"]
lib.contentElement {
layoutRootPaths {
50 = EXT:dpn_glossary/Resources/Private/Extensions/FluidStyledContent/Layouts
}
}
[global]


config.pageTitleProviders {
glossaryTerm {
provider = Featdd\DpnGlossary\PageTitle\TermPageTitleProvider
Expand Down
61 changes: 61 additions & 0 deletions Documentation/Configuration/ExampleTypoScriptSetup/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,64 @@ Add the following code to you setup:
}
Official documentaton: `https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/Seo/XmlSitemap.html`

.. _example-exclude-pages:

Exclude pages from being parsed
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Pages can be statically excluded from parsing via TypoScript::

plugin.tx_dpnglossary {
settings.parsingExcludePidList = 42, 185, 365
}

Pages can also dynamically excluded from parsing by page properties
:guilabel:`Page Properties > Behaviour > Settings for dreipunktnull Glossary`:

.. figure:: /Images/ExcludePageFromParsing.png
:alt: Exclude page from parsing

Exclude page from parsing

By making field :sql:`tx_dpnglossary_parsing_settings` of table
:sql:`pages` available for your editors, it is also possible to let (power)
editors decide, which pages should be parsed.

.. _example-exclude-content:

Exclude content from being parsed
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The following TypoScript constant defines HTML classes whose content will be
excluded from parsing::

plugin.tx_dpnglossary {
settings.forbiddenParsingTagClasses = tx_dpn_glossary_exclude, my_search_results
}

Content wrapped with one of these classes will be excluded from parsing.

Content can also dynamically excluded from parsing by content properties
:guilabel:`Content Properties > Appearance > Settings for DPN Glossary`.

This only works if the default Fluid layout has been overriden to wrap the
content with the HTML class :html:`tx_dpn_glossary_exclude` and this class is
still found in the :typoscript:`settings.forbiddenParsingTagClasses`.

You can set the following TypoScript constant to let this extension override
the Fluid Styled Content default layout::

plugin.tx_dpnglossary {
settings.overrideFluidStyledContentLayout = 1
}

If you need to override the layout yourself make sure to add the following to the
surrounding tags class:

.. code-block:: html

<div class="... {f:if(condition: data.tx_dpnglossary_disable_parser, then: ' tx_dpn_glossary_exclude')}">

Just like with the pages this property can be used to enable editors to exclude
content elements from parsing.
27 changes: 25 additions & 2 deletions Documentation/Configuration/ExtensionSettings/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ plugin.tx_dpnglossary.settings:
string

Description
Comma list of pages which should not be parsed
Comma list of pages which should not be parsed. Can be used to :ref:`exclude
pages from being pages <example-exclude-content>`


.. container:: table-row
Expand Down Expand Up @@ -148,8 +149,13 @@ plugin.tx_dpnglossary.settings:
Data Type
string

Default
tx_dpn_glossary_exclude

Description
Comma list of classes which are not allowed on any parent of the parsing tag
Comma list of classes which are not allowed on any parent of the parsing tag.
can be used to :ref:` exclude content from being parsed
<example-exclude-content>`

.. container:: table-row

Expand Down Expand Up @@ -246,4 +252,21 @@ plugin.tx_dpnglossary.settings:
Description
Comma list of special characters allowed to wrap the term


.. container:: table-row

Constant
settings.overrideFluidStyledContentLayout

Data Type
boolean

Description
If set the default layout of FluidStyledContent is overriden by this
extension. Can be used to :ref:`exclude content from being parsed
<example-exclude-content>`

Default
0

.. ###### END~OF~TABLE ######
Binary file added Documentation/Images/ExcludePageFromParsing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Documentation/Includes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
.. role:: js(code)
.. role:: php(code)
.. role:: typoscript(code)
.. role:: sql(code)

.. role:: ts(typoscript)
:class: typoscript
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:if condition="{data.frame_class} != none">
<f:then>

<div id="c{data.uid}" class="frame frame-{data.frame_class} frame-type-{data.CType} frame-layout-{data.layout}{f:if(condition: data.space_before_class, then: ' frame-space-before-{data.space_before_class}')}{f:if(condition: data.space_after_class, then: ' frame-space-after-{data.space_after_class}')} {f:if(condition: data.tx_dpnglossary_disable_parser, then: ' tx_dpn_glossary_exclude')}">
<f:if condition="{data._LOCALIZED_UID}">
<a id="c{data._LOCALIZED_UID}"></a>
</f:if>
<f:render section="Before" optional="true">
<f:render partial="DropIn/Before/All" arguments="{_all}" />
</f:render>
<f:render section="Header" optional="true">
<f:render partial="Header/All" arguments="{_all}" />
</f:render>
<f:render section="Main" optional="true" />
<f:render section="Footer" optional="true">
<f:render partial="Footer/All" arguments="{_all}" />
</f:render>
<f:render section="After" optional="true">
<f:render partial="DropIn/After/All" arguments="{_all}" />
</f:render>
</div>

</f:then>
<f:else>

<a id="c{data.uid}"></a>
<f:if condition="{data._LOCALIZED_UID}">
<a id="c{data._LOCALIZED_UID}"></a>
</f:if>
<f:if condition="{data.space_before_class}">
<div class="frame-space-before-{data.space_before_class}"></div>
</f:if>
<f:render section="Before" optional="true">
<f:render partial="DropIn/Before/All" arguments="{_all}" />
</f:render>
<f:render section="Header" optional="true">
<f:render partial="Header/All" arguments="{_all}" />
</f:render>
<f:render section="Main" optional="true" />
<f:render section="Footer" optional="true">
<f:render partial="Footer/All" arguments="{_all}" />
</f:render>
<f:render section="After" optional="true">
<f:render partial="DropIn/After/All" arguments="{_all}" />
</f:render>
<f:if condition="{data.space_after_class}">
<div class="frame-space-after-{data.space_after_class}"></div>
</f:if>

</f:else>
</f:if>
</html>
16 changes: 16 additions & 0 deletions Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@
<trans-unit id="extensionsettings.term_slug_evaluation_type.unique_in_instance">
<target>Einzigartig in der gesamten Instanz</target>
</trans-unit>


<trans-unit id="pages.glossary_settings">
<target>Einstellungen für das dreipunktnull Glossar</target>
</trans-unit>
<trans-unit id="pages.parse_for_glossary">
<target>Seite parsen </target>
</trans-unit>


<trans-unit id="tt_content.glossary_settings">
<target>Einstellungen für das dreipunktnull Glossar</target>
</trans-unit>
<trans-unit id="tt_content.parse_for_glossary">
<target>Inhalt parsen</target>
</trans-unit>
</body>
</file>
</xliff>
16 changes: 16 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@
<trans-unit id="extensionsettings.term_slug_evaluation_type.unique_in_instance">
<source>unique in the whole instance</source>
</trans-unit>


<trans-unit id="pages.glossary_settings">
<source>Settings for dreipunktnull Glossary</source>
</trans-unit>
<trans-unit id="pages.parse_for_glossary">
<source>Parse page for glossary terms</source>
</trans-unit>


<trans-unit id="tt_content.glossary_settings">
<source>Settings for dreipunktnull Glossary</source>
</trans-unit>
<trans-unit id="tt_content.parse_for_glossary">
<source>Parse content element for glossary terms</source>
</trans-unit>
</body>
</file>
</xliff>
8 changes: 8 additions & 0 deletions ext_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,11 @@ CREATE TABLE tx_dpnglossary_domain_model_description (
KEY language(l10n_parent, sys_language_uid)

);

CREATE TABLE pages (
tx_dpnglossary_disable_parser tinyint(4) DEFAULT '0' NOT NULL
);

CREATE TABLE tt_content (
tx_dpnglossary_disable_parser tinyint(4) DEFAULT '0' NOT NULL
);

0 comments on commit 8176d92

Please sign in to comment.