Skip to content

Commit

Permalink
[BUGFIX] Code Clean Up, Documentation Corrections as per CR
Browse files Browse the repository at this point in the history
  • Loading branch information
hojalatheef committed Sep 8, 2023
1 parent 99b02db commit 2312a7a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
7 changes: 5 additions & 2 deletions Classes/Helper/ReplacerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function replace(string $contentToReplace): string
$typoScriptFrontendController->config,
'config/tx_replacer.'
);

return $this->doProcessingForReplacerConfig($contentToReplace, $replacerConfig);
}

Expand Down Expand Up @@ -85,6 +86,7 @@ protected function doProcessingForReplacerConfig(string $contentToReplace, array
);
}
}

return $contentToReplace;
}

Expand All @@ -109,6 +111,7 @@ protected function doStandardWrapProcessing(array $typoscriptConfigurations, arr
}
}
}

return $processedConfigurations;
}

Expand All @@ -117,9 +120,9 @@ protected function shouldSkipKey($key): bool
return is_string($key) && substr($key, -1) === '.';
}

protected function processContent($content, $configKey): ?string
protected function processContent(string $content, array $configKey): string
{
if (is_array($configKey) && $this->getTypoScriptFrontendController()->cObj instanceof ContentObjectRenderer) {
if ($configKey && $this->getTypoScriptFrontendController()->cObj instanceof ContentObjectRenderer) {
return $this->getTypoScriptFrontendController()->cObj->stdWrap($content, $configKey);
}

Expand Down
3 changes: 3 additions & 0 deletions Documentation/Configuration/TypoScript/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ Basic example:
Outcome:
--------

Now, when visitors view your website, they will see "banana" instead of "apple" wherever it was originally used.

Use a regex as search pattern
=============================

Using a regular expression (regex) as a search pattern in the Replacer Extension provides a powerful way to perform
complex search and replace operations. Here's an elaboration:

Expand Down Expand Up @@ -67,6 +69,7 @@ Basic regex example:
Outcome:
--------

Now, when visitors view your website, they will see the modified content with the replaced patterns based on the regular
expression you defined. Using regular expressions gives you the ability to perform intricate search and replace
operations, making it particularly useful for tasks that involve complex pattern matching.This feature provides a high
Expand Down
16 changes: 9 additions & 7 deletions Documentation/Example/Index.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
.. include:: /Includes.rst.txt

.. _examples:

Example configurations
======================

In this section you will find some examples how ext:replacer can be used.

Replace pattern only within tags using a regex
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
==============================================

It is even possible to replace content just within a specific tag like a parameter.

**Replace content within a paragraph** ::
**Replace content within a paragraph**

Code:

Expand Down Expand Up @@ -41,11 +42,12 @@ Replaced by:
<p class="example">REPLACE</p>

Replace links for CDN usage
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
===========================

The example TypoScript replaces typo3temp,
typo3conf, uploads and fileadmin occurrences with CDN links.

**CDN example:** ::
**CDN example:**

Code:

Expand Down Expand Up @@ -76,13 +78,13 @@ Replaced by:


Use stdWrap for search and replacement
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
======================================

You can use stdWrap functionality if you need a more dynamic way to search and replace content. The main step is
equal with the basic configuration like above. You can also use a regex as search pattern and a stdWrap as replacement
at the same time!

**Use page title as replacement** ::
**Use page title as replacement**

Code:

Expand All @@ -99,7 +101,7 @@ Code:
}
}
**Use page modification date as replacement** ::
**Use page modification date as replacement**

Code:

Expand Down

0 comments on commit 2312a7a

Please sign in to comment.