Comments (11)
The same problem. I made category entity translatable, so I don't need name field of original entity to be required. How I can remove/override constraint defined in validation.xml?
from sonataclassificationbundle.
Ok after few hours, i finally found a way to solve the problem...
I think, it's not the best way (any idea...), because if you need to update the max length value, you have to update two files.
In your CategoryAdmin class
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', null, array(
'attr' => array(
'maxlength' => 200
)
))
;
}
public function getFormBuilder() {
//OverrideCategoryValidation => custom validation group
$this->formOptions = array('validation_groups' => 'OverrideCategoryValidation');
$formBuilder = parent::getFormBuilder();
return $formBuilder;
}
and in your category entity class :
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\Length(
* min = 2,
* max = 200,
* groups={"OverrideCategoryValidation"},
* minMessage = "Your first name must be at least {{ limit }} characters long",
* maxMessage = "Your first name cannot be longer than {{ limit }} characters"
* )
*/
protected $name;
from sonataclassificationbundle.
It's possible to exclude vendor's validation in a compiler pass. Then you can just copy validation.xml to your inherited bundle and maintain it there.
Here's a quick implementation (not tested):
$validatorBuilder = $container->getDefinition('validator.builder');
foreach ($validatorBuilder->getMethodCalls('addXmlMappings') as $call) {
if ('addXmlMappings' == $call[0]) {
$validatorBuilder->removeMethodCall($call[0]);
$arguments = array();
foreach ($call[1][0] as $path) {
if (false !== strpos($path, 'sonata-project/classification-bundle/Resources/config/validation.xml')) {
continue;
}
$arguments[]= $path;
}
$validatorBuilder->addMethodCall($call[0], array($arguments));
break;
}
}
from sonataclassificationbundle.
Please try to clear all the cache and try again.
from sonataclassificationbundle.
Thanks for answer
I already tried many times clearing cache (rm -rf app/cache/*), right now again...
from sonataclassificationbundle.
I'm having this exact same issue. it doesn't work with moving the validation.xml file to your own bundle's config, nor does it work by overriding the validate method as stated in the document, my overridden method in my own admin class looks like this:
$errorElement
->with('name')
->assertLength(array('max' => 50))
->end()
;
so now if i submit a text > 32, i get the error that says the value is too long, it should be 32 characters or less. and when it's over 50... i get BOTH ERRORS about 32 chars and 50.
What am i not doing right here?
from sonataclassificationbundle.
Ping @rande
from sonataclassificationbundle.
Have you found any solution ?
from sonataclassificationbundle.
No, unfortunately.
from sonataclassificationbundle.
Hello guys. Have anybody found a way to remove property validation from already defined class? Im solving the same issue as @kozmenkoav - moving Category->name into Translatable...
from sonataclassificationbundle.
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
from sonataclassificationbundle.
Related Issues (20)
- Context is required when creating a tag, but this isn't enforced at database level HOT 4
- Slugify 3.0 HOT 1
- Associations inconsistency for tag, collection and category towards context HOT 3
- Error: Method treeAction does not exist HOT 7
- sonata-project/classification-bundle 4.x-dev requires sonata-project/admin-bundle ^3.31 HOT 1
- duplicated Entity HOT 22
- Unable to load the twig extension
- Remove id from model classes HOT 3
- Problem with ClassificationBundle [category] on PROD env. HOT 1
- Empty context causes infinite loop
- Context::__toString() must return a string value HOT 1
- Make admin dependency optional
- ManagerRegistry HOT 1
- Cannot override final method HOT 2
- Creating a category is impossible in the fresh installation with category table empty. HOT 7
- Upgrade migration from 4.x to 5.x HOT 2
- [5.x] CategoryAdmin list view does not have edit button because default route is now show HOT 5
- [5.x] Cannot create context with ContextAdmin HOT 5
- [5.x] Admin routes are "ugly" after upgade to SonataAdmin 4 HOT 3
- [5.x] CategoryAdmin Tree view is not working HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sonataclassificationbundle.