/**
  * Shows a single item
  *
  * @todo integrate caching framework
  * @return void
  */
 public function showAction()
 {
     // Modifies the Render Object
     $this->cleanRenderObj($this->settings);
     // Load the data
     if (empty($this->settings['renderMethod']) || !isset($this->settings['renderMethod'])) {
         $this->settings['renderMethod'] = 'flexForm';
     }
     $cObjAr =& $this->settings['flexform'];
     // Append extra static fields
     if (sizeof($this->settings['cObjectStaticData.']) > 0) {
         foreach ($this->settings['cObjectStaticData.'] as $key => $val) {
             $cObjAr[$key] = $val;
         }
     }
     // Content Object loading
     $this->cObj = $this->configurationManager->getContentObject();
     // temp save of the original data
     // Load the content object data
     $data = $this->cObj->data;
     // Merge the CD Data with the current data object
     if (is_array($cObjAr)) {
         $this->cObj->start(array_merge($data, $cObjAr));
     } else {
         $this->cObj->start($data);
     }
     // Execute rendering by TypoScript
     $itemContent = \KERN23\ContentDesigner\Service\TypoScript::parseTypoScriptObj($this->settings['renderObj'], $this->settings['renderObj.'], $this->cObj);
     // Reset to default data object
     $this->cObj->start($data, 'tt_content');
     // Reset the DATA with the original data
     // Return result
     return $itemContent;
 }
 /**
  * Modifies the Element to disable Dragging for cols
  *
  * @param	tx_cms_layout	$parentObject:  Calling parent object
  * @param	boolean         $drawItem:      Whether to draw the item using the default functionalities
  * @param	string	        $headerContent: Header content
  * @param	string	        $itemContent:   Item content
  * @param	array			$row:           Record row of tt_content
  * @return	void
  */
 private function renderPreview(\TYPO3\CMS\Backend\View\PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row)
 {
     // Preview of content_designer elements
     $expr = '/^' . $this->prefix . '(.*)$/si';
     if (preg_match($expr, $row['CType'], $match)) {
         // Load the TypoScript Config
         $config = array('row' => &$row);
         $typoScript = TypoScript::loadConfig($config, substr($this->prefix, 0, strlen($this->prefix) - 1), $row['pid']);
         $this->typoScript = $typoScript[$row['CType']];
         unset($typoScript, $config);
         // Render the preview with default labels etc.? (default is now off)
         $drawItem = $this->typoScript['settings.']['enableDefaultDrawItem'] == 1 ? TRUE : FALSE;
         // Render the preview
         if (empty($this->settings['renderMethod']) || !isset($this->settings['renderMethod'])) {
             $this->settings['renderMethod'] = 'flexForm';
         }
         if ($this->typoScript['settings.']['renderMethod'] == 'tca') {
             $previewRenderer = GeneralUtility::makeInstance(\KERN23\ContentDesigner\Utility\DrawItem\Tca::class);
         } else {
             $previewRenderer = GeneralUtility::makeInstance(\KERN23\ContentDesigner\Utility\DrawItem\FlexForm::class);
         }
         $previewRenderer->getContentElementPreview($this->typoScript, $row, $headerContent, $itemContent);
         // Link the preview content
         $itemContent = $parentObject->linkEditContent($itemContent, $row);
     }
 }
 /**
  * Injects the content designer explicit allow/deny configuration.
  *
  * @param array $result
  * @return array
  */
 public function addData(array $result)
 {
     // Only if editing the be_groups table
     if ($result['tableName'] != 'be_groups' && is_array($result['processedTca']['columns']['explicit_allowdeny']['config']['items'])) {
         return $result;
     }
     // Preconf
     $table = 'tt_content';
     $explicitADMode = $GLOBALS['TYPO3_CONF_VARS']['BE']['explicitADmode'] == 'explicitAllow' ? 'ALLOW' : 'DENY';
     $adModeLang = array('ALLOW' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.allow'), 'DENY' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.deny'));
     $icons = array('ALLOW' => 'status-status-permission-granted', 'DENY' => 'status-status-permission-denied');
     // Load TS Setup Content Designer Items
     $contentDesignerItems = TypoScript::getFromAnywhere($table . '.', 'tx_contentdesigner_', TRUE);
     // Merge the content designer items to the explicitAllowDeny selector
     if (sizeof($contentDesignerItems) > 0) {
         $items =& $result['processedTca']['columns']['explicit_allowdeny']['config']['items'];
         // Add divider
         $items[] = array('Content Designer:', '--div--', NULL, NULL);
         // Add items
         foreach ($contentDesignerItems as $itemKey => $itemConf) {
             $itemSettings =& $itemConf['settings.'];
             // Put into result
             $items[] = array('[' . $adModeLang[$explicitADMode] . '] ' . $GLOBALS['LANG']->sL($itemSettings['title']), $table . ':CType:' . $itemKey . ':' . $explicitADMode, $icons[$explicitADMode], NULL);
         }
     }
     return $result;
 }
 /**
  * The main hook function called by core function getFlexFormDS()
  *
  * @param $dataStructArray
  * @param $conf
  * @param $row
  * @param $table
  * @param $fieldName
  */
 public function getFlexFormDS_postProcessDS(&$dataStructArray, &$conf, &$row, &$table, &$fieldName)
 {
     // Check for valid table and/or CType
     if ($table != 'tt_content' || !is_array($row) || !array_key_exists('CType', $row) || !strlen($row['CType'])) {
         return false;
     }
     // Init cache
     $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
     $cache = $objectManager->get(CacheManager::class, $objectManager)->getCache('content_designer');
     $cacheIdentifier = $row['CType'];
     // Restore dataStructArray from cache if necessary
     $cachedDataStructArray = $cache->get($cacheIdentifier);
     if (!array_key_exists('pi_flexform', $row) && $cachedDataStructArray) {
         $dataStructArray = $cachedDataStructArray;
         return true;
     }
     // Cache dataStructArray
     $cache->set($cacheIdentifier, $dataStructArray, array(), 0);
     $curObjType = $this->getElementTypeAndTable($row);
     // Get the typoscript configuration object
     $typoScript = TypoScript::loadConfig($conf, substr($this->prefix, 0, strlen($this->prefix) - 1), $row['pid'], $curObjType['table'] . '.');
     // Check whether to extend other CType's and identify the current element
     if (!is_array($typoScript['___extendCType'][$row['CType'] . '.']) && !$curObjType) {
         return FALSE;
     }
     // If a flexFile defined or copied by a plugin, nothing is to do
     $tsObj =& $typoScript[$this->prefix . $curObjType['CType']]['settings.'];
     $tsObjAltern =& $typoScript[$this->prefix . substr($curObjType['CType'], 0, strlen($curObjType['CType']) - 1)]['settings.'];
     # alternative access
     $tsObjCType =& $typoScript['___extendCType'][$row['CType'] . '.'];
     if (empty($tsObj['renderMethod']) || !isset($tsObj['renderMethod'])) {
         $tsObj['renderMethod'] = 'flexForm';
     }
     if (empty($tsObjAltern['renderMethod']) || !isset($tsObjAltern['renderMethod'])) {
         $tsObjAltern['renderMethod'] = 'flexForm';
     }
     if ($tsObj['renderMethod'] != 'flexForm' && $tsObjAltern['renderMethod'] != 'flexForm') {
         unset($typoScript);
         return false;
     }
     // Load the Field Configuration for the current selected Object
     if (!empty($cObject = $tsObj['cObject.']) || !empty($cObject = $tsObjAltern['cObject.']) || !empty($cObject =& $tsObjCType)) {
         unset($typoScript);
     } else {
         return false;
     }
     // Create the dataStructArray
     $this->getDataStructArray($cObject, $dataStructArray);
     // Cache modified dataStructArray
     $cache->set($cacheIdentifier, $dataStructArray, array(), 0);
     return true;
 }
 /**
  * Renders the typoscript preview object with the data from the flexform
  *
  * @param $cObjAr
  * @param $itemContent
  * @param $row
  * @param $objType
  * @param $objArray
  */
 private function parsePreview(&$cObjAr, &$itemContent, &$row, &$objType, &$objArray)
 {
     // initialize TSFE
     $cObj = TypoScript::cObjInit();
     // TypoScript FIELD Startpoint set
     $cObj->start(array_merge($row, $cObjAr));
     // Render preview with TypoScript
     $itemContent = TypoScript::parseTypoScriptObj($objType, $objArray, $cObj);
     // Reset
     $cObj->start($row, 'tt_content');
     // Reset des CURRENT Wert damit die Content ID wieder eingefuegt werden kann
     // Initializing of TypoScript overrides the backend backPath... so we need to set it back for the backend
     $pageRenderer = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
     $backPath = TYPO3_MODE === 'BE' ? $GLOBALS['BACK_PATH'] : '';
     # same way as done in: \TYPO3\CMS\Core\Resource\ResourceCompresso->setInitialBackPath()
     $pageRenderer->setBackPath($backPath);
     // free memory
     unset($cObj, $pageRenderer, $backPath);
 }
 /**
  * Extends the pages configuration the magic to modify the fields are comming in the Hooks (FlexFormDs)
  *
  * @return void
  */
 public static function extendPagesTca()
 {
     // Get current page id
     $table = 'pages';
     $pageUid = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('edit');
     $pageUid = @key($pageUid[$table]);
     // Load TS Setup for content designer pages
     $pagesConfig = TypoScript::loadConfig($config, self::CD_PREFIX, $pageUid, $table . '.', TRUE);
     // do we have something to add?
     if (is_array($pagesConfig) && count($pagesConfig[self::CD_PREFIX . '_flexform']['settings.']['cObject.'])) {
         $cdItem =& $pagesConfig[self::CD_PREFIX . '_flexform']['settings.'];
         ExtensionManagementUtility::addToAllTCAtypes('pages', $cdItem['tca']);
         if ($cdItem['cObjectFlexFile']) {
             // Use a FlexForm File
             $GLOBALS['TCA']['pages']['columns'][self::CD_PREFIX . '_flexform']['config']['ds']['default'] = 'FILE:' . $cdItem['cObjectFlexFile'];
         } else {
             // Use base XML structure (the rest comes with TypoScript)
             $GLOBALS['TCA']['pages']['columns'][self::CD_PREFIX . '_flexform']['config']['ds']['default'] = 'FILE:EXT:content_designer/Configuration/FlexForms/defaultPages.xml';
         }
     }
 }