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

Commit

Permalink
[!!!][TASK] Remove deprecated validation data
Browse files Browse the repository at this point in the history
  • Loading branch information
romm committed Aug 5, 2017
1 parent 3ca5335 commit b57bd08
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 227 deletions.
15 changes: 0 additions & 15 deletions Classes/Form/FormInterface.php
Expand Up @@ -25,19 +25,4 @@
*/
interface FormInterface
{
/**
* @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 and will be deleted in FormZ v2.
*
* @param array $validationData
* @internal
*/
public function setValidationData(array $validationData);
}
2 changes: 1 addition & 1 deletion Classes/Form/FormObject/Service/FormObjectProperties.php
Expand Up @@ -26,7 +26,7 @@ class FormObjectProperties
/**
* @var array
*/
private static $ignoredProperties = ['validationData', 'uid', 'pid', '_localizedUid', '_languageUid', '_versionedUid'];
private static $ignoredProperties = ['uid', 'pid', '_localizedUid', '_languageUid', '_versionedUid'];

/**
* @var FormObjectStatic
Expand Down
42 changes: 0 additions & 42 deletions Classes/Form/FormTrait.php
Expand Up @@ -13,8 +13,6 @@

namespace Romm\Formz\Form;

use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* This trait should be used by default to implement all the functions required
* by the interface `FormInterface`.
Expand All @@ -24,44 +22,4 @@
*/
trait FormTrait
{
/**
* Contains the optional data returned from the validators of each field.
*
* @var array
*/
protected $validationData = [];

/**
* @deprecated This method is deprecated and will be deleted in FormZ v2.
*
* @param string $key
* @return array
*/
public function getValidationData($key = null)
{
GeneralUtility::logDeprecatedFunction();

$result = $this->validationData;

if (null !== $key) {
$result = (isset($this->validationData[$key]))
? $result = $this->validationData[$key]
: null;
}

return $result;
}

/**
* @deprecated This method is deprecated and will be deleted in FormZ v2.
*
* @param array $validationData
* @internal
*/
public function setValidationData(array $validationData)
{
GeneralUtility::logDeprecatedFunction();

$this->validationData = $validationData;
}
}
40 changes: 0 additions & 40 deletions Classes/Validation/Validator/AbstractValidator.php
Expand Up @@ -72,14 +72,6 @@ abstract class AbstractValidator extends \TYPO3\CMS\Extbase\Validation\Validator
*/
protected $messages = [];

/**
* Array of arbitral data which can be added by child classes, and will
* then be added to the `$validationData` property of the form instance.
*
* @var array
*/
protected $validationData = [];

/**
* @var ValidatorDataObject
*/
Expand Down Expand Up @@ -146,38 +138,6 @@ protected function addNotice($key, $code, array $arguments = [], $title = '')
$this->result->addNotice($message);
}

/**
* Get the full validation data.
*
* @return array
*/
public function getValidationData()
{
return $this->validationData;
}

/**
* Refreshes entirely the validation data (see `setValidationDataValue()`).
*
* @param array $validationData
*/
protected function setValidationData(array $validationData)
{
$this->validationData = array_merge($this->validationData, $validationData);
}

/**
* Adds an arbitral value to the validator, which will be added to the
* `$validationData` property of the form.
*
* @param string $key Key of the data.
* @param mixed $value Value bound to the key.
*/
protected function setValidationDataValue($key, $value)
{
$this->validationData[$key] = $value;
}

/**
* @param string $type
* @param string $key
Expand Down
20 changes: 0 additions & 20 deletions Classes/Validation/Validator/Form/FormValidatorExecutor.php
Expand Up @@ -24,7 +24,6 @@
use Romm\Formz\Form\FormObject\FormObject;
use Romm\Formz\Service\MessageService;
use Romm\Formz\Validation\DataObject\ValidatorDataObject;
use Romm\Formz\Validation\Validator\AbstractValidator;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Error\Result;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
Expand Down Expand Up @@ -59,13 +58,6 @@ class FormValidatorExecutor
*/
protected $fieldsValidated = [];

/**
* Array of arbitral data which are handled by validators.
*
* @var array
*/
protected $validationData = [];

/**
* @var PhpConditionDataObject
*/
Expand Down Expand Up @@ -222,18 +214,6 @@ protected function processFieldValidator(Field $field, Validator $validator)
$validatorResult = $validatorInstance->validate($fieldValue);
$validatorResult = MessageService::get()->sanitizeValidatorResult($validatorResult, $validator->getName());

if ($validatorInstance instanceof AbstractValidator
&& false === empty($validationData = $validatorInstance->getValidationData())
) {
$this->validationData[$fieldName] = ($this->validationData[$fieldName]) ?: [];
$this->validationData[$fieldName] = array_merge(
$this->validationData[$fieldName],
$validationData
);

$form->setValidationData($this->validationData);
}

$this->getResult()->forProperty($fieldName)->merge($validatorResult);
unset($validatorDataObject);

Expand Down
39 changes: 0 additions & 39 deletions Documentation/04-DeveloperManual/PHP/Validator.rst
Expand Up @@ -22,8 +22,6 @@ The validators of FormZ give you access to the following variables/functions:
- :ref:`$supportsAllMessages <validator-supportsAllMessages>`
- :ref:`$javaScriptValidationFiles <validator-javaScriptValidationFiles>`
- :ref:`addError($key, $code, array $arguments) <validator-addError>`
- :ref:`setValidationData($validationData) <validator-setValidationData>`
- :ref:`setValidationDataValue($key, $value) <validator-setValidationDataValue>`

-----

Expand Down Expand Up @@ -139,43 +137,6 @@ Add an error
Description
You must use this function in order to add an error if the value does not pass the validation.

.. _validator-setValidationData:

Save information in an array
----------------------------

.. container:: table-row

Function
.. code-block:: php
$this->setValidationData(array $validationData);
Return
/
Parameters
- ``$validationData``: arbitrary data array to be saved.
Description
When a validator is used on a form field, you may want to put some arbitrary information aside for a future usage. It is a plain array which can contain any information. This array will then be injected inside the form instance (``$this->form``) at the end of the validation process.

.. _validator-setValidationDataValue:

Save information value in an array
----------------------------------

.. container:: table-row

Function
.. code-block:: php
$this->setValidationDataValue($key, $value);
Return
/
Parameters
- ``$key``: key of the arbitrary data to be saved.
- ``$value``: arbitrary data to be saved.
Description
Same as above, but for a simple entry in the array.

.. _validator-javaScriptValidationFiles:

Bind a JavaScript file
Expand Down
@@ -0,0 +1,30 @@
.. include:: ../../../Includes.txt

==========================================
Breaking: Remove validation data component
==========================================

Description
===========

Validation data is an old concept: managing form data from inside a validator is an anti-pattern.

Upcoming middlewares feature (coming in a next patch) will allow better flexibility and replace this feature.

Impact
======

The functionality has been entirely removed and the following methods can't be used anymore:

- :php:`Romm\Formz\Validation\Validator\AbstractValidator::getValidationData()`
- :php:`Romm\Formz\Validation\Validator\AbstractValidator::setValidationData()`
- :php:`Romm\Formz\Validation\Validator\AbstractValidator::setValidationDataValue()`
- :php:`Romm\Formz\Form\FormInterface::getValidationData()`
- :php:`Romm\Formz\Form\FormInterface::setValidationData()`

Migration
=========

You might set up your own service class which can be used to manipulate data between two validators.

An upcoming patch will introduce persistence for forms, and allow storing arbitrary data in database.
Expand Up @@ -22,8 +22,6 @@ Les validateurs de FormZ vous donnent accès aux variables/fonctions suivantes :
- :ref:`$supportsAllMessages <validator-supportsAllMessages>`
- :ref:`$javaScriptValidationFiles <validator-javaScriptValidationFiles>`
- :ref:`addError($key, $code, array $arguments) <validator-addError>`
- :ref:`setValidationData($validationData) <validator-setValidationData>`
- :ref:`setValidationDataValue($key, $value) <validator-setValidationDataValue>`

-----

Expand Down Expand Up @@ -139,43 +137,6 @@ Ajouter un erreur
Description
Vous devrez utiliser cette fonction pour rajouter une erreur si la valeur ne passe pas la validation.

.. _validator-setValidationData:

Enregistrer un tableau d'information
------------------------------------

.. container:: table-row

Fonction
.. code-block:: php
$this->setValidationData(array $validationData);
Retour
/
Paramètres
- ``$validationData`` : tableau de données arbitraires à enregistrer.
Description
Lorsqu'un validateur est utilisé sur un champ de formulaire, vous pouvez vouloir mettre de côté quelques informations arbitraires pour une utilisation future. Il s'agit d'un simple tableau pouvant contenir n'importe quelle information. Ce tableau sera injecté dans l'instance du formulaire (``$this->form``) à la fin du processus du validateur.

.. _validator-setValidationDataValue:

Enregistrer une valeur dans le tableau d'information
----------------------------------------------------

.. container:: table-row

Fonction
.. code-block:: php
$this->setValidationDataValue($key, $value);
Retour
/
Paramètres
- ``$key`` : clé de la valeur arbitraire à enregistrer.
- ``$value`` : valeur arbitraire à enregistrer.
Description
Pareil qu'au dessus, mais pour une simple entrée dans le tableau.

.. _validator-javaScriptValidationFiles:

Lier un fichier JavaScript
Expand Down
31 changes: 0 additions & 31 deletions Tests/Unit/Form/FormTraitTest.php

This file was deleted.

0 comments on commit b57bd08

Please sign in to comment.