Skip to content

Commit

Permalink
[FEATURE] Add TypoScript condition that checks if a powermail plugin …
Browse files Browse the repository at this point in the history
…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 48513af
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Classes/Condition/IsPluginOnCurrentPageCondition.php
Original file line number Diff line number Diff line change
@@ -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']);
}
}
22 changes: 22 additions & 0 deletions Documentation/Faq/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 48513af

Please sign in to comment.