Symfony2 - MissingTranslationException - symfony

Receiving the following error message when trying to run my project.
Fatal error: Uncaught exception 'Doctrine\ODM\PHPCR\Translation\MissingTranslationException' with message 'The locale 'en' is not present in the list of available locales' in /var/www/sources/piccolo-standard/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php on line 133
Doctrine\ODM\PHPCR\Translation\MissingTranslationException: The locale 'en' is not present in the list of available locales in /var/www/sources/piccolo-standard/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php on line 133
And the following stack trace:
# Time Memory Function Location
1 0.0040 240752 {main}( ) ../app.php:0
2 0.0299 643576 Symfony\Component\HttpKernel\HttpCache\HttpCache->handle( ) ../app.php:20
3 0.0309 657488 Symfony\Component\HttpKernel\HttpCache\HttpCache->lookup( ) ../HttpCache.php:193
4 0.0316 659008 Symfony\Component\HttpKernel\HttpCache\HttpCache->fetch( ) ../HttpCache.php:329
5 0.0317 665184 Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache->forward( ) ../HttpCache.php:429
6 0.4876 9740256 Symfony\Component\HttpKernel\HttpCache\HttpCache->forward( ) ../HttpCache.php:60
7 0.4877 9742120 Symfony\Component\HttpKernel\Kernel->handle( ) ../HttpCache.php:466
8 0.4957 9838264 Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle( ) ../Kernel.php:187
That is all what I am getting as error report.
What could be going wrong?
edit:
Here is a part my config.yml;
framework:
#esi: ~
translator: { fallback: en }
secret: %secret%
router: { resource: "%kernel.root_dir%/config/routing.yml" }
form: true
csrf_protection: true
templating: { engines: ['twig'] } #assets_version: SomeVersionScheme
default_locale: %locale%
session: ~
edit 2:
After configuring config.yml;
Warning: filemtime(): stat failed for /var/www/sources/piccolo-standard/app/config/config.yml in /var/www/sources/piccolo-standard/vendor/symfony/symfony/src/Symfony/Component/Config/Resource/FileResource.php on line 68
Fatal error: Uncaught exception 'Doctrine\ODM\PHPCR\Translation\MissingTranslationException' with message 'The locale 'en' is not present in the list of available locales' in /var/www/sources/piccolo-standard/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php on line 133
Doctrine\ODM\PHPCR\Translation\MissingTranslationException: The locale 'en' is not present in the list of available locales in /var/www/sources/piccolo-standard/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php on line 133
Edit 3: Solution
The problem was a combining of two issues. The first one was the config.yml. Make sure that the 'doctrine_phpcr.odm.locales' section is set as followed (or something a like, considering what languages you support):
locales:
en: [de, fr]
de: [en, fr]
fr: [en, de]
And the second problem was the absence of database connection configured in 'parameters.yml'. Without connection to my database, the server most likely tried to load an English object (perhaps a DateTime) and failed to load.

This is may be stupid, but have you tried to quote your language value ?
like this :
Translator : { fallback : 'en' }
in all of our symfony project we use the locale variable instead of an hard value
Translator : { fallback : "%locale%" }
according to this source code :
https://github.com/doctrine/phpcr-odm/blob/master/lib/Doctrine/ODM/PHPCR/Translation/LocaleChooser/LocaleChooser.php
the language definition should be quoted ( line 37 )
/**
* locale fallback list indexed by source locale
*
* example:
* array(
* 'en' => array('en', 'de', 'fr'),
* 'fr' => array('fr', 'de', 'en'),
* 'de' => array('de', 'fr', 'en'),
* )
*/
protected $localePreference;
hope that will help you
EDIT : Did you correctly setup you php-cr parameters ?
here is an example from symfony.com
doctrine_phpcr:
odm:
# ...
locales:
en: [de, fr]
de: [en, fr]
fr: [en, de]
locale_fallback: hardcoded
http://symfony.com/doc/current/cmf/bundles/phpcr_odm/multilang.html

Related

Symfony : Attribute "Doctrine\ORM\Mapping\Table" must not be repeated

Sorry for my English (gg translation).
I just passed all my entities with attributes instead of annotations.
Everything was working before and now I have this error.
I can't get it up. Do you have an idea ?
Thanks
composer.json :
Symfony 6.1.*
"php": ">=8.0.2",
"doctrine/annotations": "^1.13",
"doctrine/doctrine-bundle": "^2.6",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.12",
doctrine.yaml
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '13'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
#type: annotation
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
dql:
numeric_functions:
acos: DoctrineExtensions\Query\Mysql\Acos
cos: DoctrineExtensions\Query\Mysql\Cos
radians: DoctrineExtensions\Query\Mysql\Radians
sin: DoctrineExtensions\Query\Mysql\Sin
error message : "Attribute "Doctrine\ORM\Mapping\Table" must not be repeated"
I made the modification of the annotations in attributes with rector.
In one of my entities, he transformed me this code:
/**
* #ORM\Entity(repositoryClass=CodePostalRepository::class)
* #Table(name="code_postal_villes",
* uniqueConstraints={#UniqueConstraint(name="ville_code_postal", columns={"code_postal_id", "villes_id"})}
* )
* #Table(name="code_postal",
* indexes={#Index(name="cp_idx",columns={"cp"})},
* uniqueConstraints={#UniqueConstraint(name="cp", columns={"cp"})}
* )
*/
in :
#[Table(name: 'code_postal_villes')]
#[UniqueConstraint(name: 'ville_code_postal', columns: ['code_postal_id', 'villes_id'])]
#[Table(name: 'code_postal')]
#[Index(name: 'cp_idx', columns: ['cp'])]
#[UniqueConstraint(name: 'cp', columns: ['cp'])]
#[ORM\Entity(repositoryClass: CodePostalRepository::class)]
This is what poses the problem.
There cannot be twice the table attribute
It remains to be seen how I solve the problem.
Same for me: I made the modifications with rector
It transformed this code:
* #ORM\Entity(repositoryClass="DropzoneRepository::class")
* #ORM\Table(name="dropzone")
* #ORM\Entity
into:
#[ORM\Table(name: 'dropzone')]
#[ORM\Entity(repositoryClass: DropzoneRepository::class)]
#[ORM\Entity]
The last line must be removed or you get two ORM\Entity annotations:
//#[ORM\Entity]

Empty result for Doctrine using Entity and Repository folder - migration from Symfony 3.4 to 4.4

I'm working in app upgrade from symfony 3.4 to 4.4.
But I'm having an issue with the query selects, I'm not sure why the result is always empty:
return $this
->_em
->createQuery('SELECT u FROM App\Entity\InternalUsers u')
->getResult();
Result: Array ( )
Using with getRepository:
$user = $this
->getDoctrine()
->getRepository(InternalUsers::class)
->validate($this->_getFilterParams(), $this->getParameter('ENCRYPTION_KEY'));
print_r($user);
Result: Array ( )
Validate function is inside InternalUserRepository
<?php
namespace App\Repository;
use CoreBundle\DoctrineExtensions\Paginate\Paginate;
use CoreBundle\Utils\Validate;
use App\Repository\BaseRepository;
use App\Entity\InternalUsers;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
/**
* Internal Users
* Controls DB operations of internal users.
*/
class InternalUserRepository extends ServiceEntityRepository {
/**
*
* #var type
*/
protected $InternalUsers;
public function __construct(ManagerRegistry $registry) {
parent::__construct($registry, InternalUsers::class);
}
/**
* Validate credentias.
*
* #param array $userData User creteria.
* #param string $encryptionKey Entrypt key.
*
* #return type
*/
public function validate(array $userData, string $encryptionKey) {
$criteria = [
'username' => $userData['username'],
'password' => sha1($encryptionKey . $userData['password'])
];
$user = $this->findOneBy($criteria);
var_dump($user); // NULL
if ($user) {
return $user;
}
}
It's using my cli:
$ php bin/console doctrine:query:dql "SELECT cat FROM App\Entity\InternalUsers cat"
array(0) {
}
I've a supposition with the ORM manually adjusted:
orm:
auto_generate_proxy_classes: '%kernel.debug%'
default_entity_manager: default
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
# alias: App
# AppBundle:
# is_bundle: false
# type: annotation
# dir: '%kernel.project_dir%/src/AppBundle/Entity'
# prefix: 'AppBundle\Entity'
# alias: AppBundle
App\Entity\:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/'
prefix: 'App\Entity\'
alias: App\Entity\
But I'm still not getting results, I've almost 2 days working on this issue and there is no answer after investigating and reading the documentations.
It was another try, but there were no results as well.
orm:
auto_generate_proxy_classes: '%kernel.debug%'
default_entity_manager: default
entity_managers:
default:
auto_mapping: true
metadata_cache_driver:
type: 'service'
id: doctrine.cache.memcached
query_cache_driver:
type: 'service'
id: doctrine.cache.memcached
result_cache_driver:
type: 'service'
id: doctrine.cache.memcached
dql:
string_functions:
STRING_AGG: GalleryCore\CoreBundle\DoctrineExtensions\DQL\StringAgg
Here an update!
It looks like related to type of Entity mapping.
After configuring the doctrine.orm.
orm:
auto_generate_proxy_classes: '%kernel.debug%'
#default_entity_manager: default
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
#entity_managers:
#default:
#metadata_cache_driver:
# type: 'service'
# id: doctrine.cache.memcached
#query_cache_driver:
# type: 'service'
# id: doctrine.cache.memcached
#dql:
# string_functions:
# STRING_AGG: GalleryCore\CoreBundle\DoctrineExtensions\DQL\StringAgg
#connection: default
#naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
# alias: App
# AppBundle:
# is_bundle: false
# type: annotation
# dir: '%kernel.project_dir%/src/AppBundle/Entity'
# prefix: 'AppBundle\Entity'
# alias: AppBundle
#App\Entity:
#is_bundle: false
#type: annotation
#dir: '%kernel.project_dir%/src/Entity'
#prefix: 'App\Entity'
#alias: App
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/'
prefix: 'App\Entity'
alias: App
I ran this command:
php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
to generate the entities correctly in my src/Entity folder
output:
$ php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
Importing mapping information from "default" entity manager
> writing src/Entity/Bonsai.trackSites.php
> writing src/Entity/Gallery.adTagTypes.php
> writing src/Entity/Gallery.albumAssets.php
> writing src/Entity/Gallery.appUrls.php
> writing src/Entity/Gallery.adTags.php
> writing src/Entity/Bonsai.trackAssettypes.php
> writing src/Entity/Bonsai.trackViews.php
> writing src/Entity/Bonsai.trackVisitors.php
> writing src/Entity/Gallery.apps.php
> writing src/Entity/Gallery.adGptTags.php
> writing src/Entity/Gallery.appConfigurations.php
> writing src/Entity/Gallery.appFeatures.php
> writing src/Entity/Gallery.appUrlTypes.php
> writing src/Entity/Gallery.assetFlags.php
> writing src/Entity/Gallery.assetTypes.php
> writing src/Entity/Gallery.assetVotes.php
> writing src/Entity/Gallery.assets.php
> writing src/Entity/Gallery.assetsKeywords.php
> writing src/Entity/Gallery.exifValues.php
> writing src/Entity/Gallery.comments.php
> writing src/Entity/Gallery.exifFields.php
> writing src/Entity/Gallery.domains.php
> writing src/Entity/Gallery.countries.php
> writing src/Entity/Gallery.featuredAssetsData.php
> writing src/Entity/Gallery.fieldValues.php
> writing src/Entity/Gallery.jobsQueue.php
> writing src/Entity/Gallery.regions.php
> writing src/Entity/Gallery.indexJobs.php
> writing src/Entity/Gallery.keywords.php
> writing src/Entity/Gallery.externalValues.php
> writing src/Entity/Gallery.releaseDates.php
> writing src/Entity/Gallery.requestTypes.php
> writing src/Entity/Gallery.responseLogs.php
> writing src/Entity/Gallery.userRoles.php
> writing src/Entity/Gallery.trendingConfiguration.php
> writing src/Entity/Gallery.votesConfiguration.php
> writing src/Entity/Bonsai.trackAssets.php
> writing src/Entity/Gallery.internalUsers.php
> writing src/Entity/Gallery.commentFlags.php
> writing src/Entity/Gallery.verticals.php
> writing src/Entity/Gallery.fields.php
> writing src/Entity/Gallery.fieldTypes.php
> writing src/Entity/Gallery.imageTags.php
> writing src/Entity/Gallery.internalCategories.php
> writing src/Entity/Gallery.sitesConnections.php
> writing src/Entity/Gallery.threadAssets.php
> writing src/Entity/Gallery.trendingCriterias.php
> writing src/Entity/Gallery.trendingFormulaDetails.php
> writing src/Entity/Gallery.trendingFormulas.php
> writing src/Entity/Gallery.userSettings.php
> writing src/Entity/Gallery.userVariables.php
> writing src/Entity/AdGptTags.php
after made a couple of adjustments:
$user = $this
->getDoctrine()
->getRepository(InternalUsers::class)
->findOneBy(
$criteria = [
'username' => $this->_getFilterParams()['username'],
'password' => sha1($this->getParameter('ENCRYPTION_KEY') . $this->_getFilterParams()['password'])
]
);
// validate($this->_getFilterParams(), $this->getParameter('ENCRYPTION_KEY'));
var_dump($user->getUsername());
exit;
it's my output:
string(10) "superadmin"

Homestead not loading the page (symfony)

I am working on Mac OSX El Capitan 10.11.2. I am quite new to vagrant and this would be my first project in Symfony. I set up the environment to start my first symfony 4 project. Everything was installed correctly (including VirtualBox, Vagrant). I updated my hosts file, I edited Homestead.yaml and at the end when I wanted to access my domain (symf01.test) in Chrome I get a message that this site can't be reached and a text file is downloaded automatically, containing such information:
<?php
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__).'/config/bootstrap.php';
if ($_SERVER['APP_DEBUG']) { unmask(0000);
Debug::enable();}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false)
{ Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false)
{ Request::setTrustedHosts([$trustedHosts]);}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
This is my Homestead.yaml file:
ip:"192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /Users/username/Homestead/code/simba
to: /home/vagrant/simba
type: "nfs"
sites:
- map: symf01.test
to: /home/vagrant/simba/public
type: symfony
databases:
- homestead
# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp
# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# zray:
# If you've already freely registered Z-Ray, you can place the token here.
# - email: foo#bar.com
# token: foo
# Don't forget to ensure that you have 'zray: "true"' for your site.
This is what I get when I run serve nginx status
For future reference, this helped:
...
sites:
- map: symf01.test
to: /home/vagrant/simba/public
type: symfony
to
...
sites:
- map: symf01.test
to: /home/vagrant/simba/public
type: "symfony4"
Difference is in syntax. Value of type needs to be under quotes.
That type tells Homestead how to modify .htaccess files so that your websites can be properly accessed.

Error running wkhtmltopdf knp snappy bundle

I am using knp snappy bundle in symfony 2 ,when I tried this code below i get the error "The exit status code '127' says something went wrong:
stderr: "sh: 1: /usr/local/bin/wkhtmltopdf: not found
"
stdout: ""
command: /usr/local/bin/wkhtmltopdf --lowquality '/tmp/knp_snappy5730ffc6454157.04526188.html' '/tmp/knp_snappy5730ffc6454549.48294109.pdf'."
public function showtestAction()
{
$html = $this->renderView('CondorsTnMallBundle:SimpleVisitor:test.html.twig');
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
}
The error message is quite clear: /usr/local/bin/wkhtmltopdf does not exist
First of all you need to know where wkhtmltopdf is in your filesystem. Then, you can add to your config.yml file these lines:
knp_snappy:
pdf:
enabled: true
binary: /real/path/to/your/file/wkhtmltopdf
options:
print-media-type: true
This works for me, just rename wkhtmltopdf-amd64 to wkhtmltopdf. Test older versions too.
knp_snappy:
pdf:
enabled: true
binary: /real/path/to/your/file/wkhtmltopdf
options:
print-media-type: true

Warning: Missing argument 1 for FM\ElFinderPHP\Connector\ElFinderConnector::run()

I'm working in a symfony project and I have a problem with browsing server in ckeditor for inserting images.
I'm using "Trsteel/ckeditor-bundle": "~1.8" and "helios-ag/fm-elfinder-bundle": "~4.0". When I try to browse the server to add image I have this error (Unable to connect to backend):
Warning: Missing argument 1 for
FM\ElFinderPHP\Connector\ElFinderConnector::run(), called in
C:\wamp\www\awb\vendor\helios-ag\fm-elfinder-bundle\Loader\ElFinderLoader.php
on line 63 and defined
Here is my config.yml:
trsteel_ckeditor: class: Trsteel\CkeditorBundle\Form\Type\CkeditorType
transformers: [] toolbar: ['document', 'clipboard', 'editing', '/',
'basicstyles', 'paragraph', 'links', '/', 'insert', 'styles', 'tools']
toolbar_groups: document: ['Source','-','Save','-','Templates']
clipboard:
['Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo']
editing: ['Find','Replace','-','SelectAll'] basicstyles:
['Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat']
paragraph:
['NumberedList','BulletedList','-','Outdent','Indent','-','JustifyLeft',
'JustifyCenter','JustifyRight','JustifyBlock'] links:
['Link','Unlink','Anchor'] insert:
['Image','Flash','Table','HorizontalRule'] styles: ['Styles','Format']
tools: ['Maximize', 'ShowBlocks'] ui_color: '#ffffff'
startup_outline_blocks: false width: 100% #Integer or % height: 300
Integer or % language: 'fr'
filebrowser_upload_url:
url: relative-url.php?type=file filebrowser_image_browse_url: route: elfinder route_parameters: instance: default
fm_elfinder: instances: default: locale: %locale% editor: ckeditor
fullscreen: true include_assets: true connector: debug: false roots:
uploads: show_hidden: false driver: LocalFileSystem path: uploads
upload_allow: ['image/png', 'image/jpg', 'image/jpeg'] upload_deny:
['all'] upload_max_size: 6M
Can someone help me please?
You should as suggested in the issues of fe-elfindeer to use the 5.0.5 version of ElFinderBundle who provides the 1st parameter to the ElFinderConnector::run() function.
Maybe you could try to edit your composer.json file as following :
"helios-ag/fm-elfinder-bundle": "~5.0",
"helios-ag/fm-elfinder-php-connector": "~2.3"
and run composer update helios-ag/fm-elfinder-bundle helios-ag/fm-elfinder-php-connector

Resources