Added field entityId to requests when validating unique fields#144
Added field entityId to requests when validating unique fields#144bastos71 wants to merge 2 commits into
Conversation
|
|
||
| if ($item instanceof \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity) { | ||
| $item = new UniqueEntity($item, $this->currentElement->getConfig()->getDataClass()); | ||
| $item = new UniqueEntity($item, $this->currentElement->getConfig()->getDataClass(), $this->currentElement->getConfig()->getData()); |
There was a problem hiding this comment.
I thinks better to pass all class with data. $this->currentElement->getConfig()
| /** | ||
| * @var int | ||
| */ | ||
| public $entityId = null; |
There was a problem hiding this comment.
Store here whole entity object instead of fields.
| * @param mixed $data | ||
| */ | ||
| public function __construct(BaseUniqueEntity $base, $entityName) | ||
| public function __construct(BaseUniqueEntity $base, $entityName, $data) |
There was a problem hiding this comment.
public function __construct(BaseUniqueEntity $base, $entity)
| public function __construct(BaseUniqueEntity $base, $entityName) | ||
| public function __construct(BaseUniqueEntity $base, $entityName, $data) | ||
| { | ||
| $this->entityName = $entityName; |
66Ton99
left a comment
There was a problem hiding this comment.
I think you got my idea.
|
Okay no problem I think you're right :) Just a few minutes and I will commit it |
|
@66Ton99 The problem is : how do I pass entity object from PHP to Js Model ? Any idea ? Edit : because in my case my //...
public static function phpValueToJs($value)
{
// For object which has own __toString method
if ($value instanceof JsModelAbstract) {
return $value->toJsString();
}
// For object which has own __toString method
elseif (is_object($value) && method_exists($value, '__toString')) {
return self::phpValueToJs($value->__toString());
}
// For an object or associative array
elseif (is_object($value) || (is_array($value) && array_values($value) !== $value)) {
$jsObject = array();
foreach ($value as $paramName => $paramValue) {
$paramName = addcslashes($paramName, '\'\\');
$jsObject[] = "'$paramName':" . self::phpValueToJs($paramValue);
}
return sprintf('{%1$s}', implode($jsObject, ','));
}
//.....
}
//... |
|
Leave it as is. Put object as protected (or something like this, which will be ignored by phpValueToJs function) value it will allow extend base class and use all required fields for custom cases. |
|
You mean by creating a custom Constraint that will extends UniqueEntity constraint ? |
|
Yes |
|
Couldn't we just add the I pushed a new commit with my changes |
|
This bundle used in many different ways, so it must cover at list 99% cases. |
|
Sorry but I don't agree with you, the only fact to include the variable I will maintain my own fork to get future updates, hope you will change your mind |
|
Closing this in favor of #177, which ports the UniqueEntity entity id payload support to current master with focused PHPUnit/Jest coverage and green CI. Thanks for the original implementation and context. |
Port the request-payload part of old PR #144 onto the revived codebase. When a form is bound to an object exposing getId(), copy that id into the generated UniqueEntity JS constraint as entityId and include it in the browser uniqueness request payload. Document the entityId request field for custom uniqueness controllers. The default AjaxController behavior is intentionally unchanged because excluding the current entity depends on application-specific repository logic and identifier strategy. Add PHPUnit coverage for generated UniqueEntity model metadata and Jest coverage for the request payload. Validation: php /tmp/jsfv-composer.phar validate --strict; php /tmp/jsfv-composer.phar test; npm test; git diff --check. Co-authored-by: Codex <codex@openai.com>
Resolving issue #143