* @owner University of Latvia * @version 1.0.0 * @since 02.09.2020 * * @package Lu\LuSearch\Hooks\PageLayoutView */ class NewContentElementPreviewRenderer implements PageLayoutViewDrawItemHookInterface { /** * Extension key * * @var string */ const KEY = 'lu_search'; /** * Path to the locallang file * * @var string */ const LLPATH = 'LLL:EXT:'.self::KEY.'/Resources/Private/Language/locallang.xlf:'; /** * Flexform information * * @var array */ public $flexformData = []; /** * Pre-processes the preview rendering of a content element of type "My new content element" * * @param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling parent object * @param bool $drawItem Whether to draw the item using the default functionality * @param string $headerContent Header content * @param string $itemContent Item content * @param array $row Record row of tt_content * * @return void */ public function preProcess(PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row) { // Notice: Always check if your extions, or you will overwrite other plugin data! if ($row['list_type'] == 'lusearch_pi1') { $itemContent = '
'.$this->getLanguageService()->sL(self::LLPATH.'extension.title').'
'.$itemContent.''; $drawItem = false; } } /** * Get field value from flexform configuration, * including checks if flexform configuration is available * * @param string $key name of the key * @param string $sheet name of the sheet * * @return string|NULL if nothing found, value if found */ public function getFieldFromFlexform($key, $sheet = 'sDEF') { $flexform = $this->flexformData; if (isset($flexform['data'])) { $flexform = $flexform['data']; if (isset($flexform[$sheet]['lDEF'][$key]['vDEF']) ) { return $flexform[$sheet]['lDEF'][$key]['vDEF']; } } return null; } /** * Return language service instance * * @return \TYPO3\CMS\Core\Localization\LanguageService */ public function getLanguageService() { return $GLOBALS['LANG']; } /** * Recursive method for finding site objects * * @param int $current_id * * @return array|\TYPO3\CMS\Core\Site\Entity\Site */ private function getParentSite($current_id = 0) { // Get current ID if parent ID = 0 if (!$current_id) { $current_id = (int)GeneralUtility::_GP('id'); } $parent_id = $this->getParentId($current_id); // Check if parent exists if ($parent_id < 1) { return []; } // Try to find site info try { $sites = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($parent_id); } catch (SiteNotFoundException $e) { $sites = []; } // Go up, if no site founf if (empty($sites)) { return $this->getParentSite($parent_id); } // Return site data return $sites; } /** * Fetch current page parent id * * @param $current_id * * @return int */ private function getParentId($current_id) { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages')->createQueryBuilder(); return (int)$queryBuilder->select('pid')->from('pages')->where( $queryBuilder->expr()->eq('uid', $current_id) )->execute()->fetchColumn(0); } }