From 3ea3c30bb1d8f2e21e02cf7c56a6e762df8c71f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Auswo=CC=88ger?= Date: Mon, 5 Jan 2015 16:04:47 +0100 Subject: [PATCH] Added config options beTemplate and isNewsletter, closes #28 --- src/MadeYourDay/Contao/CustomElements.php | 2 +- .../Contao/Element/CustomElement.php | 59 +++++++++++++++++-- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/MadeYourDay/Contao/CustomElements.php b/src/MadeYourDay/Contao/CustomElements.php index 19bb547..d8755c3 100644 --- a/src/MadeYourDay/Contao/CustomElements.php +++ b/src/MadeYourDay/Contao/CustomElements.php @@ -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; diff --git a/src/MadeYourDay/Contao/Element/CustomElement.php b/src/MadeYourDay/Contao/Element/CustomElement.php index a135dfb..180be4a 100644 --- a/src/MadeYourDay/Contao/Element/CustomElement.php +++ b/src/MadeYourDay/Contao/Element/CustomElement.php @@ -9,6 +9,7 @@ namespace MadeYourDay\Contao\Element; use MadeYourDay\Contao\Template\CustomTemplate; +use MadeYourDay\Contao\CustomElements; /** * Custom content element and frontend module @@ -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 { @@ -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 *