<?php | |||||
namespace Lc\SovBundle\Factory; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
abstract class AbstractFactory | |||||
{ | |||||
protected $em ; | |||||
public function __construct(EntityManagerInterface $em) | |||||
{ | |||||
$this->em = $em ; | |||||
} | |||||
public function create($params = array()) | |||||
{ | |||||
$entityClass = $this->em->getEntityName($this->getEntityClass()); | |||||
if ($entityClass && strlen($entityClass) > 0) { | |||||
$entity = new $entityClass(); | |||||
$this->populate($entity, $params); | |||||
return $entity; | |||||
} | |||||
else { | |||||
throw new \ErrorException('La classe de l\'entité n\'est pas définie.'); | |||||
} | |||||
} | |||||
public function populate($entity, $params = array()) | |||||
{ | |||||
$entityArray = (array)$entity; | |||||
foreach ($entityArray as $name => $value) { | |||||
$nameArray = explode("\x00", $name); | |||||
$name = $nameArray[2]; | |||||
if ($name != 'id' && isset($params[$name])) { | |||||
$setter = 'set' . ucfirst($name); | |||||
if (method_exists($entity, $setter)) { | |||||
$entity->$setter($params[$name]); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} |
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface; | use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait; | use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait; | ||||
use Lc\SovBundle\Form\Common\FileManagerType; | use Lc\SovBundle\Form\Common\FileManagerType; | ||||
use Symfony\Component\Form\Extension\Core\Type\TextType; | |||||
/** | /** | ||||
* @author La clic ! <contact@laclic.fr> | * @author La clic ! <contact@laclic.fr> | ||||
->setProperty($propertyName) | ->setProperty($propertyName) | ||||
->setLabel($label) | ->setLabel($label) | ||||
->setTemplatePath('@LcSov/adminlte/crud/field/image.html.twig') | ->setTemplatePath('@LcSov/adminlte/crud/field/image.html.twig') | ||||
->addWebpackEncoreEntries('adminlte-field-filemanager') | |||||
//->addWebpackEncoreEntries('adminlte-field-filemanager') | |||||
->setFormType(FileManagerType::class) | ->setFormType(FileManagerType::class) | ||||
->setCustomOption('managerDir', 'image') | ->setCustomOption('managerDir', 'image') | ||||
->setCustomOption('type', 'image') | ->setCustomOption('type', 'image') |
{% set managerDir = form.vars.ea_crud_form.ea_field.customOptions.get('managerDir') %} | {% set managerDir = form.vars.ea_crud_form.ea_field.customOptions.get('managerDir') %} | ||||
{% set type = form.vars.ea_crud_form.ea_field.customOptions.get('type') %} | {% set type = form.vars.ea_crud_form.ea_field.customOptions.get('type') %} | ||||
{% else %} | {% else %} | ||||
{% set managerDir = form.parent.vars.ea_crud_form.ea_field.customOptions.get('managerDir') %} | |||||
{% set type = form.parent.vars.ea_crud_form.ea_field.customOptions.get('type') %} | |||||
{% set managerDir = form.vars.attr.type %} | |||||
{% set type = form.vars.attr.type %} | |||||
{% endif %} | {% endif %} | ||||
<div class="lc-filemanager row"> | <div class="lc-filemanager row"> |