/** * Configures the pages.abstract RTE * * @param array $configuration Extension configuration * * @return void */ public static function configure(array $configuration) { try { self::$configuration = ArrayUtility::getValueByPath($configuration, 'pages./abstract./rte.'); self::disableGlobally(); self::setVisibleButtons(); self::setHiddenButtons(); } catch (\Exception $e) { } }
/** * Returns the TypoScript configuration value at a the given path. * Example: config.tx_myext.some_conf * * @param string $path The path to the configuration value. * @param int|null|bool $pageUid The uid of the page you want the TypoScript configuration from. If "null" is given, only the static configuration is returned. * @param string $delimiter The delimiter for the path. Default is ".". * @return mixed|null */ public static function getConfigurationFromPath($path, $pageUid = null, $delimiter = '.') { $result = null; $cacheIdentifier = md5($path . (string) $pageUid); $cacheInstance = CacheManager::getCacheInstance(CacheManager::CACHE_MAIN); if ($cacheInstance) { if ($cacheInstance->has($cacheIdentifier)) { $result = $cacheInstance->get($cacheIdentifier); } elseif (ArrayUtility::isValidPath(self::getTypoScriptConfiguration($pageUid), $path, $delimiter)) { $result = ArrayUtility::getValueByPath(self::getTypoScriptConfiguration($pageUid), $path, $delimiter); $cacheInstance->set($cacheIdentifier, $result); } } return $result; }
/** * Read the option called $optionName from $this->options, and parse {...} * as object accessors. * * Then translate the value. * * If $optionName was not found, the corresponding default option is returned (from $this->defaultOptions) * * @param string $optionName * @return string|array|null * @api */ protected function parseOption(string $optionName) { if ($optionName === 'translation') { return null; } $optionValue = ArrayUtility::getValueByPath($this->options, $optionName); $defaultValue = ArrayUtility::getValueByPath($this->defaultOptions, $optionName); if ($optionValue === null && $defaultValue !== null) { $optionValue = $defaultValue; } if ($optionValue === null) { return null; } if (is_array($optionValue)) { return $optionValue; } $formRuntime = $this->finisherContext->getFormRuntime(); $optionToCompare = $optionValue; // You can encapsulate a option value with {}. // This enables you to access every getable property from the // TYPO3\CMS\Form\Domain\Runtime. // // For example: {formState.formValues.<elemenIdentifier>} // This is equal to "$formRuntime->getFormState()->getFormValues()[<elemenIdentifier>]" $optionValue = preg_replace_callback('/{([^}]+)}/', function ($match) use($formRuntime) { return ObjectAccess::getPropertyPath($formRuntime, $match[1]); }, $optionValue); if ($optionToCompare === $optionValue) { // This is just a shortcut for a {formState.formValues.<elementIdentifier>} notation. // If one of the finisher option values is equal // to a identifier from the form definition then // the value of the submitted form element is used // insteed. // Lets say you have a textfield in your form with the // identifier "Text1". If you put "Text1" // in the email finisher option "subject" then the submited value // from the "Text1" element is used as the email subject. $formValues = $this->finisherContext->getFormValues(); if (!is_bool($optionValue) && array_key_exists($optionValue, $formValues)) { $optionValue = $formRuntime[$optionValue]; } } if (isset($this->options['translation']['translationFile'])) { $optionValue = TranslationService::getInstance()->translateFinisherOption($formRuntime, $this->finisherIdentifier, $optionName, $optionValue, $this->options['translation']); } if (empty($optionValue)) { if ($defaultValue !== null) { $optionValue = $defaultValue; } } return $optionValue; }
/** * Get a value from configuration, this is default configuration * merged with local configuration * * @param string $path Path to search for * @return mixed */ public function getConfigurationValueByPath($path) { return Utility\ArrayUtility::getValueByPath(Utility\GeneralUtility::array_merge_recursive_overrule($this->getDefaultConfiguration(), $this->getLocalConfiguration()), $path); }
/** * Get the value within the settings of the duplication process, at the * given path. * If $path begins with "data:", the function will search for the * duplication data at the given index (string after "data:"), and return * the value, if found. * * @param string $path The path within the settings, if none given, the full settings will be returned. * @param string $delimiter The delimiter for path, default ".". * @return mixed The settings of the process at the given path, or the duplication data value (see function documentation). */ public function getProcessSettings($path = null, $delimiter = '.') { if ($path) { $setting = ArrayUtility::isValidPath($this->settings, $path, $delimiter) ? ArrayUtility::getValueByPath($this->settings, $path, $delimiter) : null; if ($setting) { if (strpos($setting, 'data:') !== false) { $settingDataKey = substr($setting, 5); if ($this->getDuplicationData($settingDataKey)) { $setting = $this->getDuplicationData($settingDataKey); } } } return $setting; } return $this->settings; }
/** * Get a value from configuration, this is default configuration * merged with local configuration * * @param string $path Path to search for * @return mixed */ public function getConfigurationValueByPath($path) { $defaultConfiguration = $this->getDefaultConfiguration(); Utility\ArrayUtility::mergeRecursiveWithOverrule($defaultConfiguration, $this->getLocalConfiguration()); return Utility\ArrayUtility::getValueByPath($defaultConfiguration, $path); }
/** * @param string $path The path within the settings, if none given, the full settings will be returned. * @param string $delimiter The delimiter for path, default ".". * @return mixed The settings of the field. */ public function getSettings($path = null, $delimiter = '.') { if ($path) { $setting = \TYPO3\CMS\Core\Utility\ArrayUtility::isValidPath($this->settings, $path, $delimiter) ? \TYPO3\CMS\Core\Utility\ArrayUtility::getValueByPath($this->settings, $path, $delimiter) : null; return $setting; } return $this->settings; }
/** * @param Page $page * @return Result * @throws PropertyMappingException */ protected function mapAndValidatePage(Page $page) : Result { $result = $this->objectManager->get(Result::class); $requestArguments = $this->request->getArguments(); $propertyPathsForWhichPropertyMappingShouldHappen = []; $registerPropertyPaths = function ($propertyPath) use(&$propertyPathsForWhichPropertyMappingShouldHappen) { $propertyPathParts = explode('.', $propertyPath); $accumulatedPropertyPathParts = []; foreach ($propertyPathParts as $propertyPathPart) { $accumulatedPropertyPathParts[] = $propertyPathPart; $temporaryPropertyPath = implode('.', $accumulatedPropertyPathParts); $propertyPathsForWhichPropertyMappingShouldHappen[$temporaryPropertyPath] = $temporaryPropertyPath; } }; foreach ($page->getElementsRecursively() as $element) { $value = ArrayUtility::getValueByPath($requestArguments, $element->getIdentifier()); $element->onSubmit($this, $value, $requestArguments); $this->formState->setFormValue($element->getIdentifier(), $value); $registerPropertyPaths($element->getIdentifier()); } // The more parts the path has, the more early it is processed usort($propertyPathsForWhichPropertyMappingShouldHappen, function ($a, $b) { return substr_count($b, '.') - substr_count($a, '.'); }); $processingRules = $this->formDefinition->getProcessingRules(); foreach ($propertyPathsForWhichPropertyMappingShouldHappen as $propertyPath) { if (isset($processingRules[$propertyPath])) { $processingRule = $processingRules[$propertyPath]; $value = $this->formState->getFormValue($propertyPath); try { $value = $processingRule->process($value); } catch (PropertyException $exception) { throw new PropertyMappingException('Failed to process FormValue at "' . $propertyPath . '" from "' . gettype($value) . '" to "' . $processingRule->getDataType() . '"', 1480024933, $exception); } $result->forProperty($propertyPath)->merge($processingRule->getProcessingMessages()); $this->formState->setFormValue($propertyPath, $value); } } return $result; }
/** * @param string $propertyPath * @return mixed */ public function getFormValue(string $propertyPath) { return ArrayUtility::getValueByPath($this->formValues, $propertyPath); }
/** * Calls a defined TypoScript library. * * @param array $arguments Array containing the request arguments. * @param int $id The page uid. * @return string The result of the TypoScript library. * @throws \Exception */ private function callTypoScriptLibrary($arguments, $id) { $pageConfiguration = self::getPageConfiguration($id); if (ArrayUtility::isValidPath($pageConfiguration, $arguments['typoScriptLib'], '.')) { $typoScriptLib = ArrayUtility::getValueByPath($pageConfiguration, $arguments['typoScriptLib'], '.'); if (!array_key_exists('_typoScriptNodeValue', $typoScriptLib)) { throw new \Exception('The TypoScript libraty "' . $arguments['typoScriptLib'] . '" does not have a Content Object type.', 1429113764); } $result = $this->callContentObject($typoScriptLib, $arguments['arguments']); return $result; } else { throw new \Exception('TypoScript library "' . $arguments['typoScriptLib'] . '" was not found.', 1429113004); } }
/** * Returns a string containing all the constants configuration for the * pages. * * @param int $pageUid The page uid. * @param array $pageUidAssociation Association of uid for the given page. * @return string */ private static function getTemplateConstantsUidAssociationString($pageUid, array $pageUidAssociation) { $constantsString = ''; $pagesPaths = TypoScriptUtility::getExtensionConfigurationFromPath('constantsPaths.pagesPaths'); if (!is_array($pagesPaths)) { } else { $constants = TypoScriptUtility::getTypoScriptConstants($pageUid); foreach ($pagesPaths as $path) { if (ArrayUtility::isValidPath($constants, $path, '.')) { $pagesValues = ArrayUtility::getValueByPath($constants, $path, '.'); if (is_array($pagesValues)) { foreach ($pagesValues as $pageName => $pageValue) { if (array_key_exists($pageValue, $pageUidAssociation)) { $constantsString .= $path . '.' . $pageName . ' = ' . $pageUidAssociation[$pageValue] . CRLF; } } } } } } return $constantsString; }
/** * Get a value from configuration, this is default configuration * merged with local configuration * * @param string $path Path to search for * @return mixed */ public static function getConfigurationValueByPath($path) { return \TYPO3\CMS\Core\Utility\ArrayUtility::getValueByPath(\TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule(static::getDefaultConfiguration(), static::getLocalConfiguration()), $path); }
/** * @param RootRenderableInterface $element * @param string $property * @param FormRuntime $formRuntime * @return string|array * @throws \InvalidArgumentException * @internal */ public function translateFormElementValue(RootRenderableInterface $element, string $property, FormRuntime $formRuntime) { if (empty($property)) { throw new \InvalidArgumentException('The argument "property" is empty', 1476216007); } $propertyType = 'properties'; $renderingOptions = $element->getRenderingOptions(); if ($property === 'label') { $defaultValue = $element->getLabel(); } else { if ($element instanceof FormElementInterface) { $defaultValue = ArrayUtility::getValueByPath($element->getProperties(), $property); } else { $propertyType = 'renderingOptions'; $defaultValue = ArrayUtility::getValueByPath($renderingOptions, $property); } } if (isset($renderingOptions['translation']['translatePropertyValueIfEmpty'])) { $translatePropertyValueIfEmpty = $renderingOptions['translation']['translatePropertyValueIfEmpty']; } else { $translatePropertyValueIfEmpty = true; } if (empty($defaultValue) && !$translatePropertyValueIfEmpty) { return $defaultValue; } $defaultValue = empty($defaultValue) ? '' : $defaultValue; $translationFile = $renderingOptions['translation']['translationFile']; $language = null; if (isset($renderingOptions['translation']['language'])) { $language = $renderingOptions['translation']['language']; } $translationKeyChain = []; if ($property === 'options' && is_array($defaultValue)) { foreach ($defaultValue as $optionValue => &$optionLabel) { $translationKeyChain = [sprintf('%s:%s.element.%s.%s.%s.%s', $translationFile, $formRuntime->getIdentifier(), $element->getIdentifier(), $propertyType, $property, $optionValue), sprintf('%s:element.%s.%s.%s.%s', $translationFile, $element->getIdentifier(), $propertyType, $property, $optionValue)]; $translatedValue = $this->processTranslationChain($translationKeyChain, $language); $optionLabel = empty($translatedValue) ? $optionLabel : $translatedValue; } $translatedValue = $defaultValue; } else { $translationKeyChain = [sprintf('%s:%s.element.%s.%s.%s', $translationFile, $formRuntime->getIdentifier(), $element->getIdentifier(), $propertyType, $property), sprintf('%s:element.%s.%s.%s', $translationFile, $element->getIdentifier(), $propertyType, $property), sprintf('%s:element.%s.%s.%s', $translationFile, $element->getType(), $propertyType, $property)]; $translatedValue = $this->processTranslationChain($translationKeyChain, $language); $translatedValue = empty($translatedValue) ? $defaultValue : $translatedValue; } return $translatedValue; }
/** * Get value by path. * @param string $path Path to value. * @param mixed $default Return value if none could by found. * @return mixed */ public function get($path, $default = NULL) { try { $value = \TYPO3\CMS\Core\Utility\ArrayUtility::getValueByPath($this->array, $path, $this->delimiter); } catch (\RuntimeException $exception) { $value = $default; } return $value; }
/** * Helper to return a specified path. * * @param array &$array The array to traverse as a reference * @param array|string $path The path to follow. Either a simple array of keys or a string in the format 'foo.bar.baz' * @return mixed The value found, NULL if the path didn't exist */ protected static function getValueByPathHelper(array $array, $path) { try { return ArrayUtility::getValueByPath($array, $path, '.'); } catch (\RuntimeException $e) { 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 = []; $fieldPaths = []; foreach ($convolutedFiles as $firstLevelFieldName => $fieldInformation) { if (!is_array($fieldInformation['error'])) { $fieldPaths[] = [$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 = []; foreach ($convolutedFiles[$fieldPath[0]] as $key => $subStructure) { try { $fileInformation[$key] = \TYPO3\CMS\Core\Utility\ArrayUtility::getValueByPath($subStructure, array_slice($fieldPath, 1)); } catch (\RuntimeException $e) { // do nothing if the path is invalid } } } $untangledFiles = \TYPO3\CMS\Core\Utility\ArrayUtility::setValueByPath($untangledFiles, $fieldPath, $fileInformation); } return $untangledFiles; }
/** * Gets backend layout identifiers to be excluded * * @param array $pageTSconfig * @return array */ protected function getIdentifiersToBeExcluded(array $pageTSconfig) { $identifiersToBeExcluded = array(); if (ArrayUtility::isValidPath($pageTSconfig, 'options./backendLayout./exclude')) { $identifiersToBeExcluded = GeneralUtility::trimExplode(',', ArrayUtility::getValueByPath($pageTSconfig, 'options./backendLayout./exclude'), true); } return $identifiersToBeExcluded; }
/** * @test */ public function getValueByPathAccpetsDifferentDelimeter() { $input = array('foo' => array('bar' => array('baz' => 42), 'bar2' => array())); $searchPath = 'foo%bar%baz'; $expected = 42; $delimeter = '%'; $this->assertEquals($expected, ArrayUtility::getValueByPath($input, $searchPath, $delimeter)); }
/** * Returns a value from the given flexform xml string * * @param string $xml The flexform XML string * @param string $field The field in question * * @return mixed|string */ protected function getFlexformValue($xml, $field) { $data = GeneralUtility::xml2array($xml); $value = ArrayUtility::getValueByPath($data, 'data/sDEF/lDEF/' . $field . '/vDEF'); return $value !== $data ? $value : 'N/A'; }
/** * Returns the page type label reference for the configured page type. * * @param Type $pageType Set page type * * @return string */ private function getPageTypeLabelReference(Type $pageType) { $registeredTypes = ArrayUtility::getValueByPath($GLOBALS, 'TCA/pages/columns/doktype/config/items'); $typeConfigurations = array_filter($registeredTypes, function ($configuration) use($pageType) { return (int) $configuration[1] === $pageType->getValue(); }); $typeConfiguration = array_shift($typeConfigurations); return array_shift($typeConfiguration); }