Permalink
Browse files

[FEATURE] Add TypoScript condition that checks if a powermail plugin …

…is on the current page

And also add some documentation how to use it.
  • Loading branch information...
einpraegsam committed Mar 31, 2017
1 parent ea681e1 commit 48513aff17a6e3f3c68624e8610a7c573b43f63b
Showing with 76 additions and 0 deletions.
  1. +54 −0 Classes/Condition/IsPluginOnCurrentPageCondition.php
  2. +22 −0 Documentation/Faq/Index.rst
@@ -0,0 +1,54 @@
<?php
namespace In2code\Powermail\Condition;
use In2code\Powermail\Utility\FrontendUtility;
use In2code\Powermail\Utility\ObjectUtility;
use TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractCondition;
class IsPluginOnCurrentPageCondition extends AbstractCondition
{
/**
* @var string
*/
protected $defaultParameter = '= powermail_pi1';
/**
* Check if pluginname is anywhere on this page
* [In2code\Powermail\Condition\IsPluginOnCurrentPageCondition] for pi1 or
* [In2code\Powermail\Condition\IsPluginOnCurrentPageCondition = powermail_pi1, = powermail_pi2] for any plugins
*
* @param array $conditionParameters e.g. array('= value1', '= value2')
* @return bool
*/
public function matchCondition(array $conditionParameters)
{
if (!empty($conditionParameters)) {
foreach ($conditionParameters as $conditionParameter) {
if ($this->conditionFits($conditionParameter)) {
return true;
}
}
} else {
if ($this->conditionFits($this->defaultParameter)) {
return true;
}
}
return false;
}
/**
* @param $conditionParameter
* @return bool
*/
protected function conditionFits($conditionParameter)
{
$listType = ltrim($conditionParameter, ' =');
$row = (array)ObjectUtility::getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid',
'tt_content',
'deleted=0 and pid=' . FrontendUtility::getCurrentPageIdentifier() . ' and list_type="' . $listType . '"'
);
return !empty($row['uid']);
}
}
@@ -439,6 +439,28 @@ This is easy to handle, just add this line of TypoScript to your **Constants**:
plugin.tx_powermail.settings.misc.addQueryString = 1
.. _powermailconditions:
I want to include CSS or JavaScript only if there is a powermail plugin on this page
------------------------------------------------------------------------------------
The recommended way is to include your JavaScript via require.js or with a simple jQuery.getScript().
An alternative to include JS or CSS could be via a simple condition in TypoScrip **Setup**:
.. code-block:: text
[In2code\Powermail\Condition\IsPluginOnCurrentPageCondition]
// do something but only if Plugin1 of powermail is on the same page
[end]
The condition can be used for every plugin and every extension. Example for a defined tt_contentlist_type:
.. code-block:: text
[In2code\Powermail\Condition\IsPluginOnCurrentPageCondition = powermail_pi1, = powermail_pi2]
// do something but only if Pi1 or Pi2 of powermail is on the same page
[end]
.. _ihaveaproblem:
I have a problem, what can I do?

0 comments on commit 48513af

Please sign in to comment.