merge() public static method

public static merge ( array $array1, array $array2 ) : array
$array1 array
$array2 array
return array
 /**
  * @test
  */
 public function canOperateArrayMergeFunction()
 {
     $array1 = array('foo' => array('bar' => TRUE));
     $array2 = array('foo' => array('foo' => TRUE));
     $expected = array('foo' => array('bar' => TRUE, 'foo' => TRUE));
     $product = RecursiveArrayUtility::merge($array1, $array2);
     $this->assertSame($expected, $product);
 }
 /**
  * @return void
  */
 protected function initializeViewVariables()
 {
     $row = $this->getRecord();
     $form = $this->provider->getForm($row);
     $generalSettings = $this->configurationService->convertFlexFormContentToArray($row['pi_flexform'], $form);
     $contentSettings = $this->configurationService->convertFlexFormContentToArray($row['content_options'], $form);
     $this->settings = RecursiveArrayUtility::merge($this->settings, $generalSettings, FALSE, FALSE);
     if (FALSE === isset($this->settings['content'])) {
         $this->settings['content'] = $contentSettings;
     } else {
         $this->settings['content'] = RecursiveArrayUtility::merge($this->settings['content'], $contentSettings);
     }
     parent::initializeViewVariables();
 }
 /**
  * @return void
  */
 protected function initializeViewVariables($row)
 {
     $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     $this->provider = $objectManager->get('FluidTYPO3\\FluidcontentCore\\Provider\\CoreContentProvider');
     $this->configurationService = $objectManager->get('FluidTYPO3\\Flux\\Service\\FluxService');
     $form = $this->provider->getForm($row);
     $generalSettings = $this->configurationService->convertFlexFormContentToArray($row['pi_flexform'], $form);
     $contentSettings = $this->configurationService->convertFlexFormContentToArray($row['content_options'], $form);
     $this->settings = RecursiveArrayUtility::merge($this->settings, $generalSettings, false, false);
     if (false === isset($this->settings['content'])) {
         $this->settings['content'] = $contentSettings;
     } else {
         $this->settings['content'] = RecursiveArrayUtility::merge($this->settings['content'], $contentSettings);
     }
 }
Beispiel #4
0
 /**
  * Returns the page record with localisation applied, if any
  * exists in database.
  *
  * @return array
  */
 protected function getPageValues()
 {
     $record = $GLOBALS['TSFE']->page;
     if ($GLOBALS['TSFE']->sys_language_uid != 0) {
         $localisation = $this->recordService->get('pages_language_overlay', '*', 'pid = "' . $record['uid'] . '" AND sys_language_uid = "' . $GLOBALS['TSFE']->sys_language_uid . '"');
     }
     if (FALSE === empty($localisation)) {
         $record = RecursiveArrayUtility::merge($record, reset($localisation));
     }
     return $record;
 }
Beispiel #5
0
 /**
  * @param ProviderInterface $provider
  * @param array $row
  * @param Form $form
  * @return string|NULL
  */
 protected function renderPreviewSection(ProviderInterface $provider, array $row, Form $form = NULL)
 {
     $templatePathAndFilename = $provider->getTemplatePathAndFilename($row);
     if (NULL === $templatePathAndFilename) {
         return NULL;
     }
     $extensionKey = $provider->getExtensionKey($row);
     $paths = $provider->getTemplatePaths($row);
     $flexformVariables = $provider->getFlexFormValues($row);
     $templateVariables = $provider->getTemplateVariables($row);
     $variables = RecursiveArrayUtility::merge($templateVariables, $flexformVariables);
     $variables['row'] = $row;
     $variables['record'] = $row;
     if (TRUE === is_object($form)) {
         $formLabel = $form->getLabel();
         $label = LocalizationUtility::translate($formLabel, $extensionKey);
         $variables['label'] = $label;
     }
     $templatePaths = new TemplatePaths($paths);
     $viewContext = new ViewContext($templatePathAndFilename, $extensionKey, self::CONTROLLER_NAME);
     $viewContext->setTemplatePaths($templatePaths);
     $viewContext->setVariables($variables);
     $view = $this->configurationService->getPreparedExposedTemplateView($viewContext);
     $existingContentObject = $this->configurationManager->getContentObject();
     $contentObject = new ContentObjectRenderer();
     $contentObject->start($row, $provider->getTableName($row));
     $this->configurationManager->setContentObject($contentObject);
     $previewContent = $view->renderStandaloneSection(self::PREVIEW_SECTION, $variables, TRUE);
     $this->configurationManager->setContentObject($existingContentObject);
     $previewContent = trim($previewContent);
     return $previewContent;
 }
 /**
  * @param array $tree
  * @param string $cacheKey Overrides the cache key
  * @param boolean $mergeToCache Merges the configuration of $tree to the current $cacheKey
  * @return array
  */
 protected function getMergedConfiguration(array $tree, $cacheKey = NULL, $mergeToCache = FALSE)
 {
     if (NULL === $cacheKey) {
         $cacheKey = $this->getCacheKeyForMergedConfiguration($tree);
     }
     if (FALSE === $mergeToCache && TRUE === $this->hasCacheForMergedConfiguration($cacheKey)) {
         return self::$cache[$cacheKey];
     }
     $data = array();
     foreach ($tree as $branch) {
         $form = $this->getForm($branch);
         if (NULL === $form) {
             self::$cache[$cacheKey] = $data;
             return $data;
         }
         $fields = $form->getFields();
         $values = $this->getFlexFormValues($branch);
         foreach ($fields as $field) {
             $values = $this->unsetInheritedValues($field, $values);
         }
         $data = RecursiveArrayUtility::merge($data, $values);
     }
     if (TRUE === $mergeToCache && TRUE === $this->hasCacheForMergedConfiguration($cacheKey)) {
         $data = RecursiveArrayUtility::merge(self::$cache[$cacheKey], $data);
     }
     self::$cache[$cacheKey] = $data;
     return $data;
 }
 /**
  * @param array $providers
  * @param array $record
  * @param string $field
  * @return array
  */
 protected function readDataArrayFromProvidersOrUsingDefaultMethod(array $providers, $record, $field)
 {
     if (0 === count($providers)) {
         $dataArray = $this->configurationService->convertFlexFormContentToArray($record[$field]);
     } else {
         $dataArray = array();
         foreach ($providers as $provider) {
             $data = (array) $provider->getFlexFormValues($record);
             $dataArray = RecursiveArrayUtility::merge($dataArray, $data);
         }
     }
     return $dataArray;
 }
Beispiel #8
0
 /**
  * @return void
  */
 public function initializeOverriddenSettings()
 {
     $this->settings = RecursiveArrayUtility::merge($this->settings, $this->data['settings']);
 }
Beispiel #9
0
 /**
  * Returns the page record with localisation applied, if any
  * exists in database. Maintains uid and pid of the original
  * page if localisation is applied.
  *
  * @return array
  */
 protected function getPageValues()
 {
     $record = $GLOBALS['TSFE']->page;
     if ($GLOBALS['TSFE']->sys_language_uid != 0) {
         $localisation = $this->recordService->get('pages_language_overlay', '*', 'pid = "' . $record['uid'] . '" AND sys_language_uid = "' . $GLOBALS['TSFE']->sys_language_uid . '"' . ' AND hidden = false' . ' AND deleted = false' . ' AND (starttime = 0 OR starttime <= UNIX_TIMESTAMP())' . ' AND (endtime = 0 OR endtime > UNIX_TIMESTAMP())');
     }
     if (FALSE === empty($localisation)) {
         $mergedRecord = RecursiveArrayUtility::merge($record, reset($localisation));
         if (isset($record['uid']) && isset($record['pid'])) {
             $mergedRecord['uid'] = $record['uid'];
             $mergedRecord['pid'] = $record['pid'];
         }
         return $mergedRecord;
     }
     return $record;
 }
Beispiel #10
0
 /**
  * @param string $extensionName
  * @return array|NULL
  */
 public function getViewConfigurationForExtensionName($extensionName)
 {
     $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionName);
     $configuration = $this->getDefaultViewConfigurationForExtensionKey($extensionKey);
     $subConfiguration = (array) $this->getTypoScriptSubConfiguration(NULL, 'view', $extensionKey);
     $configuration = RecursiveArrayUtility::merge($configuration, $subConfiguration);
     if (FALSE === is_array($configuration)) {
         $this->message('Template paths resolved for "' . $extensionName . '" was not an array.', GeneralUtility::SYSLOG_SEVERITY_WARNING);
         $configuration = NULL;
     }
     return $configuration;
 }
Beispiel #11
0
 /**
  * Returns the page record with localisation applied, if any
  * exists in database.
  *
  * @return array
  */
 protected function getPageValues()
 {
     $record = $GLOBALS['TSFE']->page;
     $localisation = $this->recordService->get('pages_language_overlay', '*', "pid = '" . $record['uid'] . "'");
     if (FALSE === empty($localisation)) {
         $record = RecursiveArrayUtility::merge($record, reset($localisation));
     }
     return $record;
 }
Beispiel #12
0
 /**
  * @param array $row
  * @return array
  */
 protected function getInheritedConfiguration(array $row)
 {
     $tableName = $this->getTableName($row);
     $tableFieldName = $this->getFieldName($row);
     $cacheKey = $tableName . $tableFieldName . $row['uid'];
     if (false === isset(self::$cache[$cacheKey])) {
         $tree = $this->getInheritanceTree($row);
         $data = [];
         foreach ($tree as $branch) {
             /** @var SubPageProvider $provider */
             $provider = $this->pageConfigurationService->resolvePrimaryConfigurationProvider($this->tableName, self::FIELD_NAME_SUB, $branch);
             $form = $provider->getForm($branch);
             if (null === $form) {
                 continue;
             }
             $fields = $form->getFields();
             $values = $provider->getFlexFormValuesSingle($branch);
             foreach ($fields as $field) {
                 $values = $this->unsetInheritedValues($field, $values);
             }
             $data = RecursiveArrayUtility::merge($data, $values);
         }
         self::$cache[$cacheKey] = $data;
     }
     return self::$cache[$cacheKey];
 }
 /**
  * @param array $tree
  * @param string $cacheKey Overrides the cache key
  * @param boolean $mergeToCache Merges the configuration of $tree to the current $cacheKey
  * @return array
  */
 protected function getMergedConfiguration(array $tree, $cacheKey = NULL, $mergeToCache = FALSE)
 {
     if (NULL === $cacheKey) {
         $cacheKey = $this->getCacheKeyForMergedConfiguration($tree);
     }
     if (FALSE === $mergeToCache && TRUE === $this->hasCacheForMergedConfiguration($cacheKey)) {
         return self::$cache[$cacheKey];
     }
     $data = array();
     foreach ($tree as $branch) {
         $form = $this->getForm($branch);
         if (NULL === $form) {
             self::$cache[$cacheKey] = $data;
             return $data;
         }
         $fields = $form->getFields();
         $values = $this->getFlexFormValues($branch);
         foreach ($fields as $field) {
             $name = $field->getName();
             $stop = TRUE === $field->getStopInheritance();
             $inherit = TRUE === $field->getInheritEmpty();
             $empty = TRUE === empty($values[$name]) && $values[$name] !== '0' && $values[$name] !== 0;
             if (TRUE === $stop || FALSE === $inherit && TRUE === $empty) {
                 unset($values[$name]);
             }
         }
         $data = RecursiveArrayUtility::merge($data, $values);
     }
     if (TRUE === $mergeToCache && TRUE === $this->hasCacheForMergedConfiguration($cacheKey)) {
         $data = RecursiveArrayUtility::merge(self::$cache[$cacheKey], $data);
     }
     self::$cache[$cacheKey] = $data;
     return $data;
 }
Beispiel #14
0
 /**
  * @param array $row
  * @return array
  */
 protected function getInheritedConfiguration(array $row)
 {
     $tableName = $this->getTableName($row);
     $tableFieldName = $this->getFieldName($row);
     $cacheKey = $tableName . $tableFieldName . $row['uid'];
     if (TRUE === empty(self::$cache[$cacheKey])) {
         $tree = $this->getInheritanceTree($row);
         $data = array();
         foreach ($tree as $branch) {
             $provider = $this->configurationService->resolvePrimaryConfigurationProvider($this->tableName, self::FIELD_NAME_SUB, $branch);
             $form = $provider->getForm($branch);
             if (NULL === $form) {
                 break;
             }
             $fields = $form->getFields();
             $values = $provider->getFlexFormValuesSingle($branch);
             foreach ($fields as $field) {
                 $values = $this->unsetInheritedValues($field, $values);
             }
             $data = RecursiveArrayUtility::merge($data, $values);
         }
         self::$cache[$cacheKey] = $data;
     }
     return self::$cache[$cacheKey];
 }
Beispiel #15
0
 /**
  * @param array $providers
  * @param array $record
  * @param string $field
  * @return array
  */
 protected static function readDataArrayFromProvidersOrUsingDefaultMethod(array $providers, $record, $field)
 {
     if (0 === count($providers)) {
         $lang = static::getCurrentLanguageName();
         $pointer = static::getCurrentValuePointerName();
         $dataArray = static::$configurationService->convertFlexFormContentToArray($record[$field], NULL, $lang, $pointer);
     } else {
         $dataArray = array();
         /** @var ProviderInterface $provider */
         foreach ($providers as $provider) {
             $data = (array) $provider->getFlexFormValues($record);
             $dataArray = RecursiveArrayUtility::merge($dataArray, $data);
         }
     }
     return $dataArray;
 }
 /**
  * Render method
  * @param string $table
  * @param string $field
  * @param integer $uid
  * @param array $record
  * @param string $as
  * @return array
  * @throws Exception
  */
 public function render($table, $field, $uid = NULL, $record = NULL, $as = NULL)
 {
     if (NULL === $uid && NULL !== $record && TRUE === isset($record['uid'])) {
         $uid = $record['uid'];
     }
     if (TRUE === isset(self::$dataCache[$uid . $table . $field])) {
         $dataArray = self::$dataCache[$uid . $table . $field];
     } elseif (TRUE === isset($GLOBALS['TCA'][$table]) && TRUE === isset($GLOBALS['TCA'][$table]['columns'][$field])) {
         if (NULL === $record) {
             $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid,' . $field, $table, sprintf('uid=%d', $uid));
         }
         if (FALSE === $record) {
             throw new Exception(sprintf('Either table "%s", field "%s" or record with uid %d do not exist and you did not manually ' . 'provide the "row" attribute.', $table, $field, $uid), 1358679983);
         }
         $providers = $this->configurationService->resolveConfigurationProviders($table, $field, $record);
         if (0 === count($providers)) {
             $dataArray = $this->configurationService->convertFlexFormContentToArray($record[$field]);
         } else {
             $dataArray = array();
             foreach ($providers as $provider) {
                 $data = (array) $provider->getFlexFormValues($record);
                 $dataArray = RecursiveArrayUtility::merge($dataArray, $data);
             }
         }
         self::$dataCache[$uid . $table . $field] = $dataArray;
     } else {
         throw new Exception('Invalid table:field "' . $table . ':' . $field . '" - does not exist in TYPO3 TCA.', 1387049117);
     }
     if (NULL !== $as) {
         if ($this->templateVariableContainer->exists($as)) {
             $backupVariable = $this->templateVariableContainer->get($as);
             $this->templateVariableContainer->remove($as);
         }
         $this->templateVariableContainer->add($as, $dataArray);
         $content = $this->renderChildren();
         $this->templateVariableContainer->remove($as);
         if (TRUE === isset($backupVariable)) {
             $this->templateVariableContainer->add($as, $backupVariable);
         }
         return $content;
     }
     return $dataArray;
 }
Beispiel #17
0
 /**
  * @return void
  */
 protected function initializeOverriddenSettings()
 {
     $row = $this->getRecord();
     $extensionKey = $this->provider->getExtensionKey($row);
     $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionKey);
     if (TRUE === isset($this->data['settings']) && TRUE === is_array($this->data['settings'])) {
         // a "settings." array is defined in the flexform configuration - extract it, use as "settings" in template
         // as well as the internal $this->settings array as per expected Extbase behavior.
         $this->settings = RecursiveArrayUtility::merge($this->settings, $this->data['settings']);
     }
     if (TRUE === isset($this->settings['useTypoScript']) && TRUE === (bool) $this->settings['useTypoScript']) {
         // an override shared by all Flux enabled controllers: setting plugin.tx_EXTKEY.settings.useTypoScript = 1
         // will read the "settings" array from that location instead - thus excluding variables from the flexform
         // which are still available as $this->data but no longer available automatically in the template.
         $this->settings = $this->configurationService->getSettingsForExtensionName($extensionKey);
     }
 }
 /**
  * @return void
  */
 protected function initializeViewVariables()
 {
     $row = $this->getRecord();
     $flexFormData = $this->configurationService->convertFlexFormContentToArray($row['pi_flexform']);
     $this->settings = RecursiveArrayUtility::merge($this->settings, $flexFormData, FALSE, FALSE);
     parent::initializeViewVariables();
 }