In a Symfony2 project, I created a custom mapping field in order to encrypt strings in the database as suggested in this StackOverflow question. I want to slugify one of the database fields using the Gedmo\Sluggable Doctrine extension. But obviously I get the following error message because the "encrypted_string" is not an allowed type:
[Gedmo\Exception\InvalidMappingException]
Cannot use field - [username] for slug storage, type is not valid and must
be 'string' or 'text' in class - My\PrivateApplication\Bundle\UserBundle
\Entity\User
--EDIT-- This is my Entity:
<?php
namespace My\PrivateApplication\Bundle\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo,
Gedmo\Translatable\Translatable;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Doctrine\Common\Collections\ArrayCollection;
/**
* My\PrivateApplication\Bundle\UserBundle\Entity\User
*
* @ORM\Table(name="user")
* @ORM\Entity(repositoryClass="UserRepository")
*/
class User implements AdvancedUserInterface, \Serializable {
/**
* @var int
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(type="encrypted_string", length=255)
*/
private $surname;
/**
* @var string
*
* @ORM\Column(type="encrypted_string", length=255)
*/
private $name;
/**
* @var string
*
* @ORM\Column(type="encrypted_string", length=255, unique=true)
*/
private $username;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $password;
/**
* @var string
*
* @ORM\Column(type="encrypted_string", length=255)
*/
private $email;
/**
* @var string
*
* @ORM\Column(type="string", length=255, unique=true)
* @Gedmo\Slug(fields={"username"})
*/
private $slug;
/**
* @var string
*
* @ORM\Column(name="salt", type="string", length=40)
*/
private $salt;
/**
* Whether the account is active or not
*
* @var boolean
*
* @ORM\Column(name="is_active", type="boolean")
*/
private $isActive;
/**
* Whether the account is locked or not
*
* @var boolean
*
* @ORM\Column(name="is_locked", type="boolean")
*/
private $isLocked;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime", nullable=true)
* @Gedmo\Timestampable(on="create")
*
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @var string
*
* @Gedmo\Locale
*/
private $locale;
/**
* Set the locale for the translatable behavior
*
* @param string $locale
*/
public function setTranslatableLocale($locale) {
$this->locale = $locale;
}
public function eraseCredentials()
{
}
public function getPassword()
{
return $this->password;
}
public function getRoles()
{
return array((string)$this->getRole());
}
public function getSalt()
{
return $this->salt;
}
public function getUsername()
{
return $this->username;
}
public function isAccountNonExpired()
{
return true;
}
public function isAccountNonLocked()
{
return ($this->isLocked()==0)? false : true;
}
public function isCredentialsNonExpired()
{
return true;
}
public function isEnabled()
{
return ($this->isActive==0) ? false : true;
}
/**
* Serialize the User object
* @see Serializable::serialize()
*/
public function serialize()
{
return serialize(array($this->id, $this->username, $this->password, $this->salt));
}
/**
* Unserialize the User object
* @see Serializable::unserialize()
*/
public function unserialize($serialized)
{
list($this->id, $this->username, $this->password, $this->salt) = unserialize($serialized);
}
//other accessor methods
}
The property $validTypes of the class Gedmo\Sluggable\Mapping\Driver\Annotation seems to define the valid types for the sluggable. How I can modify the SluggableListener to use my new custom type?
Thank you very much.