@@ -0,0 +1,48 @@ | |||
<?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]); | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -4,8 +4,8 @@ namespace Lc\SovBundle\Field; | |||
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface; | |||
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait; | |||
use Lc\SovBundle\Form\Type\Crud\FileManagerType; | |||
use Symfony\Component\Form\Extension\Core\Type\TextType; | |||
use Lc\SovBundle\Form\Common\FileManagerType; | |||
/** | |||
* @author La clic ! <contact@laclic.fr> | |||
@@ -23,7 +23,7 @@ final class ImageManagerField implements FieldInterface | |||
->setProperty($propertyName) | |||
->setLabel($label) | |||
->setTemplatePath('@LcSov/adminlte/crud/field/image.html.twig') | |||
->addWebpackEncoreEntries('adminlte-field-filemanager') | |||
//->addWebpackEncoreEntries('adminlte-field-filemanager') | |||
->setFormType(FileManagerType::class) | |||
->setCustomOption('managerDir', 'image') | |||
->setCustomOption('type', 'image') |
@@ -151,8 +151,8 @@ | |||
{% set managerDir = form.vars.ea_crud_form.ea_field.customOptions.get('managerDir') %} | |||
{% set type = form.vars.ea_crud_form.ea_field.customOptions.get('type') %} | |||
{% 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 %} | |||
<div class="lc-filemanager row"> |