Skip to content

Commit

Permalink
[REMOVAL] Remove (broken) support for form object lookup
Browse files Browse the repository at this point in the history
Affects v:condition.form.hasValidator and v:condition.form.isRequired

This removes the currently broken ability to look for a form
object in the ViewHelperVariableContainer; which has not
worked since refactoring the ViewHelper to static calling.

Also changes the required state of arguments to make sure
a complete set of arguments will always be present.

Constitutes a breaking change if your template does not
pass the “object” argument when calling the two mentioned
ViewHelpers. To work around this, add the “object” argument.

If used in a controller action where the object may be null,
create a condition in the controller action to create a dummy
instance if the instance is NULL, then make sure that gets
assigned to the template and used in the form.
  • Loading branch information
NamelessCoder committed Jun 19, 2018
1 parent 733c4b4 commit 1f2594e
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions Classes/ViewHelpers/Condition/Form/HasValidatorViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,17 @@ public function initializeArguments()
$this->registerArgument(
'validatorName',
'string',
'The class name of the Validator that indicates the property is required.'
'The name of the validator that must exist for the condition to be true.',
true
);
$this->registerArgument(
'object',
DomainObjectInterface::class,
'Optional object - if not specified, grabs the associated form object.'
'Optional object - if not specified, grabs the associated form object.',
true
);
}

/**
* @param ViewHelperVariableContainer $viewHelperVariableContainer
* @param string $formClassName
* @return DomainObjectInterface|NULL
*/
protected static function getFormObject($viewHelperVariableContainer, $formClassName = FormViewHelper::class)
{
if (true === $viewHelperVariableContainer->exists($formClassName, 'formObject')) {
return $viewHelperVariableContainer->get($formClassName, 'formObject');
}
if (self::ALTERNATE_FORM_VIEWHELPER_CLASSNAME !== $formClassName) {
return self::getFormObject($viewHelperVariableContainer, self::ALTERNATE_FORM_VIEWHELPER_CLASSNAME);
}
return null;
}

/**
* @param array $arguments
* @return boolean
Expand All @@ -90,9 +76,6 @@ protected static function evaluateCondition($arguments = null)
$validatorName = isset($arguments['validatorName']) ? $arguments['validatorName'] : null;
$object = isset($arguments['object']) ? $arguments['object'] : null;

if (null === $object) {
$object = static::getFormObject($renderingContext->getViewHelperVariableContainer());
}
$className = get_class($object);
if (false !== strpos($property, '.')) {
$pathSegments = explode('.', $property);
Expand Down

0 comments on commit 1f2594e

Please sign in to comment.