Guest User

Untitled

a guest
Feb 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. <?php
  2. namespace Vendor\Extension\Backend\Form\FormDataProvider;
  3.  
  4. use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
  5.  
  6. /**
  7. * Disables all IRRE Controls and sets fields of IRRE records to readonly
  8. *
  9. * Note: Depending on the TYPO3 backend user permissions, a user may still be able to edit record content
  10. * (e.g. if table is available in record list and user has sufficient rights to edit data). But for inline integration,
  11. * the record(s) should be readOnly.
  12. */
  13. class InlineReadOnly implements FormDataProviderInterface
  14. {
  15. /**
  16. * @param array $result
  17. * @return array
  18. */
  19. public function addData(array $result)
  20. {
  21. $result = $this->evaluateInlineReadOnlyState($result);
  22. return $result;
  23. }
  24.  
  25. /**
  26. * Evaluates 'readOnly' TCA state. Removes controls for IRRE elements with readOnly state and
  27. * sets fields of child TCA to readOnly
  28. *
  29. * @param array $result
  30. * @return array
  31. */
  32. protected function evaluateInlineReadOnlyState(array $result): array
  33. {
  34. // Disable all controls for the IRRE records
  35. foreach ($result['processedTca']['columns'] as $columnName => $columnConfiguration) {
  36. if (!isset($columnConfiguration['config']['readOnly'])) {
  37. continue;
  38. } elseif ((bool)$columnConfiguration['config']['readOnly'] === true) {
  39. $result['processedTca']['columns'][$columnName]['config']['appearance']['enabledControls'] = [
  40. 'info' => false,
  41. 'new' => false,
  42. 'dragdrop' => false,
  43. 'sort' => false,
  44. 'hide' => false,
  45. 'delete' => false,
  46. 'localize' => false,
  47. ];
  48. }
  49. }
  50.  
  51. // Sets all fields to readOnly if parent inline element is readOnly
  52. if (isset($result['inlineParentConfig']) && $result['inlineParentConfig']['readOnly']) {
  53. foreach ($result['processedTca']['columns'] as $columnName => $columnConfiguration) {
  54. $result['processedTca']['columns'][$columnName]['config']['readOnly'] = true;
  55. }
  56. }
  57.  
  58. return $result;
  59. }
  60. }
Add Comment
Please, Sign In to add comment