Skip to content

Commit

Permalink
Added config options beTemplate and isNewsletter, closes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Jan 5, 2015
1 parent cea2b33 commit 3ea3c30
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/MadeYourDay/Contao/CustomElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ protected function createDcaMultiEdit($dc)
* @param string $type Element type beginning with "rsce_"
* @return array|null Configuration array
*/
protected static function getConfigByType($type)
public static function getConfigByType($type)
{
$configPath = null;

Expand Down
59 changes: 53 additions & 6 deletions src/MadeYourDay/Contao/Element/CustomElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace MadeYourDay\Contao\Element;

use MadeYourDay\Contao\Template\CustomTemplate;
use MadeYourDay\Contao\CustomElements;

/**
* Custom content element and frontend module
Expand All @@ -31,12 +32,9 @@ public function generate()
{
$this->strTemplate = $this->type;

if (TL_MODE === 'BE' && (
in_array($this->type, $GLOBALS['TL_WRAPPERS']['start'])
|| in_array($this->type, $GLOBALS['TL_WRAPPERS']['stop'])
|| in_array($this->type, $GLOBALS['TL_WRAPPERS']['separator'])
)) {
return '';
// Return output for the backend if in BE mode
if (($output = $this->rsceGetBackendOutput()) !== null) {
return $output;
}

try {
Expand All @@ -61,6 +59,55 @@ public function generate()
}
}

/**
* Generate backend output if TL_MODE is set to BE
*
* @return string|null Backend output or null
*/
public function rsceGetBackendOutput()
{
if (TL_MODE !== 'BE') {
return null;
}

$config = CustomElements::getConfigByType($this->type) ?: array();

// Handle newsletter output the same way as the frontend
if (!empty($config['isNewsletter'])) {

if (\Input::get('do') === 'newsletter') {
return null;
}

foreach(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $entry) {
$method = $entry['class'] . '::' . $entry['function'];
if (
$entry['file'] === TL_ROOT . '/system/modules/newsletter/classes/Newsletter.php'
|| $method === 'Contao\\Newsletter::send'
|| $method === 'tl_newsletter::listNewsletters'
) {
return null;
}
}

}

if (!empty($config['beTemplate'])) {
$this->strTemplate = $config['beTemplate'];
return null;
}

if (
in_array($this->type, $GLOBALS['TL_WRAPPERS']['start'])
|| in_array($this->type, $GLOBALS['TL_WRAPPERS']['stop'])
|| in_array($this->type, $GLOBALS['TL_WRAPPERS']['separator'])
) {
return '';
}

return null;
}

/**
* Parse the json data and pass it to the template
*
Expand Down

0 comments on commit 3ea3c30

Please sign in to comment.