0

ソナタメディアエンティティにプロパティを追加したいが、それを動作させることができない。私はSonata Media Bundle 2.3を使用しており、マニュアルに従ってインストールしています。私もSonata Easy Extends Bundleでそれを拡張しました。ソナタメディアエンティティにプロパティを追加する/

Application\Sonata\MediaBundle\Entity\Mediaにプロパティを追加すると、doctrine:generate:diff( 'マッピング情報に変更は検出されませんでした。')を実行すると取得されません。

config.ymlのメディアクラスをオーバーライドしても違いはありません。

<?php 

namespace Application\Sonata\MediaBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use Sonata\MediaBundle\Entity\BaseMedia as BaseMedia; 

/** 
* @ORM\Entity 
*/ 
class Media extends BaseMedia 
{ 
    /** 
    * @var integer $id 
    */ 
    protected $id; 

    /** 
    * @ORM\Column(type="string", nullable=true) 
    */ 
    protected $test; 

    /** 
    * @return mixed 
    */ 
    public function getTest() 
    { 
     return $this->test; 
    } 

    /** 
    * @param mixed $test 
    */ 
    public function setTest($test) 
    { 
     $this->test = $test; 
    } 

    /** 
    * Get id 
    * 
    * @return integer $id 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 
} 

そしてconfig.yml中:

これはApplication\Sonata\MediaBundle\Entity\Media.phpのコードである

再び
sonata_media: 
    class: 
     media: Application\Sonata\MediaBundle\Entity\Media 
     gallery: Application\Sonata\MediaBundle\Entity\Gallery 
     gallery_has_media: Application\Sonata\MediaBundle\Entity\GalleryHasMedia 

私はコメントアウトそのセクションを残している場合、私は同じ結果を得ます。

UPDATE:だから

// Application\Sonata\MediaBundle\Admin\MediaAdmin.php 
<?php 
namespace Sonata\MediaBundle\Admin; 

use Sonata\AdminBundle\Admin\Admin; 
use Sonata\AdminBundle\Form\FormMapper; 
use Sonata\AdminBundle\Datagrid\DatagridMapper; 
use Sonata\AdminBundle\Datagrid\ListMapper; 
use Sonata\AdminBundle\Show\ShowMapper; 

class MediaAdmin extends Admin 
{ 
    protected function configureFormFields(FormMapper $formMapper) 
    { 
     $formMapper 
      ->add('name', null, ['required' => false]) 
      ->add('enabled', null, ['required' => false]) 
      ->add('authorName', null, ['required' => false]) 
      ->add('cdnIsFlushable', null, ['required' => false]) 
      ->add('description', null, ['required' => false]) 
      ->add('copyright', null, ['required' => false]) 
      ->add('test', null, ['required' => false]) 
      ->add('binaryContent', 'file', ['required' => false]); 
    } 
} 

:私はプロパティを追加するカスタム移行を作成するときに、私はMediaAdminを拡張するとき、私は、画像編集ページに行くと、testフィールドは表示されませんソナタは拡張メディアバンドルを無視しているようです(そうではありません。なぜなら、私がApplication\Sonata\MediaBundle\Entity\Media.phpを取り除くとエラーが出るからです)。

<?php 

namespace Application\Sonata\MediaBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use Sonata\MediaBundle\Entity\BaseMedia as BaseMedia; 

/** 
* @ORM\Table(name="media__media") 
* @ORM\Entity 
*/ 
class Media extends BaseMedia 

最後に簡単なphp app/console doctrine:schema:update --forceはトリックをした:

答えて

1

まあ、私がApplication/Sonata/MediaBundle/Resources/config/doctrineフォルダを削除し、次のようにメディアエンティティに注釈を付ける必要があったように思えます。これが同じ問題に遭遇した人に役立つことを願っています。

1

イメージのさまざまなプロパティを作成する必要がありました。ここでは、デフォルトのドクトリンとプロバイダを使用した私のソリューションです。私は簡単に使いました。

注釈なしでメディアのプロパティを追加するには、media.phpcr.xmlでのようなものを得るためにノード<field name="url" type="string"/>を使用することができます。

<?xml version="1.0" encoding="utf-8"?> 
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> 
    <!-- 
     This file has been generated by the EasyExtends bundle (https://sonata-project.org/easy-extends) 

     References : 
      xsd     : https://github.com/doctrine/doctrine2/blob/master/doctrine-mapping.xsd 
      xml mapping   : http://www.doctrine-project.org/projects/orm/2.0/docs/reference/xml-mapping/en 
      association mapping : http://www.doctrine-project.org/projects/orm/2.0/docs/reference/association-mapping/en 
    --> 
    <entity 
     name="Application\Sonata\MediaBundle\Entity\Media" 
     table="media__media" 
     > 

     <id name="id" type="integer" column="id"> 
      <generator strategy="AUTO"/> 
     </id> 
     <field name="url" type="string"/> 

    </entity> 
</doctrine-mapping> 

そして、アノテーションを使用せずに、あなたはあなたの拡張Media.phpに追加する必要があります。

<?php 

namespace Application\Sonata\MediaBundle\Entity; 

use Sonata\MediaBundle\Entity\BaseMedia as BaseMedia; 

/** 
* This file has been generated by the Sonata EasyExtends bundle. 
* 
* @link https://sonata-project.org/bundles/easy-extends 
* 
* References : 
* working with object : http://www.doctrine-project.org/projects/orm/2.0/docs/reference/working-with-objects/en 
* 
* @author Christophe Ferreboeuf <[email protected]> 
*/ 
class Media extends BaseMedia 
{ 
    /** 
    * @var int $id 
    */ 
    protected $id; 

    /** 
    * Permits to link the image to a different location on the website 
    * @var string 
    */ 
    protected $url; 

    /** 
    * Get id 
    * 
    * @return int $id 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 

    /** 
    * 
    * @return string 
    */ 
    public function getUrl() { 
     return $this->url; 
    } 

    /** 
    * 
    * @param string $url 
    * @return \Application\Sonata\MediaBundle\Entity\Media 
    */ 
    public function setUrl($url) { 
     $this->url = $url; 
     return $this; 
    } 


} 

そしてORM media.orm.xmlのためにそれを宣言します。

<?xml version="1.0" encoding="utf-8"?> 
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> 
    <!-- 
     This file has been generated by the EasyExtends bundle (https://sonata-project.org/easy-extends) 

     References : 
      xsd     : https://github.com/doctrine/doctrine2/blob/master/doctrine-mapping.xsd 
      xml mapping   : http://www.doctrine-project.org/projects/orm/2.0/docs/reference/xml-mapping/en 
      association mapping : http://www.doctrine-project.org/projects/orm/2.0/docs/reference/association-mapping/en 
    --> 
    <entity 
     name="Application\Sonata\MediaBundle\Entity\Media" 
     table="media__media" 
     > 

     <id name="id" type="integer" column="id"> 
      <generator strategy="AUTO"/> 
     </id> 
     <field name="url" column="url" type="string" nullable="true" length="255"/> 

    </entity> 
</doctrine-mapping> 
(私はYMLを好む)

<?php 
namespace Application\Sonata\MediaBundle\Provider; 

use Sonata\MediaBundle\Provider\ImageProvider as BaseImageProvider; 
use Sonata\AdminBundle\Form\FormMapper; 
use Gaufrette\Filesystem; 
use Imagine\Image\ImagineInterface; 
use Sonata\CoreBundle\Model\Metadata; 
use Sonata\MediaBundle\CDN\CDNInterface; 
use Sonata\MediaBundle\Generator\GeneratorInterface; 
use Sonata\MediaBundle\Metadata\MetadataBuilderInterface; 
use Sonata\MediaBundle\Model\MediaInterface; 
use Sonata\MediaBundle\Thumbnail\ThumbnailInterface; 
use Symfony\Component\HttpFoundation\File\File; 
use Symfony\Component\HttpFoundation\File\UploadedFile; 
use Symfony\Component\Form\Form; 

/** 
* Overrides the default provider to add the url field in the admin form 
* 
* @author christophe Ferreboeuf <[email protected]> 
*/ 
class ImageProvider extends BaseImageProvider{ 

    /** 
    * 
    * @param FormMapper $formMapper 
    */ 
    public function buildCreateForm(FormMapper $formMapper) 
    { 
     $formMapper->add('binaryContent', array(), array('type' => 'string')); 
    } 

    /** 
    * 
    * @param FormMapper $formMapper 
    */ 
    public function buildEditForm(FormMapper $formMapper) 
    { 
     $formMapper->add('name'); 
     $formMapper->add('enabled'); 
     $formMapper->add('authorName'); 
     $formMapper->add('url'); 
     $formMapper->add('cdnIsFlushable'); 
     $formMapper->add('description'); 
     $formMapper->add('copyright'); 
     $formMapper->add(
      'binaryContent', 
      // NEXT_MAJOR: Remove ternary and keep 'Symfony\Component\Form\Extension\Core\Type\FileType' value 
      // (when requirement of Symfony is >= 2.8) 
      method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') 
       ? 'Symfony\Component\Form\Extension\Core\Type\FileType' 
       : 'file', 
      array('required' => false) 
     ); 
    } 
} 

をそして、あなたのサービスでそれを宣言する:

をすることにより、管理の問題を渡すには、画像のためのプロバイダをオーバーライドする必要が

sonata.media.provider.image: 
    class: Application\Sonata\MediaBundle\Provider\ImageProvider 
    arguments: 
     - sonata.media.provider.image 
     - @sonata.media.filesystem.local 
     - @sonata.media.cdn.server 
     - @sonata.media.generator.default 
     - @sonata.media.thumbnail.format 
     - [] 
     - [] 
     - @sonata.media.adapter.image.gd 
     - @sonata.media.metadata.proxy 
    tags: 
     - { name: sonata.media.provider } 
    calls: 
     - [ setTemplates, [ { helper_thumbnail: SonataMediaBundle:Provider:thumbnail.html.twig, helper_view: SonataMediaBundle:Provider:view_image.html.twig } ] ]  
関連する問題