Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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,
- ];
- }
- }
- // 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;
- }
- }
Add Comment
Please, Sign In to add comment