Skip to content

Commit

Permalink
Merge pull request #2 from million12/0.2
Browse files Browse the repository at this point in the history
Neos 1.2 revision
  • Loading branch information
ryzy committed Dec 17, 2014
2 parents fb8bb18 + 51a3b5b commit 49034cf
Show file tree
Hide file tree
Showing 48 changed files with 875 additions and 1,319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Modifies globally how TagBuilder behaves for NULL attributes.
* We're taking here the same strategy as with AttributesImplementation
* - we don't want any attributes to render at all if the value
* was set to NULL.
* was set to NULL or FALSE.
*
* @see \TYPO3\Fluid\Core\ViewHelper\TagBuilder
* @see \M12\Foundation\TypoScript\AttributesImplementation
Expand All @@ -28,15 +28,15 @@ class TagBuilderAspect {

/**
* This changes how TagBuilder->addAttribute() method works.
* When attribute's value is NULL, it does *unset* the value.
* When attribute's value is NULL or FALSE, it does *unset* the value.
* Otherwise addAttribute() method is called as usually.
*
* @param \TYPO3\Flow\AOP\JoinPointInterface $joinPoint
* @Flow\Around("method(TYPO3\Fluid\Core\ViewHelper\TagBuilder->addAttribute())")
* @return void
*/
public function catchAddAttribute(\TYPO3\Flow\AOP\JoinPointInterface $joinPoint) {
if (NULL === $joinPoint->getMethodArgument('attributeValue')) {
if (NULL === $joinPoint->getMethodArgument('attributeValue') || FALSE === $joinPoint->getMethodArgument('attributeValue')) {
/** @var \TYPO3\Fluid\Core\ViewHelper\TagBuilder $tagBuilder */
$tagBuilder = $joinPoint->getProxy();
$tagBuilder->removeAttribute($joinPoint->getMethodArgument('attributeName'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,42 @@ public function injectSettings(array $settings) {
public function process(NodeType $nodeType, array &$configuration, array $options) {
$this->validateSettings();

/** @var string $device: small, medium, large */
foreach ($this->settings['devices'] as $device => $deviceData) {
foreach ($this->settings[static::$SETTINGS_SECTION] as $set => $setData) {
$propertyName = sprintf('class%s%s', ucfirst($device), ucfirst($set));
$defaultValue = isset($setData['defaults'][$device]) ? $setData['defaults'][$device] : '';
$configuration['properties'][$propertyName] = array(
'type' => 'string',
'defaultValue' => $defaultValue,
'ui' => array(
// 'label' => $propertyName,
'reloadIfChanged' => true,
'inspector' => array(
'group' => $setData['uiInspectorGroup'],
'position' => 1,
'editor' => 'TYPO3.Neos/Inspector/Editors/SelectBoxEditor',
'editorOptions' => $this->getEditorOptions($device, $set, $setData),
),
),
);
$k = 0;
foreach ($this->settings[static::$SETTINGS_SECTION] as $set => $setData) {
$propertyName = sprintf('classGrid%s', ucfirst($set));

$editorValues = [];
$defaultValue = isset($setData['defaults']) ? $setData['defaults'] : [''];

/** @var string $device: small, medium, large */
foreach ($this->settings['devices'] as $device => $deviceData) {
$groupLabel = $deviceData['label'];
$editorValues += $this->getEditorValues($set, $setData, $device, $groupLabel);
}
}

$configuration['properties'][$propertyName] = [
'type' => 'array',
'defaultValue' => $defaultValue,
'ui' => [
'label' => $setData['label'],
'reloadIfChanged' => true,
'inspector' => [
'group' => $setData['uiInspectorGroup'],
'position' => ($k+1)*10,
'editor' => 'TYPO3.Neos/Inspector/Editors/SelectBoxEditor',
'editorOptions' => [
'multiple' => TRUE,
'allowEmpty' => TRUE,
'placeholder' => 'placeholder text...',
'values' => $editorValues,
],
],
],
];

$k++;
}

// \TYPO3\Flow\var_dump($configuration);
}

Expand All @@ -95,12 +109,9 @@ public function process(NodeType $nodeType, array &$configuration, array $option
* @param array $setData settings for the $set
* @return array
*/
protected function getEditorOptions($device, $set, array $setData) {
$editorOptions = array();

// empty 1st option
$editorOptions['placeholder'] = "- $device $set -";
$editorOptions['values'][''] = array('label' => '');
protected function getEditorValues($set, array $setData, $device, $groupLabel) {
$groupLabel = $groupLabel ? $groupLabel : $device;
$editorValues = [];

$cssSuffixes = $this->settings[static::$SETTINGS_SECTION][$set]['cssClassSuffixes'];
foreach ($cssSuffixes as $cssSuffix) {
Expand All @@ -115,8 +126,9 @@ protected function getEditorOptions($device, $set, array $setData) {
do {
$valueName = $cssClass.$col;
$labelName = $valueName;
$editorOptions['values'][$valueName] = array(
$editorValues[$valueName] = array(
'label' => $labelName,
'group' => $groupLabel,
);
$col++;
} while (--$k);
Expand All @@ -128,13 +140,14 @@ protected function getEditorOptions($device, $set, array $setData) {
else {
$valueName = $cssClass;
$labelName = $valueName;
$editorOptions['values'][$valueName] = array(
$editorValues[$valueName] = array(
'label' => $labelName,
'group' => $groupLabel,
);
}
}

return $editorOptions;
return $editorValues;
}

protected function validateSettings() {
Expand Down
136 changes: 0 additions & 136 deletions Classes/M12/Foundation/TypoScript/ContentCollectionImplementation.php

This file was deleted.

2 changes: 1 addition & 1 deletion Classes/M12/Foundation/TypoScript/MenuImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function buildMenuLevelRecursive(array $menuLevelCollection) {
$item['cssClasses'] = '';

/** @var NodeInterface $node */
$node = $item['originalNode'];
$node = $item['node'];

//
// [FEATURE]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace M12\Foundation\TypoScript;
namespace M12\Foundation\TypoScriptObjects;

/* *
* This script belongs to the "M12.Foundation" package. *
Expand All @@ -11,16 +11,22 @@
* The TYPO3 project - inspiring people to share! *
* */

use TYPO3\TypoScript\TypoScriptObjects\AttributesImplementation as NeosAttributesImplementation;
use TYPO3\TypoScript\TypoScriptObjects\AttributesImplementation as TypoScriptAttributesImplementation;
use TYPO3\Flow\Annotations as Flow;

/**
* {@inheritdoc}
*
* Additionally, we change the behaviour slightly so attributes
* with NULL values are not printed at all.
* Additionally, we change the behaviour slightly: evaluate() return
* object (itself), which with __toString method ensures that
* {attributes} inside Flow views are rendered as usually.
*
* In addition, we have a possibility to call {attributes.asString}
* or {attributes.asArray} explicitly, when needed. This might be
* needed when you want to pass arbitrary attributes to some view helpers
* additionalAttributes param (e.g. f:form).
*/
class AttributesImplementation extends NeosAttributesImplementation {
class AttributesImplementation extends TypoScriptAttributesImplementation {

/**
* Key name under which custom user attributes might be available
Expand All @@ -38,28 +44,37 @@ class AttributesImplementation extends NeosAttributesImplementation {
protected $renderedAttributes;

/**
* @return string
* @return $this
*/
public function evaluate() {
$this->parseCustomUserAttributes();

$allowEmpty = $this->getAllowEmpty();
$attributes = array();
$renderedAttributes = '';
foreach (array_keys($this->properties) as $attributeName) {
if ($attributeName === '__meta') continue;

$encodedAttributeName = htmlspecialchars($attributeName, ENT_COMPAT, 'UTF-8', FALSE);
$attributeValue = $this->tsValue($attributeName);

if (null === $attributeValue) {
continue;
} else if (is_string($attributeValue) && 0 === strlen($attributeValue)) {
if ($attributeValue === NULL || $attributeValue === FALSE) {
// No op
} elseif ($attributeValue === TRUE || $attributeValue === '') {
$attributes[$attributeName] = $attributeValue;
$renderedAttributes .= ' ' . $encodedAttributeName;
$renderedAttributes .= ' ' . $encodedAttributeName . ($allowEmpty ? '' : '=""');
} else {
if (is_array($attributeValue)) {
$attributeValue = implode(' ', $attributeValue);
$joinedAttributeValue = '';
foreach ($attributeValue as $attributeValuePart) {
if ((string)$attributeValuePart !== '') {
$joinedAttributeValue .= ' ' . trim($attributeValuePart);
}
}
$attributeValue = trim($joinedAttributeValue);
}
$encodedAttributeValue = htmlspecialchars($attributeValue, ENT_COMPAT, 'UTF-8', FALSE);

$attributes[$attributeName] = $attributeValue;
$renderedAttributes .= ' ' . $encodedAttributeName . '="' . $encodedAttributeValue . '"';
}
Expand Down
Loading

0 comments on commit 49034cf

Please sign in to comment.