FluidTYPO3\Flux\Backend\DynamicFlexForm::getFlexFormDS_postProcessDS PHP Method

getFlexFormDS_postProcessDS() public method

NOTE: patches data structure resolving in a way that solves a regression in the TYPO3 core when dealing with IRRE AJAX requests (in which the database record is no longer fetched by the controller). This patches not only data structure resolving for Flux data structures but indeed any data structure built using hooks or involving user functions which require the entire record (but when using hooks, supports only extensions which are loaded AFTER or depend on Flux).
public getFlexFormDS_postProcessDS ( array &$dataStructArray, array $conf, array &$row, string $table, string $fieldName ) : void
$dataStructArray array
$conf array
$row array
$table string
$fieldName string
return void
    public function getFlexFormDS_postProcessDS(&$dataStructArray, $conf, &$row, $table, $fieldName)
    {
        if (empty($fieldName) === TRUE) {
            // Cast NULL if an empty but not-NULL field name was passed. This has significance to the Flux internals in
            // respect to which ConfigurationProvider(s) are returned.
            $fieldName = NULL;
        }
        if (!empty($fieldName) && !isset($row[$fieldName])) {
            // Patch required (possibly temporary). Due to changes in TYPO3 in the new FormEngine we must fetch the
            // database record at this point when the record is incomplete, which happens when attempting to render
            // IRRE records. The reason is that the controller that creates the HTML does not fetch the record any
            // more - and that the AJAX request contains only the UID. So, we fetch the record here to ensure it
            // contains the necessary fields. DOES NOT WORK FOR NEW RECORDS - SEE COMMENTS BELOW.
            $row = $this->recordService->getSingle($table, '*', $row['uid']);
        }
        $defaultDataSourceCacheIdentifier = $table . '_' . $fieldName . '_' . sha1(serialize($conf));
        if (!$row) {
            // In the case that the database record cannot be fetched we are dealing with a new or otherwise deleted
            // or unidentifiable record. This happens primarily when AJAX requests are made to render IRRE records
            // without the parent record having been saved first. To accommodate this case we have to be slightly
            // creative and store a "default" data source definition which is identified based on a checksum of the
            // configuration provided. Whenever we are then unable to fetch a record, we can at least attempt to
            // locate a default data source in previously cached content. NB: we enforce a VERY high cache lifetime
            // and continually refresh it every time it is possible to render a new DS that can serve as default.
            $dataStructArray = (array) $this->cache->get($defaultDataSourceCacheIdentifier);
        } else {
            if (FALSE === is_array($dataStructArray)) {
                $dataStructArray = array();
            }
            $providers = $this->configurationService->resolveConfigurationProviders($table, $fieldName, $row);
            foreach ($providers as $provider) {
                $provider->postProcessDataStructure($row, $dataStructArray, $conf);
            }
            if (empty($dataStructArray)) {
                $dataStructArray = array('ROOT' => array('el' => array()));
            }
            $evaluationParameters = array();
            $this->cache->set($defaultDataSourceCacheIdentifier, $this->recursivelyEvaluateClosures($dataStructArray, $evaluationParameters), array(), time() + 31536000);
        }
        // Trigger TCEforms dimension patching only if required by TYPO3 version according to CompatibilityRegistry.
        if (CompatibilityRegistry::get('FluidTYPO3\\Flux\\Backend\\DynamicFlexForm::NEEDS_TCEFORMS_WRAPPER')) {
            $dataStructArray = $this->patchTceformsWrapper($dataStructArray);
        }
    }

Usage Example

Beispiel #1
0
 /**
  * @param string $fieldName
  * @param string $table
  * @return void
  */
 protected function canExecuteDataStructurePostProcessHookInternal($fieldName = 'pi_flexform', $table = 'tt_content')
 {
     $dataStructure = array();
     $config = array();
     $row = array();
     $instance = new DynamicFlexForm();
     $provider1 = $this->getMock('FluidTYPO3\\Flux\\Provider\\Provider', array('postProcessDataStructure'));
     $provider2 = $this->getMock('FluidTYPO3\\Flux\\Provider\\Provider', array('postProcessDataStructure'));
     $provider1->expects($this->once())->method('postProcessDataStructure');
     $provider2->expects($this->once())->method('postProcessDataStructure');
     $providers = array($provider1, $provider2);
     $service = $this->getMock('FluidTYPO3\\Flux\\Service\\FluxService', array('resolveConfigurationProviders'));
     $service->expects($this->once())->method('resolveConfigurationProviders')->with($table, $fieldName, $row)->willReturn($providers);
     $instance->injectConfigurationService($service);
     $instance->getFlexFormDS_postProcessDS($dataStructure, $config, $row, $table, $fieldName);
     $isArrayConstraint = new \PHPUnit_Framework_Constraint_IsType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY);
     $this->assertThat($dataStructure, $isArrayConstraint);
 }