Create and save a value object in CommandController - typo3

im trying to create and save a value object in my ImportCommandController.php, but only the entity will be saved.
Let me show some code:
// Create Entity "Fewo"
$fewo = new Fewo();
$fewo->setTitle('MyFewo');
...
// Create Value Object "Period"
$period = new Period();
$period->setTitle('MyTestTitle');
...
$fewo->addPeriod($period);
$this->fewoRepository->add($fewo);
$this->persistenceManager->persistAll();
Now the Fewo is in the database, but the period-table is still empty. I can't find my mistake...
UPDATE:
This is the Period Model:
<?php
namespace TYPO3\Fewo\Domain\Model;
class Period extends \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject {
/**
* Name der Saison
*
* #var \string
*/
protected $name;
/**
* Von
*
* #var \DateTime
*/
protected $begin;
/**
* Bis
*
* #var \DateTime
*/
protected $end;
/**
* rentalcharges
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Fewo\Domain\Model\Rentalcharge>
*/
protected $rentalcharges;
/**
* __construct
*
* #return Period
*/
public function __construct() {
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all ObjectStorage properties.
*
* #return void
*/
protected function initStorageObjects() {
/**
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*/
$this->rentalcharges = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* Returns the name
*
* #return \string $name
*/
public function getName() {
return $this->name;
}
/**
* Sets the name
*
* #param \string $name
* #return void
*/
public function setName($name) {
$this->name = $name;
}
/**
* Returns the begin
*
* #return \DateTime $begin
*/
public function getBegin() {
return $this->begin;
}
/**
* Sets the begin
*
* #param \DateTime $begin
* #return void
*/
public function setBegin($begin) {
$this->begin = $begin;
}
/**
* Returns the end
*
* #return \DateTime $end
*/
public function getEnd() {
return $this->end;
}
/**
* Sets the end
*
* #param \DateTime $end
* #return void
*/
public function setEnd($end) {
$this->end = $end;
}
/**
* Adds a Rentalcharge
*
* #param \TYPO3\Fewo\Domain\Model\Rentalcharge $rentalcharge
* #return void
*/
public function addRentalcharge(\TYPO3\Fewo\Domain\Model\Rentalcharge $rentalcharge) {
$this->rentalcharges->attach($rentalcharge);
}
/**
* Removes a Rentalcharge
*
* #param \TYPO3\Fewo\Domain\Model\Rentalcharge $rentalchargeToRemove The Rentalcharge to be removed
* #return void
*/
public function removeRentalcharge(\TYPO3\Fewo\Domain\Model\Rentalcharge $rentalchargeToRemove) {
$this->rentalcharges->detach($rentalchargeToRemove);
}
/**
* Returns the rentalcharges
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Fewo\Domain\Model\Rentalcharge> $rentalcharges
*/
public function getRentalcharges() {
return $this->rentalcharges;
}
/**
* Sets the rentalcharges
*
* #param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Fewo\Domain\Model\Rentalcharge> $rentalcharges
* #return void
*/
public function setRentalcharges(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $rentalcharges) {
$this->rentalcharges = $rentalcharges;
}
}
UPDATE2:
Tried:
class Period extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {...}
and:
$period = $this->objectManager->get('TYPO3\Fewo\Domain\Model\Period');
with no effect :(

Is Period in FeWo of the right type?
It have to be something like this:
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Fewo\Domain\Model\Fewo>

Related

TYPO3 filereference adding two files

I have TYPO3 7.6.18
this is my code:
$newVideo = new \Istar\Fefiles\Domain\Model\Video();
$videoName = $video['name'];
$videoTmpName = $video['tmp_name'];
$resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
$storage = $resourceFactory->getDefaultStorage();
$folder = $storage->getFolder("user_upload/");
$movedFile = $storage->addFile($videoTmpName, $folder, $videoName);
$newFileReference = $this->objectManager$this->objectManager->get('TYPO3\\CMS\\Extbase\\Domain\\Model\\FileReference');
$newFileReference->setFile($movedFile);
$newVideo->setVideo($newFileReference);
$this->videoRepository->add($newVideo);
$persistenceManager = $this->objectManager->get("TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager");
$persistenceManager->persistAll();
The problem is it added two files to field video file reference. It's very sudenly! And second file is't the same, it's diferent files. I sure, I send one file. Where may be the problem ?
I have model photo, and there is field image
'image' => [
'exclude' => 0,
'label' => 'LLL:EXT:fefiles/Resources/Private/Language/locallang_db.xlf:image',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', [
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
],
'maxitems' => 1,
], $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
],
Anf I see that when I create photo from BE, and upload image - this add second image, which was uploaded on site early. This is very strange! What happens ?
My video model:
<?php
namespace Istar\Fefiles\Domain\Model;
class Video extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* #var bool
*/
public $allow_for_user = true;
/**
* Title
*
* #var string
* #validate NotEmpty
*/
protected $title = '';
/**
* Description
*
* #var string
*/
protected $description = '';
/**
* rulesDescription
*
* #var string
*/
protected $rulesDescription = '';
/**
* User
*
* #var \Fhk\Feusersplus\Domain\Model\User>
*/
protected $user;
/**
* Videocategory
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocategory>
*/
protected $videocategory;
/**
* Videocomment
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocomment>
* #cascade remove
*/
protected $comment;
/**
* Allow
*
* #var int
*/
protected $allow = 0;
/**
* fskcheck
*
* #var int
*/
protected $fskcheck = 0;
/**
* private
*
* #var int
*/
protected $private = 0;
/**
* Video
* #validate NotEmpty
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* #cascade remove
*/
protected $video;
/**
* preview
*
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* #cascade remove
*/
protected $preview = null;
/**
* blurred
*
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* #cascade remove
*/
protected $blurred = null;
/**
* Crdate
*
* #var int
* #validate NotEmpty
*/
protected $crdate = 0;
/**
* Returns the title
*
* #return string $title
*/
public function getTitle()
{
return $this->title;
}
/**
* Sets the title
*
* #param string $title
* #return void
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Returns the description
*
* #return string $description
*/
public function getDescription()
{
return $this->description;
}
/**
* Sets the description
*
* #param string $description
* #return void
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Returns the rulesDescription
*
* #return string $rulesDescription
*/
public function getRulesDescription()
{
return $this->rulesDescription;
}
/**
* Sets the rulesDescription
*
* #param string $rulesDescription
* #return void
*/
public function setRulesDescription($rulesDescription)
{
$this->rulesDescription = $rulesDescription;
}
/**
* Returns the video
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference $video
*/
public function getVideo()
{
return $this->video;
}
/**
* Returns the videocategory
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocategory> $videocategory
*/
public function getVideocategory()
{
return $this->videocategory;
}
/**
* Sets the videocategory
*
* #return void
*/
public function setVideocategory($videocategory)
{
$this->videocategory = $videocategory;
}
/**
* Returns the comment
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocomment> $comment
*/
public function getComment()
{
return $this->comment;
}
/**
* Sets the comment
*
* #return void
*/
public function setComment($comment)
{
$this->comment = $comment;
}
/**
* Adds a comments to the video
*
* #param \Istar\Fefiles\Domain\Model\Videocomment $comment
* #return void
* #api
*/
public function addComment(\Istar\Fefiles\Domain\Model\Videocomment $comment)
{
$this->comment->attach($comment);
}
/**
* Removes a comment from the video
*
* #param \Istar\Fefiles\Domain\Model\Videocomment $comment
* #return void
* #api
*/
public function removeComment(\Istar\Fefiles\Domain\Model\Videocomment $comment)
{
$this->comment->detach($comment);
}
/**
* Returns the user
*
* #return \Fhk\Feusersplus\Domain\Model\User> $user
*/
public function getUser()
{
return $this->user;
}
/**
* Sets the user
*
* #return void
*/
public function setUser($user)
{
$this->user = $user;
}
/**
* Returns the allow
*
* #return int
*/
public function getAllow()
{
return $this->allow;
}
/**
* Sets the video
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $video
* #return void
*/
public function setVideo($video)
{
$this->video = $video;
}
/**
* Returns the preview
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference $preview
*/
public function getPreview()
{
return $this->preview;
}
/**
* Sets the preview
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $preview
*
* #return void
*/
public function setPreview($preview)
{
$this->preview = $preview;
}
/**
* Returns the blurred
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference $blurred
*/
public function getBlurred()
{
return $this->blurred;
}
/**
* Sets the blurred
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $blurred
*
* #return void
*/
public function setBlurred($blurred)
{
$this->blurred = $blurred;
}
/**
* Returns the fskcheck
*
* #return int
*/
public function getFskcheck()
{
return $this->fskcheck;
}
/**
* Sets the fskcheck
*
* #return void
*/
public function setFskcheck($fskcheck)
{
$this->fskcheck = $fskcheck;
}
/**
* Returns the Private
*
* #return int
*/
public function getPrivate()
{
return $this->private;
}
/**
* Sets the private
*
* #return void
*/
public function setPrivate($private)
{
$this->private = $private;
}
/**
* Returns the crdate
* #return int $crdate
*/
public function getCrdate()
{
return $this->crdate;
}
/**
* Sets the crdate
*
* #param int $crdate
* #return void
*/
public function setCrdate($crdate)
{
$this->crdate = $crdate;
}
}
Have a look at the sys_file_reference table before and after you create a new record in the backend. Is there a new record added? And after saving an existing record you don't get the random image/video added?
Solution:
'foreign_match_fields' => array(
'fieldname' => 'image',
'tablenames' => 'tx_fefiles_domain_model_photo',
'table_local' => 'sys_file_reference',
),

Symfony 2 Doctrine ODM returning errors on existing fields

I have a simple symfony 2 setup with Doctrine ORM and a db with some underscore seperated field names (for instance "error_page"). Querying this never gives a result (getTitle does give a result, getErrorPage is always empty) and symfony gives me an error:
Method "error_page" for object "My\CmsBundle\Document\Website" does not exist in MyCmsBundle:Default:dashboard.html.twig at line 5
I can't figure out why... My Document looks like this:
<?php
// src/My/CmsBundle/Document/Website.php
namespace My\CmsBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* #MongoDB\Document(
* collection="websites"
* )
*/
class Website
{
/**
* #MongoDB\Id
*/
protected $id;
/**
* #MongoDB\String
*/
protected $slug;
/**
* #MongoDB\Field(type="string", name="error_page")
*/
protected $error_page = "";
/**
* #MongoDB\String
*/
protected $title;
/**
* #MongoDB\String(name="seo_title")
*/
protected $seo_title;
/**
* #MongoDB\String
*/
protected $seo_description;
/**
* #MongoDB\Collection
*/
protected $url = array();
/**
* Get id
*
* #return id $id
*/
public function getId()
{
return $this->id;
}
/**
* Set slug
*
* #param string $slug
* #return self
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* #return string $slug
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set title
*
* #param string $title
* #return self
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string $title
*/
public function getTitle()
{
return $this->title;
}
/**
* Set errorPage
*
* #param string $errorPage
* #return self
*/
public function setErrorPage($errorPage)
{
$this->error_page = $errorPage;
return $this;
}
/**
* Get errorPage
*
* #return string $errorPage
*/
public function getErrorPage()
{
return $this->error_page;
}
/**
* Set url
*
* #param collection $url
* #return self
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url
*
* #return collection $url
*/
public function getUrl()
{
return $this->url;
}
/**
* Set seoTitle
*
* #param string $seoTitle
* #return self
*/
public function setSeoTitle($seoTitle)
{
$this->seo_title = $seoTitle;
return $this;
}
/**
* Get seoTitle
*
* #return string $seoTitle
*/
public function getSeoTitle()
{
return $this->seo_title;
}
/**
* Set seoDescription
*
* #param string $seoDescription
* #return self
*/
public function setSeoDescription($seoDescription)
{
$this->seo_description = $seoDescription;
return $this;
}
/**
* Get seoDescription
*
* #return string $seoDescription
*/
public function getSeoDescription()
{
return $this->seo_description;
}
}
Document creation via this document works fine by the way. The field name is also set to error_page as expected... I'm at a loss here :S
Actually, Doctrine+Symfony2 assume camel case variable naming. Twig using the getter method names should be obvious, how should it access protected/private variables? It needs a name for something public : the getter. You're probably wondering why "get" is ignored; it is a simplification for designers as they normally shouldnt know about what "getters" are and the difference between methods and variables.
so in your twig file ,change :
{{document.error_page}}
to
{{document.errorPage}}
this would helpful.

Fill my form with the data that I pick up from a table - Symfony2

My problem is this : I have an entity that contains user data , such as:
age
name
surname
address
phone
...
My goal is to make a form where using a query can bring all this data and fill my form with the data , so that the user can modify it if you ever change the cell for example, or changing the direction of his house.
The company and I have made the entity​​ and the form, and consulting the table will do. My problem is how to fill the form fields with the data that I get from the table.
My entity (DatosEntity):
<?php
namespace Proyecto\LavocBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Datos
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Proyecto\LavocBundle\Entity\DatosRepository")
*/
class Datos
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="empresa", type="string", length=50)
*/
private $empresa;
/**
* #var integer
*
* #ORM\Column(name="cuit", type="integer")
*/
private $cuit;
/**
* #var string
*
* #ORM\Column(name="localidad", type="string", length=50)
*/
private $localidad;
/**
* #var string
*
* #ORM\Column(name="calle", type="string", length=40)
*/
private $calle;
/**
* #var integer
*
* #ORM\Column(name="altura", type="integer")
*/
private $altura;
/**
* #var integer
*
* #ORM\Column(name="areaTel", type="integer")
*/
private $areaTel;
/**
* #var integer
*
* #ORM\Column(name="telefono", type="integer")
*/
private $telefono;
/**
* #var integer
*
* #ORM\Column(name="areaCel", type="integer")
*/
private $areaCel;
/**
* #var integer
*
* #ORM\Column(name="celular", type="integer")
*/
private $celular;
/**
* #ORM\OneToOne(targetEntity="User", inversedBy="datos")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $personales;
/**
* #var string
*
* #ORM\Column(name="email", type="string")
*/
private $email;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set empresa
*
* #param string $empresa
* #return Datos
*/
public function setEmpresa($empresa)
{
$this->empresa = $empresa;
return $this;
}
/**
* Get empresa
*
* #return string
*/
public function getEmpresa()
{
return $this->empresa;
}
/**
* Set cuit
*
* #param integer $cuit
* #return Datos
*/
public function setCuit($cuit)
{
$this->cuit = $cuit;
return $this;
}
/**
* Get cuit
*
* #return integer
*/
public function getCuit()
{
return $this->cuit;
}
/**
* Set localidad
*
* #param string $localidad
* #return Datos
*/
public function setLocalidad($localidad)
{
$this->localidad = $localidad;
return $this;
}
/**
* Get localidad
*
* #return string
*/
public function getLocalidad()
{
return $this->localidad;
}
/**
* Set calle
*
* #param string $calle
* #return Datos
*/
public function setCalle($calle)
{
$this->calle = $calle;
return $this;
}
/**
* Get calle
*
* #return string
*/
public function getCalle()
{
return $this->calle;
}
/**
* Set altura
*
* #param integer $altura
* #return Datos
*/
public function setAltura($altura)
{
$this->altura = $altura;
return $this;
}
/**
* Get altura
*
* #return integer
*/
public function getAltura()
{
return $this->altura;
}
/**
* Set telefono
*
* #param integer $telefono
* #return Datos
*/
public function setTelefono($telefono)
{
$this->telefono = $telefono;
return $this;
}
/**
* Get telefono
*
* #return integer
*/
public function getTelefono()
{
return $this->telefono;
}
/**
* Set area
*
* #param integer $area
* #return Datos
*/
public function setAreaTel($areaTel)
{
$this->areaTel = $areaTel;
return $this;
}
/**
* Get area
*
* #return integer
*/
public function getAreaTel()
{
return $this->areaTel;
}
/**
* Set celular
*
* #param integer $celular
* #return Datos
*/
public function setCelular($celular)
{
$this->celular = $celular;
return $this;
}
/**
* Get celular
*
* #return integer
*/
public function getCelular()
{
return $this->celular;
}
/**
* Set areaCel
*
* #param integer $areaCel
* #return Datos
*/
public function setAreaCel($areaCel)
{
$this->areaCel = $areaCel;
return $this;
}
/**
* Get areaCel
*
* #return integer
*/
public function getAreaCel()
{
return $this->areaCel;
}
/**
* Set email
*
* #param integer $email
* #return Datos
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* #return integer
*/
public function getEmail()
{
return $this->email;
}
/**
* Set personales
*
* #param string $personales
* #return Datos
*/
public function setPersonales($personales)
{
$this->personales = $personales;
return $this;
}
/**
* Get personales
*
* #return string
*/
public function getPersonales()
{
return $this->personales;
}
}
My DatosType:
<?php
namespace Proyecto\LavocBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class DatosType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('empresa');
$builder->add('cuit');
$builder->add('localidad');
$builder->add('calle');
$builder->add('altura');
$builder->add('areaTel');
$builder->add('telefono');
$builder->add('areaCel');
$builder->add('celular');
}
public function getName()
{
return 'datos_form';
}
}
The consultation on the controller but did not know how to do it. Now , do not like taking the data I receive and dump them in the form.
Thank you very much and sorry for the trouble
I think what you want to do can be done by following these steps :
Start by collecting your User data in a variable we will call $user
Then, give this $userto be hydrated by your form, like this :
$form = $this->createForm(new UserType(), $user);
Treat your form like you would normaly do. The values found in the entity should be automaticaly filled in your form.
Hope this helps.
Your action could be something like this:
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('LavocBundle:User')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$editForm = $this->createForm(new UserType(), $entity);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
);
}

A2lix TranslationFormBundle - Gedmo Doctrine Extension - Unwanted form fields

I am trying to build forms for translatable entities but i get 4 form fields that i don't want.
It seems these fields are coming from the Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation but i wonder what i need to do with these fields ?
Is it normal that they are appearing in the translation form ?
If someone have usefull examples that would be great.
It's a Symfony2 project.
Doctrine extensions are installed with stof:
https://github.com/stof/StofDoctrineExtensionsBundle/
Aj2lix TranslationFormBundle:
https://github.com/a2lix/TranslationFormBundle
Please find below the following files:
Page.php (this is the main entity)
PageTranslation.php (the translation entity)
Page.php
<?php
namespace Syms\PageBundle\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Page
*
* #Gedmo\Tree(type="nested")
* #ORM\Table(name="syms_page")
* #ORM\Entity(repositoryClass="Syms\PageBundle\Entity\PageRepository")
*/
class Page
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var boolean
*
* #ORM\Column(name="is_active", type="boolean", nullable=false, options={"default":0})
*/
private $isActive;
/**
* #var boolean
*
* #ORM\Column(name="is_homepage", type="boolean", nullable=false, options={"default":0})
*/
private $isHomepage;
/**
* #var \DateTime
*
* #Gedmo\Timestampable(on="create")
* #ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
protected $translations;
/**
* #Gedmo\TreeLeft
* #ORM\Column(name="lft", type="integer")
*/
private $lft;
/**
* #Gedmo\TreeRight
* #ORM\Column(name="rgt", type="integer")
*/
private $rgt;
/**
* #Gedmo\TreeLevel
* #ORM\Column(name="lvl", type="integer")
*/
private $lvl;
/**
* #Gedmo\TreeParent
* #ORM\ManyToOne(targetEntity="Page", inversedBy="children")
* #ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* #Gedmo\TreeRoot
* #ORM\Column(name="root", type="integer", nullable=true)
*/
private $root;
/**
* #ORM\OneToMany(targetEntity="Page", mappedBy="parent")
* #ORM\OrderBy({"lft" = "ASC"})
*/
private $children;
/**
* Required for Translatable behaviour
* #Gedmo\Locale
*/
protected $locale;
/**
* Constructor
*/
public function __construct()
{
$this->children = new ArrayCollection();
$this->translations = new ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set isActive
*
* #param boolean $isActive
* #return Page
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* #return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Set isHomepage
*
* #param boolean $isHomepage
* #return Page
*/
public function setIsHomepage($isHomepage)
{
$this->isHomepage = $isHomepage;
return $this;
}
/**
* Get isHomepage
*
* #return boolean
*/
public function getIsHomepage()
{
return $this->isHomepage;
}
/**
* Set createdAt
*
* #param \DateTime $createdAt
* #return Page
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* #return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
public function setParent(Page $parent)
{
$this->parent = $parent;
}
public function getParent()
{
return $this->parent;
}
/**
* Set lft
*
* #param integer $lft
* #return Page
*/
public function setLft($lft)
{
$this->lft = $lft;
return $this;
}
/**
* Get lft
*
* #return integer
*/
public function getLft()
{
return $this->lft;
}
/**
* Set rgt
*
* #param integer $rgt
* #return Page
*/
public function setRgt($rgt)
{
$this->rgt = $rgt;
return $this;
}
/**
* Get rgt
*
* #return integer
*/
public function getRgt()
{
return $this->rgt;
}
/**
* Set lvl
*
* #param integer $lvl
* #return Page
*/
public function setLvl($lvl)
{
$this->lvl = $lvl;
return $this;
}
/**
* Get lvl
*
* #return integer
*/
public function getLvl()
{
return $this->lvl;
}
/**
* Set root
*
* #param integer $root
* #return Page
*/
public function setRoot($root)
{
$this->root = $root;
return $this;
}
/**
* Get root
*
* #return integer
*/
public function getRoot()
{
return $this->root;
}
/**
* Add children
*
* #param \Syms\PageBundle\Entity\Page $children
* #return Page
*/
public function addChild(Page $children)
{
$this->children[] = $children;
return $this;
}
/**
* Remove children
*
* #param \Syms\PageBundle\Entity\Page $children
*/
public function removeChild(Page $children)
{
$this->children->removeElement($children);
}
/**
* Get children
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getChildren()
{
return $this->children;
}
public function getTranslations()
{
return $this->translations;
}
public function addTranslation(PageTranslation $t)
{
$this->translations->add($t);
$t->setObject($this);
}
public function removeTranslation(PageTranslation $t)
{
$this->translations->removeElement($t);
}
public function setTranslations($translations)
{
$this->translations = $translations;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}
PageTranslation.php
<?php
namespace Syms\PageBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* #ORM\Table(name="ext_translations_page", indexes={
* #ORM\Index(name="page_translation_idx", columns={"locale", "object_class", "field", "foreign_key"})
* })
* #ORM\Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
*/
class PageTranslation extends AbstractTranslation
{
/**
* #var string
*
* #Gedmo\Translatable
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #var string
*
* #Gedmo\Translatable
* #ORM\Column(name="meta_title", type="string", length=255)
*/
private $metaTitle;
/**
* #var string
*
* #Gedmo\Translatable
* #ORM\Column(name="meta_keywords", type="text", nullable=true)
*/
private $metaKeywords;
/**
* #var string
*
* #Gedmo\Translatable
* #ORM\Column(name="meta_description", type="text", nullable=true)
*/
private $metaDescription;
/**
* #var string
*
* #Gedmo\Translatable
* #ORM\Column(name="url_key", type="string", length=255)
*/
private $urlKey;
/**
* Set title
*
* #param string $title
* #return PageTranslation
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set metaTitle
*
* #param string $metaTitle
* #return PageTranslation
*/
public function setMetaTitle($metaTitle)
{
$this->metaTitle = $metaTitle;
return $this;
}
/**
* Get metaTitle
*
* #return string
*/
public function getMetaTitle()
{
return $this->metaTitle;
}
/**
* Set metaKeywords
*
* #param string $metaKeywords
* #return PageTranslation
*/
public function setMetaKeywords($metaKeywords)
{
$this->metaKeywords = $metaKeywords;
return $this;
}
/**
* Get metaKeywords
*
* #return string
*/
public function getMetaKeywords()
{
return $this->metaKeywords;
}
/**
* Set metaDescription
*
* #param string $metaDescription
* #return PageTranslation
*/
public function setMetaDescription($metaDescription)
{
$this->metaDescription = $metaDescription;
return $this;
}
/**
* Get metaDescription
*
* #return string
*/
public function getMetaDescription()
{
return $this->metaDescription;
}
/**
* Set urlKey
*
* #param string $urlKey
* #return PageTranslation
*/
public function setUrlKey($urlKey)
{
$this->urlKey = $urlKey;
return $this;
}
/**
* Get urlKey
*
* #return string
*/
public function getUrlKey()
{
return $this->urlKey;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
}
I've finally succeeded in displaying the correct fields.
You have to downgrade the a2lix form bundle to version 1.4.
In fact, in version 2.0, the field type "a2lix_translations_gedmo" is no more available, which is actually what you need when using Gedmo Translatable.
There's nothing to change on your entity side. Just follow the doc for the config.yml, and use "a2lix_translations_gedmo" in your PageType :
$builder->add('translations', 'a2lix_translations_gedmo', array(
'translatable_class' => "Syms\PageBundle\Entity\Page"
);
I've also red somewhere that you can keep using version 2.0 of a2lix Form Bundle, but in this case you have to use a specific branch of doctrine extensions (wip-v2.4.0).
Regards,

add role in zfcuser form registration

i am using zfcuser, bjyauthorize et roleuserbridge.
i want to add a field in the form registration. I followed this tutorial step :
http://resoftsol.com/adding-custom-fields-to-zfcuser-register-form/
in the module front i have added :
- the directory entity with files user et userinterface:
namespace Front\Entity;
interface UserInterface
{
/**
* Get id.
*
* #return int
*/
public function getId();
/**
* Set id.
*
* #param int $id
* #return UserInterface
*/
public function setId($id);
/**
* Get username.
*
* #return string
*/
public function getUsername();
/**
* Set username.
*
* #param string $username
* #return UserInterface
*/
public function setUsername($username);
/**
* Get email.
*
* #return string
*/
public function getEmail();
/**
* Set email.
*
* #param string $email
* #return UserInterface
*/
public function setEmail($email);
/**
* Get displayName.
*
* #return string
*/
public function getDisplayName();
/**
* Set displayName.
*
* #param string $displayName
* #return UserInterface
*/
public function setDisplayName($displayName);
/**
* Get password.
*
* #return string password
*/
public function getPassword();
/**
* Set password.
*
* #param string $password
* #return UserInterface
*/
public function setPassword($password);
/**
* Get state.
*
* #return int
*/
public function getState();
/**
* Set state.
*
* #param int $state
* #return UserInterface
*/
public function setState($state);
/**
* Get role.
*
* #return string
*/
public function getRole();
/**
* Set role.
*
* #param string $role
* #return UserInterface
*/
public function setRole($role);
}
++++++++++++++++++++
namespace Font\Entity;
class User implements UserInterface
{
/**
* #var int
*/
protected $id;
/**
* #var string
*/
protected $username;
/**
* #var string
*/
protected $email;
/**
* #var string
*/
protected $displayName;
/**
* #var string
*/
protected $password;
/**
* #var int
*/
protected $state;
/**
* #var string
*/
protected $role;
/**
* Get id.
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set id.
*
* #param int $id
* #return UserInterface
*/
public function setId($id)
{
$this->id = (int) $id;
return $this;
}
/**
* Get username.
*
* #return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set username.
*
* #param string $username
* #return UserInterface
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get email.
*
* #return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set email.
*
* #param string $email
* #return UserInterface
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get displayName.
*
* #return string
*/
public function getDisplayName()
{
return $this->displayName;
}
/**
* Set displayName.
*
* #param string $displayName
* #return UserInterface
*/
public function setDisplayName($displayName)
{
$this->displayName = $displayName;
return $this;
}
/**
* Get password.
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set password.
*
* #param string $password
* #return UserInterface
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get state.
*
* #return int
*/
public function getState()
{
return $this->state;
}
/**
* Set state.
*
* #param int $state
* #return UserInterface
*/
public function setState($state)
{
$this->state = $state;
return $this;
}
/**
* Get role.
*
* #return string
*/
public function getRole()
{
return $this->role;
}
/**
* Set role.
*
* #param string $role
* #return UserInterface
*/
public function setRole($role)
{
$this->role = $role;
return $this;
}
}
++++++++++++++++++++++++++
also i have add the mapp directory.
i had the following error :
Catchable fatal error: Argument 1 passed to ZfcUser\Validator\AbstractRecord::setMapper()
must be an instance of ZfcUser\Mapper\UserInterface, instance of Front\Mapper\User given,
called in C:\wamppp\www\projet\vendor\zendframework\zendframework\library\Zend\Validator
\AbstractValidator.php on line 139 and defined in C:\wamppp\www\projet\vendor\zf-commons
\zfc-user\src\ZfcUser\Validator\AbstractRecord.php on line 65
I just had the problem myself and was able to solve it... finally.
Copy the ZfcUser\Validator folder into your module.
Adapt the namespace and change the expected Object type of the method AbstractRecord::setMapper to your user entity / interface, whatever you have there now.
Also, in the code you provided the namespaces arent identical. Yout got "Front" and "Font" there.
Edit: forgot the important part xD
After you have done that you need the following code in the config file (my module is called User):
'zfcuser_register_form' => function ($sm) {
$options = $sm->get('zfcuser_module_options');
$form = new ZfcUser\Form\Register(null, $options);
//$form->setCaptchaElement($sm->get('zfcuser_captcha_element'));
$form->setInputFilter(new ZfcUser\Form\RegisterFilter(
new User\Validator\NoRecordExists(array(
'mapper' => $sm->get('zfcuser_user_mapper'),
'key' => 'email'
)),
new User\Validator\NoRecordExists(array(
'mapper' => $sm->get('zfcuser_user_mapper'),
'key' => 'username'
)),
$options
));
return $form;
},
I hope this helps.
You should not create your own interface(and if you do, your new interface should extend ZfcUser\Entity\UserInterface), instead just make your user entity extend the ZfcUser\Entity\UserInterface.