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

[FEATURE] add getter getInstances() in FormObjectFactory #87

Open
wants to merge 27 commits into
base: wip/steps
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1c9819f
[CLEANUP] Remove doc and reference to removed method
romm Aug 6, 2017
2c4763f
[BUGFIX] Instantiate fields validators with object manager in Ajax
romm Aug 11, 2017
0be97eb
[TASK] Initialize validator messages before validation
romm Aug 11, 2017
f221822
[BUGFIX] Fix variables not passed to field layout view in TYPO3 8.6
romm Sep 5, 2017
a97b7a3
[TASK] Fix unit tests
romm Oct 23, 2017
193ba2f
[BUGFIX] Use more accurate identifier for assets hash
romm Oct 23, 2017
0c91fd7
[BUGFIX] Handle multiple occurrences of messages markers in JavaScript
romm Oct 17, 2017
a3ee50a
[BUGFIX] Prevent getting unformatted input (#70)
AzOoDev Oct 24, 2017
e5b4370
[BUGFIX] Use a different view form the field layout rendering
romm Oct 25, 2017
3834e32
[BUGFIX] Add current template variables to slot
romm Oct 25, 2017
a0a4d2c
[BUGFIX] Add current layout/partial root paths to field template
romm Oct 25, 2017
3b5ac06
[BUGFIX] Handle nested fields views behaviour with Fluid standalone
romm Oct 25, 2017
3cf3f5f
[BUGFIX] Call view helpers parent arguments initialization
romm Oct 25, 2017
4626b02
[TASK] Use `self` statement in method parameter
romm Nov 9, 2017
79eddae
[BUGFIX] Handle boolean value `false` in `RequiredValidator`
romm Nov 9, 2017
ea395e8
[TASK] Add CSS condition for `FieldIsEmptyCondition` (#73)
hlabbassi Nov 10, 2017
7474daf
[DOC] Fix several typos
romm Jan 11, 2018
e316fe7
[TASK] Improve pattern for `word` validation rules
romm Jan 16, 2018
92597e5
[FEATURE] Add `fz-loading` to `form` tag when field is validating (#78)
Mopolo Jan 16, 2018
55ec7e2
[TASK] Rename TCA file to `tt_content`
romm Jan 22, 2018
a349528
[DOC] Fix English translation
romm Jan 22, 2018
c99d9f9
[TASK] Show the error code when definition is invalid (#82)
franzholz Jan 27, 2018
a6ab84d
[TASK] Update Composer licence identifier to new format
romm Jan 27, 2018
b44b0ec
[TASK] Trim value on input fields (#83)
Jan 27, 2018
e4a9bdb
[FEATURE] Introduce new condition `FieldIsFilled` (#84)
abdeljabbar Feb 12, 2018
b28e824
[FEATURE] add condition activation fieldCountValues
Mar 2, 2018
64c3e8b
[FEATURE] add getter getInstances() in FormObjectFactory
Mar 16, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getFormzGeneratedFilePath($prefix = '')
0,
22
);
$identifier .= '-' . md5($formObject->getHash());
$identifier .= '-' . md5($formObject->getHash() . $formObject->getName());

return CacheService::GENERATED_FILES_PATH . $identifier;
}
Expand Down
8 changes: 8 additions & 0 deletions Classes/Condition/ConditionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
namespace Romm\Formz\Condition;

use Romm\Formz\Condition\Items\ConditionItemInterface;
use Romm\Formz\Condition\Items\FieldCountValuesCondition;
use Romm\Formz\Condition\Items\FieldHasErrorCondition;
use Romm\Formz\Condition\Items\FieldHasValueCondition;
use Romm\Formz\Condition\Items\FieldIsEmptyCondition;
use Romm\Formz\Condition\Items\FieldIsFilledCondition;
use Romm\Formz\Condition\Items\FieldIsValidCondition;
use Romm\Formz\Exceptions\ClassNotFoundException;
use Romm\Formz\Exceptions\EntryNotFoundException;
Expand Down Expand Up @@ -134,6 +136,12 @@ public function registerDefaultConditions()
)->registerCondition(
FieldIsEmptyCondition::CONDITION_NAME,
FieldIsEmptyCondition::class
)->registerCondition(
FieldIsFilledCondition::CONDITION_IDENTIFIER,
FieldIsFilledCondition::class
)->registerCondition(
FieldCountValuesCondition::CONDITION_IDENTIFIER,
FieldCountValuesCondition::class
);
}
}
Expand Down
34 changes: 34 additions & 0 deletions Classes/Condition/Exceptions/InvalidConditionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ final public static function conditionFieldIsEmptyFieldNotFound($fieldName)
return $exception;
}

/**
* @code 1518016343128
*
* @param string $fieldName
* @return InvalidConditionException
*/
final public static function conditionFieldIsFilledFieldNotFound($fieldName)
{
/** @var self $exception */
$exception = self::getNewExceptionInstance(
self::FIELD_DOES_NOT_EXIST,
[$fieldName]
);

return $exception;
}

/**
* @code 1488183577
*
Expand All @@ -165,4 +182,21 @@ final public static function conditionFieldIsValidFieldNotFound($fieldName)

return $exception;
}

/**
* @code 1519909297
*
* @param string $fieldName
* @return InvalidConditionException
*/
final public static function conditionFieldCountValuesFieldNotFound($fieldName)
{
/** @var self $exception */
$exception = self::getNewExceptionInstance(
self::FIELD_DOES_NOT_EXIST,
[$fieldName]
);

return $exception;
}
}
108 changes: 108 additions & 0 deletions Classes/Condition/Items/FieldCountValuesCondition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?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\Condition\Items;

use Romm\Formz\Condition\Exceptions\InvalidConditionException;
use Romm\Formz\Condition\Processor\DataObject\PhpConditionDataObject;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;

/**
* This condition will match when a field has a number of selected items between
* a given minimum and maximum.
*/
class FieldCountValuesCondition extends AbstractConditionItem
{
const CONDITION_IDENTIFIER = 'fieldCountValues';

/**
* @inheritdoc
* @var array
*/
protected static $javaScriptFiles = [
'EXT:formz/Resources/Public/JavaScript/Conditions/Formz.Condition.FieldCountValues.js'
];

/**
* @var string
* @validate NotEmpty
*/
protected $fieldName;

/**
* @var int
*/
protected $minimum;

/**
* @var int
*/
protected $maximum;

/**
* @param string $fieldName
* @param int $minimum
* @param int $maximum
*/
public function __construct($fieldName, $minimum = null, $maximum = null)
{
$this->fieldName = $fieldName;
$this->minimum = $minimum;
$this->maximum = $maximum;
}

/**
* @inheritdoc
*/
public function getJavaScriptResult()
{
return $this->getDefaultJavaScriptCall([
'fieldName' => $this->fieldName,
'minimum' => $this->minimum,
'maximum' => $this->maximum
]);
}

/**
* @inheritdoc
*/
public function getPhpResult(PhpConditionDataObject $dataObject)
{
$value = ObjectAccess::getProperty($dataObject->getForm(), $this->fieldName);

return !($this->minimum && count($value) < (int)$this->minimum)
&& !($this->maximum && count($value) > (int)$this->maximum);
}

/**
* @inheritdoc
*
* @throws InvalidConditionException
*/
protected function checkConditionConfiguration()
{
$configuration = $this->formObject->getConfiguration();

if (false === $configuration->hasField($this->fieldName)) {
throw InvalidConditionException::conditionFieldCountValuesFieldNotFound($this->fieldName);
}
}

/**
* @return string
*/
public function getCssResult()
{
return '';
}
}
5 changes: 4 additions & 1 deletion Classes/Condition/Items/FieldIsEmptyCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ class FieldIsEmptyCondition extends AbstractConditionItem
*/
public function getCssResult()
{
return '[' . DataAttributesAssetHandler::getFieldDataValueKey($this->fieldName) . '=""]';
return [
'[' . DataAttributesAssetHandler::getFieldDataValueKey($this->fieldName) . '=""]',
':not([' . DataAttributesAssetHandler::getFieldDataValueKey($this->fieldName) . '])'
];
}

/**
Expand Down
95 changes: 95 additions & 0 deletions Classes/Condition/Items/FieldIsFilledCondition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/*
* 2018 Abdeljabar SAID <abdeljabar.saiid@gmail.com
* 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\Condition\Items;

use Romm\Formz\AssetHandler\Html\DataAttributesAssetHandler;
use Romm\Formz\Condition\Exceptions\InvalidConditionException;
use Romm\Formz\Condition\Processor\DataObject\PhpConditionDataObject;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;

/**
* This condition will match when a field is filled with any value.
*/
class FieldIsFilledCondition extends AbstractConditionItem
{
const CONDITION_IDENTIFIER = 'fieldIsFilled';

/**
* @inheritdoc
* @var array
*/
protected static $javaScriptFiles = [
'EXT:formz/Resources/Public/JavaScript/Conditions/Formz.Condition.FieldIsFilled.js'
];

/**
* @var string
* @validate NotEmpty
*/
protected $fieldName;

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

/**
* @inheritdoc
*/
public function getCssResult()
{
$valueKey = DataAttributesAssetHandler::getFieldDataValueKey($this->fieldName);

return '[' . $valueKey . ']:not([' . $valueKey . '=""])';
}

/**
* @inheritdoc
*/
public function getJavaScriptResult()
{
return $this->getDefaultJavaScriptCall(['fieldName' => $this->fieldName]);
}

/**
* @inheritdoc
*/
public function getPhpResult(PhpConditionDataObject $dataObject)
{
$value = ObjectAccess::getProperty($dataObject->getForm(), $this->fieldName);

return !empty($value);
}

/**
* Checks the condition configuration/options.
*
* If any syntax/configuration error is found, an exception of type
* `InvalidConditionException` must be thrown.
*
* @throws InvalidConditionException
*/
protected function checkConditionConfiguration()
{
$configuration = $this->formObject->getConfiguration();

if (false === $configuration->hasField($this->fieldName)) {
throw InvalidConditionException::conditionFieldIsFilledFieldNotFound($this->fieldName);
}
}
}
4 changes: 2 additions & 2 deletions Classes/Condition/Parser/Node/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ interface NodeInterface
public function getParent();

/**
* @param NodeInterface $parent
* @param self $parent
*/
public function setParent(NodeInterface $parent);
public function setParent(self $parent);

/**
* @return ConditionTree
Expand Down
2 changes: 1 addition & 1 deletion Classes/Configuration/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getFormzConfiguration()

/**
* Will fetch the configuration from cache, and build it if not found. It
* wont be stored in cache if any error is found. This is done this way to
* won't be stored in cache if any error is found. This is done this way to
* avoid the integrator to be forced to flush caches when errors are found.
*
* @param string $cacheIdentifier
Expand Down
3 changes: 1 addition & 2 deletions Classes/Controller/AjaxValidationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use Romm\Formz\Service\ExtensionService;
use Romm\Formz\Service\MessageService;
use Romm\Formz\Validation\DataObject\ValidatorDataObject;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Error\Error;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
Expand Down Expand Up @@ -201,7 +200,7 @@ public function runAction($name, $className, $fieldName, $validatorName)
$validatorDataObject = new ValidatorDataObject($this->formObject, $this->validation);

/** @var ValidatorInterface $validator */
$validator = GeneralUtility::makeInstance(
$validator = Core::instantiate(
$this->validation->getClassName(),
$this->validation->getOptions(),
$validatorDataObject
Expand Down
8 changes: 8 additions & 0 deletions Classes/Form/FormObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ protected function getCacheIdentifier($className, $name)
]
);
}

/**
* @return FormObject[]
*/
public function getInstances()
{
return $this->instances;
}

/**
* @param ConfigurationFactory $configurationFactory
Expand Down
4 changes: 0 additions & 4 deletions Classes/Service/FormService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
*
* - Access to the last submitted form which validation failed:
* `$myFailedForm = FormUtility::getFormWithErrors(MyForm::class);`
*
* - Automatic redirect if required argument is missing:
*
* @see `onRequiredArgumentIsMissing()`
*/
class FormService implements SingletonInterface
{
Expand Down
21 changes: 15 additions & 6 deletions Classes/Service/ViewHelper/Field/FieldViewHelperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,23 @@ public function getView(Layout $layout)
$identifier = $layout->getTemplateFile();

if (null === $this->view[$identifier]) {
/** @var StandaloneView $view */
$view = Core::instantiate(StandaloneView::class);
$view->setTemplatePathAndFilename($layout->getTemplateFile());

$this->view[$identifier] = $view;
$this->view[$identifier] = $this->getViewInstance($layout);
}

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

/**
* @param Layout $layout
* @return StandaloneView
*/
protected function getViewInstance(Layout $layout)
{
/** @var StandaloneView $view */
$view = Core::instantiate(StandaloneView::class);
$view->setTemplatePathAndFilename($layout->getTemplateFile());

return $view;
}

/**
Expand Down
Loading