sf 2.6 A2LiX entityTranslation doesn't found - symfony

I just want to make a multilingual application site so I red and saw translatable and other bundle.
I use translatable and a2lix... so I read the doc but when I try to use a2lix, I get this error message :
Class c2c\AppBundle\Entity\PeriodTranslation does not exist 500 Internal Server Error - ReflectionException
I set my entityTranslation in a subfolder like so Entity>Translation>MyEntityTranslation
Is there a way to say to a2lix... that it should look inside my sub-folder ?
Thank you for your help.
Entity
namespace c2c\AppBundle\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Translatable;
/**
* Period
*
* #ORM\Table(name="Periods")
* #ORM\Entity(repositoryClass="c2c\AppBundle\Entity\PeriodRepository")
* #Gedmo\TranslationEntity(class="c2c\AppBundle\Entity\Translation\PeriodTranslation")
*/
class Period implements Translatable
...
Entity Translation
namespace c2c\AppBundle\Entity\Translation;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation;
/**
* PeriodTranslation is used fo
*
* #author blucas
*/
/**
* #ORM\Table(name="ext_translations_period", indexes={
* #ORM\Index(name="period_translation_idx", columns={"locale", "object_class", "field", "foreign_key"})
* })
* #ORM\Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
*/
class PeriodTranslation extends AbstractTranslation
{
/**
* All required columns are mapped through inherited superclass
*/
}
Config
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
mappings:
gedmo_translatable:
type: annotation
prefix: Gedmo\Translatable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
alias: GedmoTranslatable
is_bundle: false
...
# Soft Doctrine extendions
stof_doctrine_extensions:
default_locale: en_US
# Only used if you activated the Uploadable extension
# uploadable:
# Default file path: This is one of the three ways you can configure the path for the Uploadable extension
# default_file_path: %kernel.root_dir%/../web/uploads
# Mime type guesser class: Optional. By default, we provide an adapter for the one present in the HttpFoundation component of Symfony
# mime_type_guesser_class: Stof\DoctrineExtensionsBundle\Uploadable\MimeTypeGuesserAdapter
# Default file info class implementing FileInfoInterface: Optional. By default we provide a class which is prepared to receive an UploadedFile instance.
# default_file_info_class: Stof\DoctrineExtensionsBundle\Uploadable\UploadedFileInfo
orm:
default:
# sluggable: true
translatable: true
...
# Give a way to translate form
a2lix_translation_form:
locale_provider: default
locales: [en,fr,nl]
default_locale: en
required_locales: [en]
manager_registry: doctrine
templating: "A2lixTranslationFormBundle::default.html.twig"

The error is thrown becous the newest version of a2lix is not compatible with the stable version of Gedmo
check this answer https://stackoverflow.com/a/22018321/2160958
If you want to use Gedmo strategy you will have to downgrade your "a2lix/translation-form-bundle" to "1.*#dev" if you want to use the newest version of "a2lix/translation-form-bundle" you will have to use
wip2.4 Gedmo version, with is unstable yet.
check this https://github.com/a2lix/TranslationFormBundle/blob/master/UPGRADE-2.0.md

Related

JMS Serializer Config

I am using this in config.yml:
# JMSSerializer Configuration
jms_serializer:
#parameters:
#jms_serializer.camel_case_naming_strategy.class: JMS\Serializer\Naming\IdenticalPropertyNamingStrategy
metadata:
cache: file
debug: "%kernel.debug%"
file_cache:
dir: "%kernel.cache_dir%/serializer"
auto_detection: true
directories:
AppBundle:
namespace_prefix: "AppBundle"
path: "%kernel.root_dir%/config/serializer/AppBundle"
And this in Entity.Category.yml:
AppBundle\Entity\Category:
exclusion_policy: ALL
But when i try to send request, i receive this error:
Expected metadata for class AppBundle\Entity\Category to be defined
in /var/www/test/app/config/serializer/AppBundle/Entity.Category.yml.
How can I solve this issue?
You forgot about TAB at 2 line.
It looks like you are getting an incorrect path to your project files with %kernel.root_dir%. Make sure that /var/www/test/app is the correct path to your project. Check your PHP __DIR__ constant and try replacing `%kernel.root_dir% with what that says as well as what you think the path should be.
Also, instead of defining your exclusion policy in a config file you should just be able to annotate your entity like so and expose things as needed:
use JMS\Serializer\Annotation as JMS;
/**
* Class ExampleEntity
*
* #JMS\ExclusionPolicy("all")
* #ORM\Entity()
*/
class ExampleEntity
{
}
JMS annotations are found here.

Symfony2: Why is the view annotation in NelmioApiDocBundle not working?

I want to split up my documentation for the api I am building. I am using NelmioApiDocBundle and they have a perfect way with the view annotation. Nelmio view The problem is my method stays in default view and not in the suggested oauth view:
So /doc/api/oauth/ or /api/doc/oauth ends in 404
//config.yml
# app/config/config.yml
nelmio_api_doc: ~
// app/config/routing.yml
NelmioApiDocBundle:
resource: "#NelmioApiDocBundle/Resources/config/routing.yml"
prefix: /api/doc
// routing.yml
profile_rest_oauth:
resource: "#ProfileBundle/Rest/Oauth/RestController.php"
type: rest
prefix: /api/oauth
profile_rest:
resource: "#ProfileBundle/Rest/Xwsse/RestController.php"
type: rest
prefix: /api
//RestController
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Controller\Annotations;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\Request;
class RestController extends FOSRestController
{
/**
* #ApiDoc(
* description="Update profile for user",
* section="profile",
* https=true,
* statusCodes={
* 200="OK, user profile updated",
* 400="Wrong input, no update"
* },
* views = { "oauth" }
* )
*/
public function putProfileAction(Request $request)
{
}
//composer.json
"nelmio/api-doc-bundle": "2.7.0",
To answer my own question: the version "2.7.0" in not compatible with the view parameter you need atleast 2.9.0". It's hard to understand it from the symfony documentation because it show version 2.x symfony documentation
Looks good man. At least i can say if you set up everything right - the /api/doc/oauth should never give you 404.
Try to change both your
resource: "#ProfileBundle/Rest/Xwsse/RestController.php"
to this like
resource: "#ProfileBundle/Resources/config/routing.yml"

Gedmo loggable working but not storing username

I have got logging working on my entity so that when I make a change to a product field with the #Gedmo\Versioned annotation a new version is created. However the only problem is that the username field remains NULL. There is an authenticated user as the update is performed in Sonata Admin backend.
<?php
namespace MyApp\CmsBundle\Entity\Log;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Loggable\Entity\MappedSuperclass\AbstractLogEntry;
use Gedmo\Loggable\Entity\Repository\LogEntryRepository;
/**
* #ORM\Entity(repositoryClass="Gedmo\Loggable\Entity\Repository\LogEntryRepository", readOnly=true)
* #ORM\Table(
* name="log_product",
* indexes={
* #ORM\Index(name="log_class_lookup_idx", columns={"object_class"}),
* #ORM\Index(name="log_date_lookup_idx", columns={"logged_at"}),
* #ORM\Index(name="log_user_lookup_idx", columns={"username"}),
* }
* )
*/
class ProductLog extends AbstractLogEntry
{
}
So it would appear the log_user_lookup_idx isn't working correctly, is there a particular bit of config I require for this?
It appears I was missing a bit of config, adding the following to the main app/config/config.yml file did the trick.
stof_doctrine_extensions:
default_locale: en
orm:
default:
loggable: true
I did originally have this in my bundles' services.yml config:
gedmo.listener.loggable:
class: Gedmo\Loggable\LoggableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ "#annotation_reader" ] ]
This managed to track the entity being modified but not the user, I have since removed this config and the logging remains to work with just the stof_doctrine_extensions config setting.
If you have both in your code base then everything will be logged twice I found.

Configuring the Translatable Doctrine2 extension with Symfony2 using YAML

In a nutshell
I'm writing a Symfony2 / Doctrine2 app and have installed and configured the Translatable extension provided by StofDoctrineExtensionsBundle using YAML, however no additional translation table(s) are generated and the following exception is thrown when attempting to work with entities that have translatable properties:
No mapping file found named '/var/www/my-project/vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity/Translation.orm.yml' for class 'Gedmo\Translatable\Entity\Translation'.
In more detail
I'm trying to get the Translatable extension working in my Symfony2 / Doctrine2 application that is provided by the StofDoctrineExtensionsBundle, however most of the available documentation I can find mainly targets the usage of annotations for configuration, but I'm going with YAML because that's how I have configured everything else.
My configuration
I have added the following to my composer.json file and have ran the composer update command: "stof/doctrine-extensions-bundle": "dev-master" and the bundle is registered in my app/AppKernel.php file.
My app/config/config.yml file has the following configuration:
doctrine:
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
mappings:
gedmo_translatable:
type: yml
prefix: Gedmo\Translatable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
alias: GedmoTranslatable
is_bundle: false
stof_doctrine_extensions:
default_locale: en_GB
translation_fallback: true
orm:
default:
timestampable: true
translatable: true
I have then defined an entity in YAML:
Foo\ContentBundle\Entity\Article:
type: entity
repositoryClass: Foo\ContentBundle\Repository\ArticleRepository
table: article
gedmo:
translation:
locale: locale
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 64
gedmo:
- translatable
content:
type: text
gedmo:
- translatable
# ... #
oneToMany:
# ... #
I have then ran the console command php app/console doctrine:generate:entities FooContentBundle to generate the entity classes, and have manually added the locale property and setter:
class Article
{
/* ... */
private $locale;
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
/* ... */
}
After running php app/console doctrine:schema:update --force, my article table is created along with its associations, but nothing relating to translations (I'm assuming a table is supposed to be created for this...)
Then, when working with an entity that is translatable, I'm getting the exception:
No mapping file found named '/var/www/my-project/vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity/Translation.orm.yml' for class 'Gedmo\Translatable\Entity\Translation'.
The YAML file that the exception is referencing does not exist in the path that it's looking for it within, neither could I find it anywhere else.
Does anyone have any ideas as to where I'm going wrong?
Update: After further investigation...
Running php app/console doctrine:mapping:info displays all of my entities and nothing relating to translations, however, if I update the gedmo_translatable: part of my app/config/config.yml file and change type: yml to type: annotation then run the command again, I get the following listed:
[OK] Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation
[OK] Gedmo\Translatable\Entity\Translation
[OK] Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation
At which point, I can update my schema, and I have a new ext_translations table. However, nothing is being inserted into it when working with my entities, presumably because it's now expecting configuration by annotation rather than YAML, changing my config back to type: yml starts throwing the exception again, as expected.
After trying things that the documentation suggests will not work, i.e. mixing both annotation and YAML configurations in the same bundle, it would appear I have things working. The whole thing feels like a bug or an incomplete implementation, however I may be doing something incorrectly. Here's what's working...
Setting the following in app/config/config.yml: doctrine.orm.mappings.gedmo_translatable.type: annotation
Setting the translatable configuration in my YAML schema definition as outlined in my original question, as well as as an annotation in my class file:
/* ... */
use Gedmo\Mapping\Annotation as Gedmo;
/* ... */
class Article
{
/* ... */
/**
* #Gedmo\Translatable
* #var string $name
*/
private $name;
/**
* #Gedmo\Locale
*/
private $locale;
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
/* ... */
}
After doing this, the additional table is created and translations are being inserted into it when persisting the entity.

Issues in entities from different bundles using different entity managers

Edit:
I've prepared a tar.gz which once uncompressed and after running ./bin/vendors install fails to load the fixtures through php scripts/createAll.php. In the tar.gz there are 2 bundles using 2 different connections everyone with its own database.
I think Symfony2 fails to manage them properly. If you take a look at scripts/createAll.php will see how symfony fails to load both fixtures, but if you remove a random fixture (it doesn't matter Var_.php or Foo_.php everything runs fine, which seems to me that symfony is failing to manage entities correctly.)
LINK: http://www.2shared.com/file/2u4GhFVX/SymfonyTestCasetar.html
i want to tell Symfony2 to use different entity managers for different Bundle
directories so my config.yml looks like:
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
myVendorURLCoreBundle: ~
myVendormyBundleBundle: ~
myVendormyBundleFooBundle:
prefix: "myVendor\myBundleFooBundle\Entity"
type: annotation
is_bundle: true
dir: "/Entity"
formacions:
connection: formacions
mappings:
myVendormyBundleFooBarBundle:
prefix: "myVendor\myBundleFooBarBundle\View"
type: annotation
is_bundle: false
dir: "%kernel.root_dir%/../src/myVendor/myBundleFooBarBundle/View"
The problem is when using relationships between the entities in the different directories i get the following error caused by vendor/doctrine/lib/Doctrine/ORM/Mapping/MappingException.php at line 142
Class FRJPC\SalleUrlFormacionsBundle\Entity\EspecialitatContingut is
not a valid entity or mapped super class
The probem is that sometimes "\" before the vendor name breaks the namespace. It's really strange.
Here is how i i link entities between each other:
namespace myVendor\myBundleFooBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity( repositoryClass="myVendor\myBundleFooBundle\Repository\ARepository" )
* #ORM\ChangeTrackingPolicy( "DEFERRED_EXPLICIT" )
* #ORM\Table( name="a" )
*/
class A
{
/**
* #ORM\Id
* #ORM\Column( type="integer", length="4" )
* #ORM\GeneratedValue( strategy="AUTO" )
*/
private $id;
/**
* #ORM\ManyToOne( targetEntity="\myVendor\myBundleFooBarBundle\Entity\B", inversedBy="a", cascade={"persist"} )
* #ORM\JoinColumn( name="FooBar", nullable=true, referencedColumnName="FooBar", onDelete="CASCADE" )
*/
private $fooBar;
}
Second entity:
namespace myVendor\myBundleFooBarBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity( repositoryClass="myVendor\myBundleFooBarBundle\Repository\ARepository" )
* #ORM\ChangeTrackingPolicy( "DEFERRED_EXPLICIT" )
* #ORM\Table( name="a" )
*/
class B
{
/**
* #ORM\Id
* #ORM\Column( type="integer", length="4" )
* #ORM\GeneratedValue( strategy="AUTO" )
*/
private $id;
/** #ORM\OneToMany( targetEntity="\myVendor\myBundleFooBundle\Entity\EspecialitatContingut", mappedBy="fooBar" ) */
private $a;
}
Does any one has a clue on how should i link each entity ?
PD: Both entities work like charm when they're in the same bundle and same directory.
All these Foos and Bars combined with an error message with a real name make it a bit difficult to follow and leaves open the possibility that posted code really doesn't match the actual code. The FooBarBundle/View seems to be an unlikely place to store entities.
In any event a given entity manager such as formacions needs to be able to see all the relevant entities including those involved in relations. It looks like you defined A in the foo bundle and B in the bar bundle and they both cross reference each other?
From your config, I don't see how the formacion em can see your A entity and likewise I don't see how the default em can see the B entity. The fully qualified class name in the relation is not enough to share the entity doctrine metadata. Hence the error messages.
I'd would actually be glad to be proven wrong about this. It's a bit frustrating not to be able to do these sorts of things.

Resources