无法识别 Symfony CMF 媒体包表单类型 - 无法加载类型 "cmf_media_image"

Symfony CMF Media Bundle Form Type not recognised - Could not load type "cmf_media_image"

我一直在关注 CMF 媒体包安装,在经历了所有作曲家冲突之后,我现在无法加载带有图像小部件的简单表单。

给予Could not load type "cmf_media_image"

如果我 运行 php app/console container:debug --tag=form.type 它不会出现在表单类型列表中。

相关代码:

Config.yml

[...]
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
    form:
        resources:
            - 'bootstrap_3_layout.html.twig'
            - 'CmfMediaBundle:Form:fields.html.twig'

cmf_media:
    persistence:
        phpcr:
            enabled:         false

liip_imagine:
    filter_sets:
        # default filter to be used with the image preview
        image_upload_thumbnail:
            data_loader: cmf_media_doctrine_phpcr
            quality: 85
            filters:
                thumbnail: { size: [100, 100], mode: outbound }
doctrine_phpcr:
    session:
        backend:
            type: doctrinedbal
            # connection: default
        workspace: default
        username: admin
        password: admin
    odm:
        auto_mapping: true
        auto_generate_proxy_classes: "%kernel.debug%"

autoload.php

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php');

composer.json

"require": {
    "php": ">=5.3.9",
    "symfony/symfony": "2.7.*",
    "doctrine/dbal": "*",
    "doctrine/doctrine-bundle": "*",
    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "sensio/distribution-bundle": "~4.0",
    "sensio/framework-extra-bundle": "~3.0,>=3.0.2",
    "incenteev/composer-parameter-handler": "~2.0",
    "components/jquery": "^2.1",
    "components/font-awesome": "^4.4",
    "friendsofsymfony/user-bundle": "~2.0@dev",
    "avanzu/admin-theme-bundle": "^1.3",
    "egeloen/ckeditor-bundle": "^3.0",
    "symfony-cmf/media-bundle": "^1.2",
    "doctrine/orm": "^2.5",
    "jackalope/jackalope-doctrine-dbal": "1.2.*",
    "jackalope/jackalope": "1.2.*",
    "liip/imagine-bundle": "^1.3",
    "doctrine/phpcr-bundle": "1.*",
    "doctrine/phpcr-odm": "1.2.*"
},
"require-dev": {
    "sensio/generator-bundle": "~2.3"
},

app/AppKernel.php

public function registerBundles()
    {
        $bundles = array(
            [...]
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
            new Liip\ImagineBundle\LiipImagineBundle(),
            new Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle(),
            new Symfony\Cmf\Bundle\MediaBundle\CmfMediaBundle(),
       );
[...]

php app/console container:debug --tag=form.type

的输出
container] Public services with tag form.type
 Service ID                               alias                          Class name
 doctrine_phpcr.odm.form.type.path        phpcr_odm_path                 Doctrine\Bundle\PHPCRBundle\Form\Type\PathType
 form.type.birthday                       birthday                       Symfony\Component\Form\Extension\Core\Type\BirthdayType
 form.type.button                         button                         Symfony\Component\Form\Extension\Core\Type\ButtonType
 form.type.checkbox                       checkbox                       Symfony\Component\Form\Extension\Core\Type\CheckboxType
 form.type.choice                         choice                         Symfony\Component\Form\Extension\Core\Type\ChoiceType
 form.type.collection                     collection                     Symfony\Component\Form\Extension\Core\Type\CollectionType
 form.type.country                        country                        Symfony\Component\Form\Extension\Core\Type\CountryType
 form.type.currency                       currency                       Symfony\Component\Form\Extension\Core\Type\CurrencyType
 form.type.date                           date                           Symfony\Component\Form\Extension\Core\Type\DateType
 form.type.datetime                       datetime                       Symfony\Component\Form\Extension\Core\Type\DateTimeType
 form.type.email                          email                          Symfony\Component\Form\Extension\Core\Type\EmailType
 form.type.entity                         entity                         Symfony\Bridge\Doctrine\Form\Type\EntityType
 form.type.file                           file                           Symfony\Component\Form\Extension\Core\Type\FileType
 form.type.form                           form                           Symfony\Component\Form\Extension\Core\Type\FormType
 form.type.hidden                         hidden                         Symfony\Component\Form\Extension\Core\Type\HiddenType
 form.type.integer                        integer                        Symfony\Component\Form\Extension\Core\Type\IntegerType
 form.type.language                       language                       Symfony\Component\Form\Extension\Core\Type\LanguageType
 form.type.locale                         locale                         Symfony\Component\Form\Extension\Core\Type\LocaleType
 form.type.money                          money                          Symfony\Component\Form\Extension\Core\Type\MoneyType
 form.type.number                         number                         Symfony\Component\Form\Extension\Core\Type\NumberType
 form.type.password                       password                       Symfony\Component\Form\Extension\Core\Type\PasswordType
 form.type.percent                        percent                        Symfony\Component\Form\Extension\Core\Type\PercentType
 form.type.phpcr.document                 phpcr_document                 Doctrine\Bundle\PHPCRBundle\Form\Type\DocumentType
 form.type.phpcr.reference                phpcr_reference                Doctrine\Bundle\PHPCRBundle\Form\Type\PHPCRReferenceType
 form.type.phpcr_odm.reference_collection phpcr_odm_reference_collection Doctrine\Bundle\PHPCRBundle\Form\Type\PHPCRODMReferenceCollectionType
 form.type.radio                          radio                          Symfony\Component\Form\Extension\Core\Type\RadioType
 form.type.repeated                       repeated                       Symfony\Component\Form\Extension\Core\Type\RepeatedType
 form.type.reset                          reset                          Symfony\Component\Form\Extension\Core\Type\ResetType
 form.type.search                         search                         Symfony\Component\Form\Extension\Core\Type\SearchType
 form.type.submit                         submit                         Symfony\Component\Form\Extension\Core\Type\SubmitType
 form.type.text                           text                           Symfony\Component\Form\Extension\Core\Type\TextType
 form.type.textarea                       textarea                       Symfony\Component\Form\Extension\Core\Type\TextareaType
 form.type.time                           time                           Symfony\Component\Form\Extension\Core\Type\TimeType
 form.type.timezone                       timezone                       Symfony\Component\Form\Extension\Core\Type\TimezoneType
 form.type.url                            url                            Symfony\Component\Form\Extension\Core\Type\UrlType
 ivory_ck_editor.form.type                ckeditor                       Ivory\CKEditorBundle\Form\Type\CKEditorType
 liip_imagine.form.type.image             liip_imagine_image             Liip\ImagineBundle\Form\Type\ImageType

我刚刚仔细检查过文件在捆绑包中,它是 vendor/symfony-cmf/media-bundle/Resources/views/Form/fields.html.twig

非常感谢任何帮助。

不幸的是,cmf_media_image(以及其他 CmfMediaBundle 表单类型)仅适用于 phpcr 存储。您的配置禁用了 phpcr 存储。如果您想使用 phpcr,请启用它。否则,您可以看看如何使存储接口与您选择的存储系统一起工作,并将该代码贡献给捆绑包。将不胜感激。

遗憾的是,有关表单类型的文档 http://symfony.com/doc/current/cmf/bundles/media/form_types.html 并未指出这一点。我会在这方面添加注释。