Last active
July 24, 2019 17:13
-
-
Save derhansen/3e3cc4a5b5ca0cd960fe9047f01f171b to your computer and use it in GitHub Desktop.
TYPO3 InlineReadOnly FormDataProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('TYPO3_MODE') or die(); | |
call_user_func(function () { | |
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'][ | |
\Vendor\Extension\Backend\Form\FormDataProvider\InlineReadOnly::class | |
] = [ | |
'depends' => [ | |
\TYPO3\CMS\Backend\Form\FormDataProvider\EvaluateDisplayConditions::class, | |
] | |
]; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vendor\Extension\Backend\Form\FormDataProvider; | |
use TYPO3\CMS\Backend\Form\FormDataProviderInterface; | |
/** | |
* Disables all IRRE Controls and sets fields of IRRE records to readonly | |
* | |
* Note: Depending on the TYPO3 backend user permissions, a user may still be able to edit record content | |
* (e.g. if table is available in record list and user has sufficient rights to edit data). But for inline integration, | |
* the record(s) should be readOnly. | |
*/ | |
class InlineReadOnly implements FormDataProviderInterface | |
{ | |
/** | |
* @param array $result | |
* @return array | |
*/ | |
public function addData(array $result) | |
{ | |
$result = $this->evaluateInlineReadOnlyState($result); | |
return $result; | |
} | |
/** | |
* Evaluates 'readOnly' TCA state. Removes controls for IRRE elements with readOnly state and | |
* sets fields of child TCA to readOnly | |
* | |
* @param array $result | |
* @return array | |
*/ | |
protected function evaluateInlineReadOnlyState(array $result): array | |
{ | |
// Disable all controls for the IRRE records | |
foreach ($result['processedTca']['columns'] as $columnName => $columnConfiguration) { | |
if (!isset($columnConfiguration['config']['readOnly'])) { | |
continue; | |
} elseif ((bool)$columnConfiguration['config']['readOnly'] === true) { | |
$result['processedTca']['columns'][$columnName]['config']['appearance']['enabledControls'] = [ | |
'info' => false, | |
'new' => false, | |
'dragdrop' => false, | |
'sort' => false, | |
'hide' => false, | |
'delete' => false, | |
'localize' => false, | |
]; | |
foreach ([ | |
'inlineNewButtonStyle', | |
'inlineNewRelationButtonStyle', | |
'inlineOnlineMediaAddButtonStyle' | |
] as $field) { | |
$result['processedTca']['columns'][$columnName]['config']['inline'][$field] = 'display: none;'; | |
} | |
} | |
} | |
// Sets all fields to readOnly if parent inline element is readOnly | |
if (isset($result['inlineParentConfig']) && $result['inlineParentConfig']['readOnly']) { | |
foreach ($result['processedTca']['columns'] as $columnName => $columnConfiguration) { | |
$result['processedTca']['columns'][$columnName]['config']['readOnly'] = true; | |
} | |
} | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment