From 6c7ac6443b176dd313bb936c29096252a26bf513 Mon Sep 17 00:00:00 2001 From: doishub Date: Fri, 24 Jan 2020 09:05:26 +0100 Subject: [PATCH] Adding support for config files from vendor bundles --- src/Resources/contao/drivers/DC_Config.php | 74 ++++++++++++++-------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/src/Resources/contao/drivers/DC_Config.php b/src/Resources/contao/drivers/DC_Config.php index 3d32f3e..95d1c41 100644 --- a/src/Resources/contao/drivers/DC_Config.php +++ b/src/Resources/contao/drivers/DC_Config.php @@ -8,6 +8,7 @@ namespace Contao; +use Symfony\Component\Finder\SplFileInfo; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface; /** @@ -98,41 +99,45 @@ public function __construct($strTable) } } - /** - * Automatically switch to edit mode - * - * @return string - */ + /** + * Automatically switch to edit mode + * + * @return string + * @throws \Exception + */ public function create() { return $this->edit(); } - /** - * Automatically switch to edit mode - * - * @return string - */ + /** + * Automatically switch to edit mode + * + * @return string + * @throws \Exception + */ public function cut() { return $this->edit(); } - /** - * Automatically switch to edit mode - * - * @return string - */ + /** + * Automatically switch to edit mode + * + * @return string + * @throws \Exception + */ public function copy() { return $this->edit(); } - /** - * Automatically switch to edit mode - * - * @return string - */ + /** + * Automatically switch to edit mode + * + * @return string + * @throws \Exception + */ public function move() { return $this->edit(); @@ -145,7 +150,23 @@ public function move() */ private function generateDcaFieldsFromConfig() { - $strFilePath = TL_ROOT . '/templates/' . $GLOBALS['TL_DCA'][$this->strTable]['config']['configFile'] . '.php'; + // search config file + $strFile = $GLOBALS['TL_DCA'][$this->strTable]['config']['configFile'] . '.php'; + $strFilePath = TL_ROOT . '/templates/' . $strFile; + + if(!file_exists($strFilePath)) + { + try + { + // Search for the template if it is not in the lookup array (last match wins) + foreach (\System::getContainer()->get('contao.resource_finder')->findIn('templates')->name($strFile) as $file) + { + /** @var SplFileInfo $file */ + $strFilePath = $file->getPathname(); + } + } + catch (\InvalidArgumentException $e){} + } if(!file_exists($strFilePath)) { @@ -170,11 +191,12 @@ private function generateDcaFieldsFromConfig() return true; } - /** - * Auto-generate a form to edit the local configuration file - * - * @return string - */ + /** + * Auto-generate a form to edit the local configuration file + * + * @return string + * @throws \Exception + */ public function edit() { $return = '';