diff --git a/Classes/FrontendEditPanel.php b/Classes/FrontendEditPanel.php index 1130e61..40cf7df 100644 --- a/Classes/FrontendEditPanel.php +++ b/Classes/FrontendEditPanel.php @@ -1,7 +1,7 @@ cObj = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class); + protected $frontendController; + + /** + * Property for accessing DatabaseConnection centrally + * + * @var DatabaseConnection + */ + protected $databaseConnection; + + /** + * @var FrontendBackendUserAuthentication + */ + protected $backendUser; + + /** + * Constructor for the edit panel + * + * @param DatabaseConnection $databaseConnection + * @param TypoScriptFrontendController $frontendController + * @param FrontendBackendUserAuthentication $backendUser + */ + public function __construct(DatabaseConnection $databaseConnection = NULL, TypoScriptFrontendController $frontendController = NULL, FrontendBackendUserAuthentication $backendUser = NULL) { + $this->databaseConnection = $databaseConnection ?: $GLOBALS['TYPO3_DB']; + $this->frontendController = $frontendController ?: $GLOBALS['TSFE']; + $this->backendUser = $backendUser ?: $GLOBALS['BE_USER']; + $this->cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer'); $this->cObj->start(array()); } @@ -46,68 +78,63 @@ class FrontendEditPanel { * @param string $currentRecord The "table:uid" of the record being shown. If empty string then $this->currentRecord is used. For new records (set by $conf['newRecordFromTable']) it's auto-generated to "[tablename]:NEW * @param array $dataArr Alternative data array to use. Default is $this->data * @param string $table - * @param string $allow + * @param array $allow * @param int $newUID * @param array $hiddenFields * @return string The input content string with the editPanel appended. This function returns only an edit panel appended to the content string if a backend user is logged in (and has the correct permissions). Otherwise the content string is directly returned. */ - public function editPanel($content, array $conf, $currentRecord = '', array $dataArr = array(), $table = '', $allow = '', $newUID = 0, array $hiddenFields = array()) { + public function editPanel($content, array $conf, $currentRecord = '', array $dataArr = array(), $table = '', array $allow = array(), $newUID = 0, array $hiddenFields = array()) { $hiddenFieldString = $command = ''; // Special content is about to be shown, so the cache must be disabled. - $GLOBALS['TSFE']->set_no_cache('Frontend edit panel is shown', TRUE); + $this->frontendController->set_no_cache('Frontend edit panel is shown', TRUE); - $formName = 'TSFE_EDIT_FORM_' . substr($GLOBALS['TSFE']->uniqueHash(), 0, 4); + $formName = 'TSFE_EDIT_FORM_' . substr($this->frontendController->uniqueHash(), 0, 4); $formTag = '