-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
1 parent
ea681e1
commit 48513af
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters