/** * Get the settings * * @param Tx_PtExtlist_Domain_Configuration_ConfigurationBuilder $configurationBuilder * @return array */ protected static function getExportSettingsForCurrentView(Tx_PtExtlist_Domain_Configuration_ConfigurationBuilder $configurationBuilder) { $allExportSettings = $configurationBuilder->getSettingsForConfigObject('export'); $controllerSettings = $configurationBuilder->getSettings('controller'); $selectedViewSettingsKey = $controllerSettings['Export']['download']['view']; $exportSettingsPath = explode('.', $selectedViewSettingsKey); $exportSettings = \TYPO3\CMS\Extbase\Utility\ArrayUtility::getValueByPath($configurationBuilder->getSettings(), $exportSettingsPath); /* In this case we have to merge the prototype settings again because the prototype settings are filled from flexform.... * This smells ... * TODO: find a better way .... */ return $configurationBuilder->getMergedSettingsWithPrototype($exportSettings, 'export'); }
/** * Extends the getData()-Method of \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer to process more/other commands * * @param string $getDataString Full content of getData-request e.g. "TSFE:id // field:title // field:uid * @param array $fields Current field-array * @param string $sectionValue Currently examined section value of the getData request e.g. "field:title * @param string $returnValue Current returnValue that was processed so far by getData * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $parentObject Parent content object * @return string Get data result */ public function getDataExtension($getDataString, array $fields, $sectionValue, $returnValue, \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer &$parentObject) { $parts = explode(':', $sectionValue, 2); $type = strtolower(trim($parts[0])); $key = trim($parts[1]); switch ($type) { case 'qbtools_flexform_field': $flexform_service = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Service\\FlexFormService'); $flexform_fields = $flexform_service->convertFlexFormContentToArray($fields['pi_flexform']); $returnValue = ArrayUtility::getValueByPath($flexform_fields, $key); break; } return $returnValue; }
/** * Add support for variable argument lists using a wildcard property name '*'. * This is required for a file multiupload, as you can't guess how many files * will be uploaded when rendering the form (and generating the * trustedPropertiesToken) on the server. * * You can use it like this: * If you write a formfield viewhelper, you have to register all the properties * that should be mapped when processing the input on the server. To allow * the mapping of some properties of all submitted elements, insert a wildcard * in the path at the position where new keys will appear. This class will * enable the mapping of all arguments that are assigned to this path. * * So, if you have this line in your viewhelper: * $this->registerFieldNameForFormTokenGeneration('my_plugin[my_object][object_storage_property][*][foo]'); * and request arguments like this: * array( 'my_object' => array( 'object_storage_property' => array( * 0 => array( 'foo' => 13 ), * 1 => array( 'foo' => 42 ), * 2 => array( 'foo' => false ) * ))) * the PropertyMapper won't complain about missing permissions to "map * attribute my_object.object_storage_property.0". * * This is different from simply using $propertyMappingConfiguration->allowAllProperties() * because: * - You don't have to post that line into each of your controllers * - You can control which sub-properties to map * - You don't override assigned settings for specific keys: if there is a * configuration for my_object.object_storage_property.42, it won't be * changed to the wildcard value. * * @param \TYPO3\CMS\Extbase\Mvc\Request $request * @param \TYPO3\CMS\Extbase\Mvc\Controller\Arguments $controllerArguments * @return void */ public function initializePropertyMappingConfigurationFromRequest(\TYPO3\CMS\Extbase\Mvc\Request $request, \TYPO3\CMS\Extbase\Mvc\Controller\Arguments $controllerArguments) { $trustedPropertiesToken = $request->getInternalArgument('__trustedProperties'); if (!is_string($trustedPropertiesToken)) { return; } $serializedTrustedProperties = $this->hashService->validateAndStripHmac($trustedPropertiesToken); $trustedProperties = unserialize($serializedTrustedProperties); foreach ($trustedProperties as $propertyName => $propertyConfiguration) { if (!$controllerArguments->hasArgument($propertyName)) { continue; } $propertyMappingConfiguration = $controllerArguments->getArgument($propertyName)->getPropertyMappingConfiguration(); // // Extended from parent class - begin // if (is_array($propertyConfiguration)) { foreach (HelhumArrayUtility::getPathsToKey($propertyConfiguration, '*') as $path) { $configurationTemplate = ExtbaseArrayUtility::getValueByPath($propertyConfiguration, $path . '.*'); $propertyConfiguration = ExtbaseArrayUtility::unsetValueByPath($propertyConfiguration, $path . '.*'); if ($request->hasArgument($propertyName) && is_array($request->getArgument($propertyName))) { $rawArgument = ExtbaseArrayUtility::getValueByPath($request->getArgument($propertyName), $path); $subPropertyConfiguration = ExtbaseArrayUtility::getValueByPath($propertyConfiguration, $path); foreach ($rawArgument as $index => $_) { if (!is_int($index) || array_key_exists($index, $subPropertyConfiguration)) { continue; } $propertyConfiguration = ExtbaseArrayUtility::setValueByPath($propertyConfiguration, $path . '.' . $index, $configurationTemplate); } } } } // // Extended from parent class - end // $this->modifyPropertyMappingConfiguration($propertyConfiguration, $propertyMappingConfiguration); } }
/** * Resolve the viewClassname defined via typoscript * * View class can be configured in TS via * plugin.<plugin_key>.settings.controller.<Controller_Name_without_Controller>.<action_Name_without_Action>.view = ViewClassName * * @throws Exception if view class does not exist * @return string */ protected function resolveTsDefinedViewClassName() { $viewClassName = $this->getTsViewClassName(); if ($viewClassName != '') { if (!class_exists($viewClassName)) { // Use the viewClassName as redirect path to a typoscript value holding the viewClassName $redirectedViewClassName = $viewClassName . '.viewClassName'; $tsRedirectPath = explode('.', $redirectedViewClassName); $redirectedViewClassName = \TYPO3\CMS\Extbase\Utility\ArrayUtility::getValueByPath($this->settings, $tsRedirectPath); if ($redirectedViewClassName) { $viewClassName = $redirectedViewClassName; } } } if ($viewClassName && !class_exists($viewClassName)) { throw new Exception('View class does not exist: ' . $viewClassName . ' 1281369758'); } // TODO make sure that given class implements a view return $viewClassName; }
/** * return a typoscript array by given typoscript path * * @param string $typoScriptPath * * @return array */ protected function getTSArrayByPath($typoScriptPath) { $pathArray = explode('.', $typoScriptPath); $outTSArray = \TYPO3\CMS\Extbase\Utility\ArrayUtility::getValueByPath($this->extListTypoScript, $pathArray); if (!is_array($outTSArray)) { $outTSArray = array(); } return $outTSArray; }
/** * Resolve the viewClassname defined via typoscript * * @return string * @throws Exception */ protected function resolveTsDefinedViewClassName() { $viewClassName = $this->settings['controller'][$this->request->getControllerName()][$this->request->getControllerActionName()]['view']; if ($viewClassName != '') { if (!class_exists($viewClassName)) { // Use the viewClassName as redirect path to a typoscript value holding the viewClassName $viewClassName .= '.viewClassName'; $tsRedirectPath = explode('.', $viewClassName); $viewClassName = \TYPO3\CMS\Extbase\Utility\ArrayUtility::getValueByPath($this->settings, $tsRedirectPath); } } if ($viewClassName && !class_exists($viewClassName)) { throw new Exception('View class does not exist! ' . $viewClassName, 1281369758); } return $viewClassName; }
/** * @param string $path * @return NULL|bool|int|string|array */ public function getValue($path) { try { return ArrayUtility::getValueByPath($this->data, $path); } catch (\InvalidArgumentException $exception) { return NULL; } }
/** * Transforms the convoluted _FILES superglobal into a manageable form. * * @param array $convolutedFiles The _FILES superglobal * @return array Untangled files * @see TYPO3\Flow\Utility\Environment */ protected function untangleFilesArray(array $convolutedFiles) { $untangledFiles = array(); $fieldPaths = array(); foreach ($convolutedFiles as $firstLevelFieldName => $fieldInformation) { if (!is_array($fieldInformation['error'])) { $fieldPaths[] = array($firstLevelFieldName); } else { $newFieldPaths = $this->calculateFieldPaths($fieldInformation['error'], $firstLevelFieldName); array_walk($newFieldPaths, function (&$value, $key) { $value = explode('/', $value); }); $fieldPaths = array_merge($fieldPaths, $newFieldPaths); } } foreach ($fieldPaths as $fieldPath) { if (count($fieldPath) === 1) { $fileInformation = $convolutedFiles[$fieldPath[0]]; } else { $fileInformation = array(); foreach ($convolutedFiles[$fieldPath[0]] as $key => $subStructure) { $fileInformation[$key] = \TYPO3\CMS\Extbase\Utility\ArrayUtility::getValueByPath($subStructure, array_slice($fieldPath, 1)); } } $untangledFiles = \TYPO3\CMS\Extbase\Utility\ArrayUtility::setValueByPath($untangledFiles, $fieldPath, $fileInformation); } return $untangledFiles; }
/** * @test */ public function getValueByPathReturnsNullIfThePathHasMoreSegmentsThanTheGivenArray() { $array = array('Foo' => array('Bar' => array('Baz' => 'the value'))); $this->assertNull(\TYPO3\CMS\Extbase\Utility\ArrayUtility::getValueByPath($array, array('Foo', 'Bar', 'Baz', 'Bux'))); }