Skip to content

Commit

Permalink
Merge pull request #17 from Tobi77/master
Browse files Browse the repository at this point in the history
Release 2.0.0
  • Loading branch information
Digi92 authored Mar 19, 2021
2 parents 19e8754 + 2c496eb commit 0bc365b
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 158 deletions.
7 changes: 5 additions & 2 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Core\Core\Environment;

/**
* Class BackendController
Expand Down Expand Up @@ -59,7 +60,7 @@ public function indexAction()
count($providers) === 0
) {
// Check if source extension exists
if (!is_dir(PATH_typo3conf . 'ext/dw_content_elements_source')) {
if (!is_dir(Environment::getPublicPath() . '/typo3conf/ext/dw_content_elements_source')) {
$this->forward('createSourceExt');
} else {
$this->forward('loadSourceExt');
Expand All @@ -82,7 +83,9 @@ public function createSourceExtAction()
$fileService = $this->objectManager->get(
FileService::class
);
$fileService->setSourceExtensionDirectory(PATH_typo3conf . 'ext/dw_content_elements_source/');
$fileService->setSourceExtensionDirectory(
Environment::getPublicPath() . '/typo3conf/ext/dw_content_elements_source/'
);
$success = $fileService->createSourceExt();

if ($success) {
Expand Down
4 changes: 3 additions & 1 deletion Classes/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Extbase\Annotation as Extbase;

/**
* Class BaseController
Expand Down Expand Up @@ -62,7 +63,7 @@ class BaseController extends ActionController
* IrreService
*
* @var \Denkwerk\DwContentElements\Service\IrreService
* @inject
* @Extbase\Inject
*/
protected $irreService;

Expand All @@ -76,6 +77,7 @@ class BaseController extends ActionController
protected function initializeView(ViewInterface $view)
{
$this->classReflection = new \ReflectionClass($this);
// @extensionScannerIgnoreLine
$this->contentObj = $this->configurationManager->getContentObject();
$this->data = $this->contentObj->data;
$view->assign('data', $this->contentObj->data);
Expand Down
21 changes: 6 additions & 15 deletions Classes/Hooks/PageLayoutViewDrawItemHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,16 @@ public function renderFieldPreview($fieldName, $row, $itemLabels = '', $fieldTab

switch ($fieldConfig['type']) {
case "input":
//If field has a link wizard
if (isset($fieldConfig['wizards']['link']) &&
//If field has the renderType "inputLink" generate link
if (isset($fieldConfig['renderType']) &&
$fieldConfig['renderType'] === 'inputLink' &&
empty($fieldValue) === false
) {
/*** @var UrlService $urlService */
$urlService = GeneralUtility::makeInstance(
UrlService::class
);
$fieldValue = $urlService->getUrl(
$row['pid'],
$fieldValue
);
$fieldValue = $urlService->getUrl($fieldValue);
}

// If field has an eval type, format the value by respect eval type
Expand Down Expand Up @@ -259,14 +257,7 @@ public function renderFieldPreview($fieldName, $row, $itemLabels = '', $fieldTab
FormDataCompiler::class,
$formDataGroup
);
// ToDo: Remove hotfix if the core bug is fixed or change the code! Change initTSFE back to private!
// Bug ticket: https://forge.typo3.org/issues/79354
// Hotfix BEGIN
/*** @var UrlService $urlService */
$urlService = GeneralUtility::makeInstance(
UrlService::class
);
$urlService->initTSFE($row['pid']);

// TODO: Fix that user with only read rights can't run this command
try {
$formData = $formDataCompiler->compile($formDataCompilerInput);
Expand Down Expand Up @@ -346,7 +337,7 @@ public function renderFieldPreview($fieldName, $row, $itemLabels = '', $fieldTab
null,
0,
'',
'150cxNULL',
'150c',
true
);
$filedContent .= '<br />';
Expand Down
6 changes: 5 additions & 1 deletion Classes/Service/IniProviderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
* This copyright notice MUST APPEAR in all copies of the script!
* **************************************************************/

use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Class IniProviderService
Expand Down Expand Up @@ -83,7 +85,9 @@ public function loadProvider()
protected function mergeConfigurations(array $config)
{
// Extension manager configuration: used as default configuration
$extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dw_content_elements']);
$extensionConfiguration = GeneralUtility::makeInstance(
ExtensionConfiguration::class
)->get('dw_content_elements');

if (is_array($config) &&
is_array($extensionConfiguration)
Expand Down
5 changes: 3 additions & 2 deletions Classes/Service/IniService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

use Denkwerk\DwContentElements\Utility\Paths;
use Denkwerk\DwContentElements\Utility\TypoScriptParser;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand Down Expand Up @@ -55,15 +56,15 @@ public function __construct()
/**
* Returns the configuration from the file set by configuration file
*
* @param string $configFile Relative Path to TYPO3-DocumentRoot (PATH_site)
* @param string $configFile Relative Path to TYPO3-DocumentRoot (\TYPO3\CMS\Core\Core\Environment::getPublicPath())
* @return array|bool
*/
public function loadConfig($configFile)
{
$result = false;
$configFileAbsPath = Paths::concat(
array(
realpath(PATH_site),
realpath(Environment::getPublicPath()),
realpath($configFile),
)
);
Expand Down
85 changes: 57 additions & 28 deletions Classes/Service/IrreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
***************************************************************/

use Denkwerk\DwContentElements\Utility\Logger;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Class IrreService
Expand All @@ -49,38 +55,56 @@ public static function getRelations($contentObj, $tableName, $repositoryName = '
$result = array();

// Check if field "foreign_uid" exists on table
$fieldsInDatabase = $GLOBALS['TYPO3_DB']->admin_get_fields($tableName);
//$fieldsInDatabase = $GLOBALS['TYPO3_DB']->admin_get_fields($tableName);
$fieldsInDatabase = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable($tableName)
->getSchemaManager()
->listTableColumns($tableName);

if (empty($fieldsInDatabase) === false &&
array_key_exists("foreign_uid", $fieldsInDatabase)
) {
// If "$repositoryName" is not set. Get the table data by single select
if ($contentObj->data[$tableName] > 0 &&
empty($repositoryName)
) {
$rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'*',
$tableName,
'foreign_uid = ' . $contentObj->data['uid'] .
(TYPO3_MODE == 'BE' ?
BackendUtility::BEenableFields($tableName)
. ' AND ' . $tableName . '.deleted=0' :
$contentObj->enableFields($tableName)
),
'',
'sorting'
);
$foreignUid = $contentObj->data['uid'];
if (isset($contentObj->data['_LOCALIZED_UID'])) {
$foreignUid = $contentObj->data['_LOCALIZED_UID'];
}

/** @var \TYPO3\CMS\Core\Database\Query\QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($tableName);

$queryBuilder->getRestrictions()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(HiddenRestriction::class))
->add(GeneralUtility::makeInstance(StartTimeRestriction::class))
->add(GeneralUtility::makeInstance(EndTimeRestriction::class));

$rows = $queryBuilder
->select('*')
->from($tableName)
->where('foreign_uid = ' . $foreignUid)
->orderBy('sorting')
->execute();

foreach ($rows as $row) {
// Get "tt_content" content elements of the relations if it exist a row "content_elements"
array_push($result, self::getContentElements($contentObj, $row, $tableName));
}
}


// Get the IRRE data by the repository magic function "findByForeignUid"
if ($contentObj->data[$tableName] > 0 &&
empty($repositoryName) === false
) {
$foreignUid = $contentObj->data['uid'];
if (isset($contentObj->data['_LOCALIZED_UID'])) {
$foreignUid = $contentObj->data['_LOCALIZED_UID'];
}

/*** @var $extbaseObjectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
$extbaseObjectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Extbase\\Object\\ObjectManager'
Expand All @@ -89,7 +113,7 @@ public static function getRelations($contentObj, $tableName, $repositoryName = '
$repository = $extbaseObjectManager->get($repositoryName);

// Get the table data by the given repository
$rows = $repository->findByForeignUid($contentObj->data['uid']);
$rows = $repository->findByForeignUid($foreignUid);

if (empty($rows) === false) {
$result = $rows;
Expand Down Expand Up @@ -123,18 +147,23 @@ public static function getContentElements($contentObj, $data, $parentTable)
if (is_array($data)
) {
if ($data['content_elements'] != null && empty($data['content_elements']) === false) {
$elementRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'uid',
'tt_content',
'foreign_uid = ' . $data['uid'] .
(TYPO3_MODE == 'BE' ?
BackendUtility::BEenableFields('tt_content')
. ' AND tt_content.deleted=0' :
$contentObj->enableFields('tt_content')
) . 'AND parent_table = "' . $parentTable . '"',
'',
'sorting'
);
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tt_content');

$queryBuilder->getRestrictions()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(HiddenRestriction::class))
->add(GeneralUtility::makeInstance(StartTimeRestriction::class))
->add(GeneralUtility::makeInstance(EndTimeRestriction::class));

$elementRows = $queryBuilder
->select('uid')
->from('tt_content')
->where('foreign_uid = ' . $data['uid'])
->orderBy('sorting')
->execute();

$contentElements = array();
foreach ($elementRows as $elementRow) {
array_push($contentElements, $elementRow['uid']);
Expand Down
87 changes: 3 additions & 84 deletions Classes/Service/UrlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

namespace Denkwerk\DwContentElements\Service;

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use \TYPO3\CMS\Core\Utility\VersionNumberUtility;
use \TYPO3\CMS\Core\Utility\GeneralUtility as GeneralUtility;
use \TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Utility\EidUtility;

/***************************************************************
* Copyright notice
Expand Down Expand Up @@ -45,25 +39,14 @@ class UrlService
/**
* Create link for frontend pages
*
* @param int $currentPageUid Pid of the current page
* @param string $linkParameter The string from the link wizard
* @return string
*/
public function getUrl($currentPageUid, $linkParameter)
public function getUrl($linkParameter)
{
$result = $linkParameter;

// If the TSFE can't load, we can NOT create a typolink
$currentPage = BackendUtility::getRecord(
'pages',
$currentPageUid
);
if ($currentPageUid > 0 &&
$currentPage['doktype'] <= 200 &&
$currentPage['hidden'] != 1 &&
empty($linkParameter) === false &&
$this->initTSFE($currentPageUid)
) {
if (empty($linkParameter) === false) {
/** @var ContentObjectRenderer $cObj */
$cObj = GeneralUtility::makeInstance(
ContentObjectRenderer::class
Expand All @@ -73,68 +56,4 @@ public function getUrl($currentPageUid, $linkParameter)

return $result;
}

/**
* Load the $GLOBALS['TSFE'] for the given page. Is need to created typolinks
*
* @param int $id Id of the current page
* @param int $typeNum
* @return bool
*/
public function initTSFE($id = 1, $typeNum = 0)
{
$hasTsTemplate = false;
$rootLine = BackendUtility::BEgetRootLine($id);

// Check root line pages if there is an sysTemplate with configuration. We need this for initialize the TSFE.
if (empty($rootLine) === false &&
is_array($rootLine)
) {
foreach ($rootLine as $page) {
$row = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'uid',
'sys_template',
'pid=' . (int)$page['uid'] . ' AND deleted=0 AND hidden=0',
'sorting',
1
);
if (isset($row[0])) {
$hasTsTemplate = true;
break;
}
}
}

if ($hasTsTemplate) {
EidUtility::initTCA();
if (!is_object($GLOBALS['TT'])) {
$GLOBALS['TT'] = new TimeTracker;
$GLOBALS['TT']->start();
}

$GLOBALS['TSFE'] = GeneralUtility::makeInstance(
TypoScriptFrontendController::class,
$GLOBALS['TYPO3_CONF_VARS'],
$id,
$typeNum
);
$GLOBALS['TSFE']->connectToDB();
$GLOBALS['TSFE']->initFEuser();

if (TYPO3_MODE === 'BE') {
$GLOBALS['TSFE']->initializeBackendUser();
}

$GLOBALS['TSFE']->determineId();
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->getConfigArray();

if (ExtensionManagementUtility::isLoaded('realurl')) {
$host = BackendUtility::firstDomainRecord($rootLine);
$_SERVER['HTTP_HOST'] = $host;
}
}

return $hasTsTemplate;
}
}
Loading

0 comments on commit 0bc365b

Please sign in to comment.