Skip to content

Commit

Permalink
Merge branch 'development' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Sep 19, 2014
2 parents 29ee7e6 + 864630a commit ff42ee1
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 14 deletions.
7 changes: 7 additions & 0 deletions Classes/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ public static function createFromSettings(array $settings) {
$settings['movable'] = $settings['allowMoveToFooter'];
unset($settings['allowMoveToFooter']);
}
if (TRUE === isset($settings['arguments'])) {
// @TODO: remove in 2.2 or 3.0 whichever comes first.
GeneralUtility::deprecationLog('Deprecated property "arguments" was used in VHS Asset settings ' .
'for asset named "' . $settings['name'] . '". Please correct this to use the proper "variables" attribute');
$settings['variables'] = $settings['arguments'];
unset($settings['arguments']);
}
$asset = self::getInstance();
foreach ($settings as $propertyName => $value) {
ObjectAccess::setProperty($asset, $propertyName, $value);
Expand Down
24 changes: 19 additions & 5 deletions Classes/Service/AssetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,15 @@ private function manipulateAssetsByTypoScriptSettings($assets) {
if (TRUE === $removed) {
continue;
}
$localSettings = $assetSettings;
$localSettings = (array) $assetSettings;
if (TRUE === isset($settings['asset'])) {
ArrayUtility::mergeRecursiveWithOverrule($localSettings, (array) $settings['asset']);
$localSettings = $this->mergeArrays($localSettings, (array) $settings['asset']);
}
if (TRUE === isset($settings['asset'][$name])) {
ArrayUtility::mergeRecursiveWithOverrule($localSettings, (array) $settings['asset'][$name]);
$localSettings = $this->mergeArrays($localSettings, (array) $settings['asset'][$name]);
}
if (TRUE === isset($settings['assetGroup'][$groupName])) {
ArrayUtility::mergeRecursiveWithOverrule($localSettings, (array) $settings['assetGroup'][$groupName]);
$localSettings = $this->mergeArrays($localSettings, (array) $settings['assetGroup'][$groupName]);
}
if (TRUE === $asset instanceof \FluidTYPO3\Vhs\ViewHelpers\Asset\AssetInterface) {
$asset->setSettings($localSettings);
Expand All @@ -425,6 +425,20 @@ private function manipulateAssetsByTypoScriptSettings($assets) {
return $filtered;
}

/**
* @param $array1
* @param $array2
* @return array
*/
protected function mergeArrays(&$array1, $array2) {
if (6.2 <= (float) substr(TYPO3_version, 3)) {
ArrayUtility::mergeRecursiveWithOverrule($array1, $array2);
return $array1;
} else {
return GeneralUtility::array_merge_recursive_overrule($array1, $array2);
}
}

/**
* @param \FluidTYPO3\Vhs\ViewHelpers\Asset\AssetInterface[] $assets
* @throws \RuntimeException
Expand Down Expand Up @@ -508,7 +522,7 @@ private function sortAssetsByDependency($assets) {
private function renderAssetAsFluidTemplate($asset) {
$settings = $this->extractAssetSettings($asset);
$templateReference = $settings['path'];
$variables = (TRUE === (isset($settings['arguments']) && is_array($settings['arguments'])) ? $settings['arguments'] : array());
$variables = (TRUE === (isset($settings['variables']) && is_array($settings['variables'])) ? $settings['variables'] : array());
$isExternal = (TRUE === (isset($settings['external']) && $settings['external'] > 0));
if (TRUE === $isExternal) {
$fileContents = file_get_contents($templateReference);
Expand Down
3 changes: 2 additions & 1 deletion Classes/ViewHelpers/Asset/AbstractAssetViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public function initializeArguments() {
$this->registerArgument('standalone', 'boolean', 'If TRUE, excludes this Asset from any concatenation which may be applied');
$this->registerArgument('rewrite', 'boolean', 'If FALSE, this Asset will be included as is without any processing of contained urls', FALSE, TRUE);
$this->registerArgument('fluid', 'boolean', 'If TRUE, renders this (standalone or external) Asset as if it were a Fluid template, passing along values of the "arguments" attribute or every available template variable if "arguments" not specified', FALSE, FALSE);
$this->registerArgument('arguments', 'mixed', 'An optional array of arguments which you use inside the Asset, be it standalon or inline. Use this argument to ensure your Asset filenames are only reused when all variables used in the Asset are the same', FALSE, FALSE);
$this->registerArgument('arguments', 'mixed', 'DEPRECATED. Use argument `variables` instead', FALSE, FALSE);
$this->registerArgument('variables', 'mixed', 'An optional array of arguments which you use inside the Asset, be it standalon or inline. Use this argument to ensure your Asset filenames are only reused when all variables used in the Asset are the same', FALSE, FALSE);
$this->registerArgument('allowMoveToFooter', 'boolean', 'If TRUE, allows this Asset to be included in the document footer rather than the header. Should never be allowed for CSS.', FALSE, TRUE);
$this->registerArgument('trim', 'boolean', 'DEPRECATED. Trim is no longer supported. Setting this to TRUE doesn\'t do anything.', FALSE, FALSE);
$this->registerArgument('namedChunks', 'boolean', 'If FALSE, hides the comment containing the name of each of Assets which is merged in a merged file. Disable to avoid a bit more output at the cost of transparency', FALSE, FALSE);
Expand Down
24 changes: 19 additions & 5 deletions Classes/ViewHelpers/Iterator/ExtractViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,33 @@
*
* {anArray->v:iterator.extract(path: 'childProperty.secondNestedChildObject')->v:iterator.sort(direction: 'DESC', sortBy: 'propertyOnSecondChild')->v:iterator.slice(length: 10)->v:iterator.extract(key: 'uid')}
*
* #### Single return value
*
* Outputs the "uid" value of the first record in variable $someRecords without caring if there are more than
* one records. Always extracts the first value and then stops. Equivalent of chaning -> v:iterator.first().
* {someRecords -> v:iterator.extract(key: 'uid', single: TRUE)}
*
* @author Andreas Lappe <nd@kaeufli.ch>
* @package Vhs
* @subpackage ViewHelpers\Iterator
*/
class ExtractViewHelper extends AbstractViewHelper {

/**
* @param string $key
* @param \Traversable $content
* @param boolean $recursive
* @param string $key The name of the key from which you wish to extract the value
* @param mixed $content The array or Iterator that contains either the value or arrays of values
* @param boolean $recursive If TRUE, attempts to extract the key from deep nested arrays
* @param boolean $single If TRUE, returns only one value - always the first one - instead of an array of values
* @return array
*/
public function render($key, $content = NULL, $recursive = TRUE) {
public function render($key, $content = NULL, $recursive = TRUE, $single = FALSE) {
if (NULL === $content) {
$content = $this->renderChildren();
}
try {
// extraction from Iterators could potentially use a getter method which throws
// exceptions - although this would be bad practice. Catch the exception here
// and turn it into a WARNING log message so that output does not break.
if (TRUE === (boolean) $recursive) {
$result = $this->recursivelyExtractKey($content, $key);
} else {
Expand All @@ -111,6 +121,10 @@ public function render($key, $content = NULL, $recursive = TRUE) {
$result = array();
}

if (TRUE === (boolean) $single) {
return reset($result);
}

return $result;
}

Expand Down Expand Up @@ -143,7 +157,7 @@ public function extractByKey($iterator, $key) {
public function recursivelyExtractKey($iterator, $key) {
$content = array();

foreach ($iterator as $k => $v) {
foreach ($iterator as $v) {
// Lets see if we find something directly:
$result = ObjectAccess::getPropertyPath($v, $key);
if (NULL !== $result) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/Iterator/SortViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function initializeArguments() {
$this->registerArgument('as', 'string', 'Which variable to update in the TemplateVariableContainer. If left out, returns sorted data instead of updating the variable (i.e. reference or copy)');
$this->registerArgument('sortBy', 'string', 'Which property/field to sort by - leave out for numeric sorting based on indexes(keys)');
$this->registerArgument('order', 'string', 'ASC, DESC, RAND or SHUFFLE. RAND preserves keys, SHUFFLE does not - but SHUFFLE is faster', FALSE, 'ASC');
$this->registerArgument('sortFlags', 'string', 'Constant name from PHP for SORT_FLAGS: SORT_REGULAR, SORT_STRING, SORT_NUMERIC, SORT_NATURAL, SORT_LOCALE_STRING or SORT_FLAG_CASE. You can provide a comma seperated list or array to use a combination of flags.', FALSE, 'SORT_REGULAR');
$this->registerArgument('sortFlags', 'string', 'Constant name from PHP for `SORT_FLAGS`: `SORT_REGULAR`, `SORT_STRING`, `SORT_NUMERIC`, `SORT_NATURAL`, `SORT_LOCALE_STRING` or `SORT_FLAG_CASE`. You can provide a comma seperated list or array to use a combination of flags.', FALSE, 'SORT_REGULAR');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion Classes/ViewHelpers/Page/LanguageMenuViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,13 @@ protected function parseLanguageMenu() {
foreach ($languageMenu as $key => $value) {
$current = $GLOBALS['TSFE']->sys_language_uid === (integer) $key ? 1 : 0;
$inactive = $pageArray[$key] || (integer) $key === $this->defaultLangUid ? 0 : 1;
$url = $this->getLanguageUrl($key, $inactive);
if (TRUE === empty($url)) {
$url = GeneralUtility::getIndpEnv('REQUEST_URI');
}
$languageMenu[$key]['current'] = $current;
$languageMenu[$key]['inactive'] = $inactive;
$languageMenu[$key]['url'] = TRUE === (boolean) $current ? GeneralUtility::getIndpEnv('REQUEST_URI') : $this->getLanguageUrl($key, $inactive);
$languageMenu[$key]['url'] = $url;
$languageMenu[$key]['flagSrc'] = $this->getLanguageFlagSrc($value['flag']);
if (TRUE === (boolean) $this->arguments['hideNotTranslated'] && TRUE === (boolean) $inactive) {
unset($languageMenu[$key]);
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/Page/Menu/SubViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function render() {
return '';
}
// retrieve the set of template variables which were in play when the parent menu VH started rendering.
$variables = $this->viewHelperVariableContainer->get('\FluidTYPO3\Vhs\ViewHelpers\Page\Menu\AbstractMenuViewHelper', 'variables');
$variables = $this->viewHelperVariableContainer->get('FluidTYPO3\Vhs\ViewHelpers\Page\Menu\AbstractMenuViewHelper', 'variables');
$parentInstance->setOriginal(FALSE);
$content = $parentInstance->render();
// restore the previous set of variables after they most likely have changed during the render() above.
Expand Down

0 comments on commit ff42ee1

Please sign in to comment.