Skip to content

Instantly share code, notes, and snippets.

@derhansen
Last active July 24, 2019 17:13

Revisions

  1. derhansen revised this gist Jul 24, 2019. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions InlineReadOnly
    Original file line number Diff line number Diff line change
    @@ -45,6 +45,13 @@ class InlineReadOnly implements FormDataProviderInterface
    'delete' => false,
    'localize' => false,
    ];
    foreach ([
    'inlineNewButtonStyle',
    'inlineNewRelationButtonStyle',
    'inlineOnlineMediaAddButtonStyle'
    ] as $field) {
    $result['processedTca']['columns'][$columnName]['config']['inline'][$field] = 'display: none;';
    }
    }
    }

  2. derhansen created this gist Feb 15, 2019.
    60 changes: 60 additions & 0 deletions InlineReadOnly
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    <?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;
    }
    }
    12 changes: 12 additions & 0 deletions ext_localconf.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <?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,
    ]
    ];
    });