Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'remotes/composer/development' into midd…
Browse files Browse the repository at this point in the history
…leware-wip

# Conflicts:
#	Classes/Form/FormInterface.php
#	Classes/Form/FormTrait.php
#	Classes/Service/ViewHelper/Slot/SlotContextEntry.php
#	Classes/ViewHelpers/FormViewHelper.php
#	Tests/Unit/Service/ViewHelper/Field/FieldViewHelperServiceTest.php
#	Tests/Unit/Service/ViewHelper/Form/FormViewHelperServiceTest.php
#	Tests/Unit/ViewHelpers/ClassViewHelperTest.php
#	Tests/Unit/ViewHelpers/FieldViewHelperTest.php
#	Tests/Unit/ViewHelpers/FormatMessageViewHelperTest.php
#	Tests/Unit/ViewHelpers/OptionViewHelperTest.php
#	Tests/Unit/ViewHelpers/Slot/RenderViewHelperTest.php
  • Loading branch information
romm committed May 17, 2017
2 parents 1dfeb05 + e225096 commit 7d77947
Show file tree
Hide file tree
Showing 28 changed files with 451 additions and 238 deletions.
4 changes: 2 additions & 2 deletions Classes/Form/FormInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
interface FormInterface
{
/**
* @deprecated This method is deprecated since FormZ v2, and will be deleted in FormZ v3.
* @deprecated This method is deprecated and will be deleted in FormZ v2.
*
* @param string $key
* @return array
*/
public function getValidationData($key = null);

/**
* @deprecated This method is deprecated since FormZ v2, and will be deleted in FormZ v3.
* @deprecated This method is deprecated and will be deleted in FormZ v2.
*
* @param array $validationData
* @internal
Expand Down
4 changes: 2 additions & 2 deletions Classes/Form/FormTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getValidationResult()
}

/**
* @deprecated This method is deprecated since FormZ v2, and will be deleted in FormZ v3.
* @deprecated This method is deprecated and will be deleted in FormZ v2.
*
* @param string $key
* @return array
Expand All @@ -92,7 +92,7 @@ public function getValidationData($key = null)
}

/**
* @deprecated This method is deprecated since FormZ v2, and will be deleted in FormZ v3.
* @deprecated This method is deprecated and will be deleted in FormZ v2.
*
* @param array $validationData
* @internal
Expand Down
62 changes: 62 additions & 0 deletions Classes/Service/ViewHelper/Field/FieldContextEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/*
* 2017 Romain CANON <romain.hydrocanon@gmail.com>
*
* This file is part of the TYPO3 FormZ project.
* It is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License, either
* version 3 of the License, or any later version.
*
* For the full copyright and license information, see:
* http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace Romm\Formz\Service\ViewHelper\Field;

use Romm\Formz\Configuration\Form\Field\Field;

class FieldContextEntry
{
/**
* @var Field
*/
protected $field;

/**
* @var array
*/
protected $options = [];

/**
* @param Field $field
*/
public function __construct(Field $field)
{
$this->field = $field;
}

/**
* @return Field|null
*/
public function getField()
{
return $this->field;
}

/**
* @param string $name
* @param mixed $value
*/
public function setOption($name, $value)
{
$this->options[$name] = $value;
}

/**
* @return array
*/
public function getOptions()
{
return $this->options;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
* http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace Romm\Formz\Service\ViewHelper;
namespace Romm\Formz\Service\ViewHelper\Field;

use Romm\Formz\Configuration\View\Layouts\Layout;
use Romm\Formz\Core\Core;
use Romm\Formz\Form\Definition\Field\Field;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;

/**
Expand All @@ -26,58 +27,55 @@
class FieldViewHelperService implements SingletonInterface
{
/**
* @var Field
*/
protected $currentField;

/**
* @var array
* Contains all current fields being rendered by FormZ: if a field is
* rendered beneath another field, several entries will be added to this
* property.
*
* @var FieldContextEntry[]
*/
protected $fieldOptions = [];
protected $contextEntries;

/**
* @var StandaloneView[]
*/
protected $view;

/**
* Reset every state that can be used by this service.
* Adds a new context entry to the entries array. The other field-related
* methods will be processed on this entry until the field rendering has
* ended.
*
* @param Field $field
*/
public function resetState()
public function setCurrentField(Field $field)
{
$this->currentField = null;
$this->fieldOptions = [];
$this->contextEntries[] = GeneralUtility::makeInstance(FieldContextEntry::class, $field);
}

/**
* Checks that the `FieldViewHelper` has been called. If not, an exception
* is thrown.
*
* @return bool
* Removes the current field context entry.
*/
public function fieldContextExists()
public function removeCurrentField()
{
return $this->currentField instanceof Field;
array_pop($this->contextEntries);
}

/**
* Returns the current field which was defined by the `FieldViewHelper`.
*
* Returns null if no current field was found.
* Checks that a field context is found.
*
* @return Field|null
* @return bool
*/
public function getCurrentField()
public function fieldContextExists()
{
return $this->currentField;
return false === empty($this->contextEntries);
}

/**
* @param Field $field
* @return Field
*/
public function setCurrentField(Field $field)
public function getCurrentField()
{
$this->currentField = $field;
return $this->getCurrentContext()->getField();
}

/**
Expand All @@ -86,15 +84,15 @@ public function setCurrentField(Field $field)
*/
public function setFieldOption($name, $value)
{
$this->fieldOptions[$name] = $value;
$this->getCurrentContext()->setOption($name, $value);
}

/**
* @return array
*/
public function getFieldOptions()
{
return $this->fieldOptions;
return $this->getCurrentContext()->getOptions();
}

/**
Expand All @@ -119,4 +117,12 @@ public function getView(Layout $layout)

return $this->view[$identifier];
}

/**
* @return FieldContextEntry
*/
protected function getCurrentContext()
{
return end($this->contextEntries);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace Romm\Formz\Service\ViewHelper;
namespace Romm\Formz\Service\ViewHelper\Form;

use Romm\Formz\AssetHandler\Html\DataAttributesAssetHandler;
use Romm\Formz\Behaviours\BehavioursManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,63 @@
* http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace Romm\Formz\Service\ViewHelper;
namespace Romm\Formz\Service\ViewHelper\Slot;

use Closure;
use Romm\Formz\Exceptions\EntryNotFoundException;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3\CMS\Fluid\Core\ViewHelper\TemplateVariableContainer;

class SlotViewHelperService implements SingletonInterface
class SlotContextEntry
{
/**
* @var RenderingContextInterface|\TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface
*/
protected $renderingContext;

/**
* Contains the closures which will render the registered slots. The keys
* of this array are the names of the slots.
*
* @var Closure[]
*/
private $closures = [];
protected $closures = [];

/**
* @var array[]
*/
private $arguments = [];
protected $arguments = [];

/**
* @var RenderingContextInterface[]|\TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface[]
* @var array[]
*/
private $renderingContext = [];
protected $injectedVariables = [];

/**
* @var array[]
*/
private $injectedVariables = [];
protected $savedVariables = [];

/**
* @var array[]
* @param RenderingContextInterface $renderingContext
*/
private $savedVariables = [];
public function __construct(RenderingContextInterface $renderingContext)
{
$this->renderingContext = $renderingContext;
}

/**
* Adds a closure - which will render the slot with the given name - to the
* Adds a closure - used to render the slot with the given name - to the
* private storage in this class.
*
* @param string $name
* @param Closure $closure
* @param array $arguments
* @param RenderingContextInterface $renderingContext
* @param string $name
* @param Closure $closure
* @param array $arguments
*/
public function addSlot($name, Closure $closure, array $arguments, RenderingContextInterface $renderingContext)
public function addSlot($name, Closure $closure, array $arguments)
{
$this->closures[$name] = $closure;
$this->arguments[$name] = $arguments;
$this->renderingContext[$name] = $renderingContext;
}

/**
Expand Down Expand Up @@ -114,12 +118,12 @@ public function hasSlot($name)
* Note that the variables that are already defined are first saved before
* being overridden, so they can be restored later.
*
* @param string $slotName
* @param array $arguments
* @param string $slotName
* @param array $arguments
*/
public function addTemplateVariables($slotName, array $arguments)
{
$templateVariableContainer = $this->getTemplateVariableContainer($slotName);
$templateVariableContainer = $this->renderingContext->getTemplateVariableContainer();
$savedArguments = [];

ArrayUtility::mergeRecursiveWithOverrule(
Expand All @@ -144,11 +148,11 @@ public function addTemplateVariables($slotName, array $arguments)
* Will remove all variables previously injected in the template variable
* container, and restore the ones that were saved before being overridden.
*
* @param string $slotName
* @param string $slotName
*/
public function restoreTemplateVariables($slotName)
{
$templateVariableContainer = $this->getTemplateVariableContainer($slotName);
$templateVariableContainer = $this->renderingContext->getTemplateVariableContainer();
$mergedArguments = (isset($this->injectedVariables[$slotName])) ? $this->injectedVariables[$slotName] : [];
$savedArguments = (isset($this->savedVariables[$slotName])) ? $this->savedVariables[$slotName] : [];

Expand All @@ -160,27 +164,4 @@ public function restoreTemplateVariables($slotName)
$templateVariableContainer->add($key, $value);
}
}

/**
* @param string $slotName
* @return TemplateVariableContainer
*/
protected function getTemplateVariableContainer($slotName)
{
/** @var TemplateVariableContainer $templateVariableContainer */
$templateVariableContainer = $this->renderingContext[$slotName]->getTemplateVariableContainer();

return $templateVariableContainer;
}

/**
* Resets the service variables.
*/
public function resetState()
{
$this->closures = [];
$this->arguments = [];
$this->injectedVariables = [];
$this->savedVariables = [];
}
}

0 comments on commit 7d77947

Please sign in to comment.