浏览代码

BaseFactory + adaptation ImageManagerField

feature/ticket
Guillaume 3 年前
父节点
当前提交
1062fd5e28
共有 3 个文件被更改,包括 53 次插入5 次删除
  1. +48
    -0
      Factory/AbstractFactory.php
  2. +3
    -3
      Field/ImageManagerField.php
  3. +2
    -2
      Resources/views/adminlte/crud/form_theme.html.twig

+ 48
- 0
Factory/AbstractFactory.php 查看文件

@@ -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]);
}
}
}
}
}

+ 3
- 3
Field/ImageManagerField.php 查看文件

@@ -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')

+ 2
- 2
Resources/views/adminlte/crud/form_theme.html.twig 查看文件

@@ -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">

正在加载...
取消
保存