The Cookbook show how to translate assert messages, but how to do the same on #Constraint annotations on a class level? Example which is not working :
use Symfony\Bridge\Doctrine\Validator\Constraints as Constraint;
/**
* #Constraint\UniqueEntity(
* fields={"mobileDomainName"},
* errorPath="mobileDomainName",
* message="site.validation.mobileName.alreadyUsed"
* )
*/
class Site {
Thanks for your answers.
EDIT : translator is activated, all others classical calls worked (including Assert annotations).
In my case I have to enable translator in the config
translator: {
fallbacks: ['%locale%']
}
like Adam Elsodaney said.
Thanks to A.L comment, I read again the documentation (that I already tried to follow). But I misread the translation file name (i.e. validators.language.filetype), whereas I orignally dropped my translations in my custom validation file.
With all constraints validation in good file, all is working.
Thanks for your answers and pointing.
Related
I'm writing a new endpoint for 3rd party desktop application, and there are several different functions in the application that post to the same endpoint on my Symfony 2.8 server.
Sometimes the desktop application goes to the correct path - example.com/path/to/endpoint. However sometimes it tries to go to add an extra slash in between the domain name and the path - example.com//path/to/endpoint.
I tried to just add an extra route with the double slash in it like this:
/**
* #Route("/path/to/route", name="example_route")
* #Route("//path/to/route", name="example_route_double_slash")
* #Method({"POST"})
*/
Symfony just ignores the double slash when it compiles the routes though, and I end up with 2 of "/path/to/route" if I check my routes with app/console debug:router
By default, the Symfony Routing component requires that the parameters
match the following regex path: [^/]+. This means that all characters
are allowed except /.
You must explicitly allow / to be part of your parameter by specifying
a more permissive regex path.
Your route definition have to use regex :
/**
* #Route("/{slash}/path/to/route", name="example_route_double_slash", requirements={"slash"="\/?"})
*/
I haven't tested the code but it basically says that you are adding an extra parameter that may or may not be a /.
The code snippet is inspired from this one at official docs :
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class DemoController
{
/**
* #Route("/hello/{username}", name="_hello", requirements={"username"=".+"})
*/
public function helloAction($username)
{
// ...
}
}
find more here : http://symfony.com/doc/current/routing/slash_in_parameter.html
While trying to understand why my view is not displaying, I noticed the following error in the log:
I do not think it is possible to delete the URL alias from Taxonomy terms. At least I cannot find how to do this.
I have, however gone through ALL of my taxonomy terms and removed the value for this field.
I have also done the following with Pathauto:
Also, I have checked the report located at admin/reports/fields and can confirm that there are no entities that use a field called URL alias.
I have gone through each content item and ensured that they have the following setting (anyone know how to do this in bulk?). But still the error remains.
Anyone know then how I can fix this strange error?
Im not entirely sure what this command does, but it fixed the error:
drush updb --entity-updates
Since https://www.drupal.org/node/2554097, the magic in Drupal core that took care of updating entity definitions is gone. drush updb --entiy-updates is an alternative to this but it is not a silver bullet. Instead, it is safer to write database updates.
Taking the screenshot at the top as an example, here is a database update that would delete those two field definitions:
/**
* Fix taxonomy and node field definitions.
*
*/
function mymodule_update_8101() {
$manager = \Drupal::entityDefinitionUpdateManager();
if ($field = $manager->getFieldStorageDefinition('alias', 'node')) {
$manager->uninstallFieldStorageDefinition($field);
}
if ($field = $manager->getFieldStorageDefinition('alias', 'term')) {
$manager->uninstallFieldStorageDefinition($field);
}
}
Have a look at the rest of the available methods at https://www.drupal.org/node/2554097 in order to write database updates for each scenario.
use the entity_update module or the devel_entity_updates module
I am working with symfony. I have an entity Check. It has a relation field part.
The definition is something like:
/** #ORM\OneToMany(targetEntity="Power\SelfBundle\Entity\Friends", mappedBy="check")*/
protected $part1;
In the inverse relation (at Friendsentity) the declaration is like:
/** #ORM\ManyToOne(targetEntity="Power\SelfBundle\Entity\Check", inversedBy="part1") */
public $check;
Now for removing ambiguity I have deleted the field and replaced it by part. I have updated the schema and cleared the cache and logs.
Later I am inserting into the friends entity (table infact) and it gives an error while event calling the entity:
1/1ReflectionException: Property Power\SelfBundle\Entity\Check::$part1 does not exists
But $part1 is deleted long ago. The cache is cleared and the log is cleared too. I have searched the whole project but nowhere even the text part1 is found.
I am out of my wit!!
Can anyone please help me!!
Thanks.
The problem is fixed after lots of researching.
The problem was in doctrine metadata cache.
In my config.yml file metadata_cache_driver was set to use APC. So clearing the doctrine app/cache was not helpful.
After lots of searching - I have done
php -r "apc_clear_cache(); apc_clear_cache('user'); apc_clear_cache('opcode');"
and BINGO it worked!!
So in my config_dev.yml I have overridden the setting to set the metadata_cache_driver to array.
I've been working with Symfony2 recently, and I've been using annotations for routing, instead of the standard yml or PHP.
I've managed to get my head around most of it, but I'm having trouble using #Method to limit what type of http requests get a response from a controller.
I'm currently using:
/**
* #Route("/contact/", name="_contact")
* #Method({"GET", "POST"})
*/
and getting an error that states Cannot import resource "C:\wamp\www\jimmy\src\Scott\BlogBundle/Controller/" from "C:/wamp/www/jimmy/app/config\routing.yml".
If I remove the #Method line completely the page loads as normal. I've read the documentation on symfony about #Method and they do the same #Method line in their examples, so I'm really not sure where I have gone wrong.
My routing.yml in app/config is:
scott_blog:
resource: "#ScottBlogBundle/Controller/"
type: annotation
prefix: /
Thanks for any help.
You might have forgot to use the namespace Sensio\Bundle\FrameworkExtraBundle\Configuration\Method . If that is the case , add
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
I have installed FPNTagBundle via composer. I have successfully added tags to my articles, but when I add DoctrineExtensions' TagRepository as the repositoryClass with
/**
* #ORM\Entity(repositoryClass="DoctrineExtensions\Taggable\Entity\TagRepository")
* #ORM\Table
*/
class Tag extends FPN\TagBundle\Entity\Tag
and try to use TagRepository's method getResourceIdsForTag('post', 'tagname'), it fails. I've checked the repository class with
$tagRepo = $this->getDoctrine()->getRepository('GergelyPolonkaiFrontBundle:Tag');
echo get_class($tagRepo);
and it's not TagRepository, but Doctrine\ORM\Entity\Repository. I don't have any other error message regarding the repositoryClass thing, even if I specify an invalid classname.
Have I found a bug, or do I miss something somewhere?
It seems I was hitting a bug. After merging some pull requests by Fabien Pennequin 16 days ago, it now seems working as expected.