Skip to content

Commit

Permalink
GH-214: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
magicsunday committed Feb 3, 2023
1 parent b889d34 commit dcff7a2
Show file tree
Hide file tree
Showing 9 changed files with 572 additions and 297 deletions.
3 changes: 2 additions & 1 deletion Classes/Controller/ImageRenderingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Resource\Service\MagicImageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
use TYPO3\CMS\Frontend\Plugin\AbstractPlugin;

use function get_class;
Expand Down Expand Up @@ -230,7 +231,7 @@ protected function getMagicImageService(): MagicImageService
protected function isExternalImage(string $imageSource): bool
{
// https://github.com/netresearch/t3x-rte_ckeditor_image/issues/187
if (strpos($imageSource, '/typo3/image/process?token') !== false) {
if (strpos($imageSource, 'typo3/image/process?token') !== false) {
// is a 11LTS backend processing url only valid for BE users, thus reprocessing needed
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions Classes/Controller/SelectImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public function infoAction(ServerRequestInterface $request): ResponseInterface

$file = $this->getImage((int) $id);
$processedFile = $this->processImage($file, $params);

$lang = $this->getLanguageService();
$lang = $this->getLanguageService();

// Include language files
$this->getLanguageService()
Expand Down
143 changes: 143 additions & 0 deletions Classes/DataHandling/DataHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php

/**
* This file is part of the package netresearch/rte-ckeditor-image.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Netresearch\RteCKEditorImage\DataHandling;

use Netresearch\RteCKEditorImage\Database\RteImagesDbHook;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Html\RteHtmlParser;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

/**
* Hooks for data handler.
*
* @author Rico Sonntag <[email protected]>
* @license https://www.gnu.org/licenses/agpl-3.0.de.html
* @link https://www.netresearch.de
*/
class DataHandler
{
/**
* Process the modified text from TCA text field before its stored in the database.
*
* @param string $status
* @param string $table
* @param string $id
* @param array &$fieldArray
* @param \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler
*
* @return void
*/
public function processDatamap_postProcessFieldArray(
string $status,
string $table,
string $id,
array &$fieldArray,
\TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler
): void {

//DebuggerUtility::var_dump(__METHOD__);
//DebuggerUtility::var_dump($status);
//DebuggerUtility::var_dump($table);
//DebuggerUtility::var_dump($id);
//DebuggerUtility::var_dump($fieldArray);

foreach ($fieldArray as $field => $fieldValue) {
// The field must be editable. Checking if a value for language can be changed.
if (($GLOBALS['TCA'][$table]['ctrl']['languageField'] ?? false)
&& ((string)$GLOBALS['TCA'][$table]['ctrl']['languageField']) === ((string)$field)
&& !$this->getBackendUser()->checkLanguageAccess($fieldValue)
) {
continue;
}

// Ignore disabled fields
if ($dataHandler->data_disableFields[$table][$id][$field] ?? false) {
continue;
}

// Ignore not existing fields in TCA definition
if (!isset($GLOBALS['TCA'][$table]['columns'][$field])) {
continue;
}

// Getting config for the field
$tcaFieldConf = $this->resolveFieldConfigurationAndRespectColumnsOverrides(
$dataHandler,
$table,
$field
);

// Handle only fields of type "text"
if (empty($tcaFieldConf['type'])
|| ($tcaFieldConf['type'] !== 'text')
) {
continue;
}

// Ignore all none RTE text fields
if (!isset($tcaFieldConf['enableRichtext'])
|| ($tcaFieldConf['enableRichtext'] === false)
) {
continue;
}

$rteImageDbHook = GeneralUtility::makeInstance(RteImagesDbHook::class);
$rteHtmlParser = GeneralUtility::makeInstance(RteHtmlParser::class);

$fieldArray[$field] = $rteImageDbHook->transform_db($fieldArray[$field], $rteHtmlParser);
}
}

/**
* Returns the current backend user authentication instance.
*
* @return BackendUserAuthentication
*/
private function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}

/**
* Use columns overrides for evaluation.
*
* Fetch the TCA ["config"] part for a specific field, including the columnsOverrides value.
* Used for checkValue purposes currently (as it takes the checkValue_currentRecord value).
*
* @param \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler
* @param string $table
* @param string $field
*
* @return array
*
* @see \TYPO3\CMS\Core\DataHandling\DataHandler::resolveFieldConfigurationAndRespectColumnsOverrides
*/
private function resolveFieldConfigurationAndRespectColumnsOverrides(
\TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler,
string $table,
string $field
): array {
$tcaFieldConf = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
$recordType = BackendUtility::getTCAtypeValue($table, $dataHandler->checkValue_currentRecord);

$columnsOverridesConfigOfField = $GLOBALS['TCA'][$table]['types'][$recordType]['columnsOverrides'][$field]['config'] ?? null;

if ($columnsOverridesConfigOfField) {
ArrayUtility::mergeRecursiveWithOverrule($tcaFieldConf, $columnsOverridesConfigOfField);
}

return $tcaFieldConf;
}
}
Loading

0 comments on commit dcff7a2

Please sign in to comment.