symfony3 & SonataAdmin & Formatter Bundle - 使用格式化程序选项时出错 "target_field" 不存在

symfony3 & SonataAdmin & Formatter Bundle - Error when using formatter options "target_field" do not exist

我正在使用 symfony 3.1.4 并安装 SonataAdminBundle、SonataFormatterBundle。 我在使用 Sonata Formatter Bundle 时遇到问题。

  1. 通过这个 guide 安装 SonataFormatterBundle:

  2. 我有一个实体:BlogSpost 有 3 个字段:

/**
 * @var string
 *
 * @ORM\Column(name="body", type="blob")
 */
private $body;
/**
 * @var string
 *
 */
private $rawBody;
/**
 * @var string
 *
 */
private $bodyFormatter ;
  1. 这是我在博客中的表单映射器Post管理员class
class BlogPostAdmin extends AbstractAdmin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper->add('title', 'text')
            ->add('bodyFormatter', 'sonata_formatter_type', array(
                'source_field'         => 'rawBody',
                'source_field_options' => array('attr' => array('class' => 'span10', 'rows' => 20)),
                'format_field'         => 'bodyFormatter',
                'target_field'         => 'body',
                'event_dispatcher'     => $formMapper->getFormBuilder()->getEventDispatcher()
            ))
            ->add('draft')
            ->add('published_time');
    }
    // ...
  1. 但是我在尝试创建 Post 时收到以下错误消息。

The options "event_dispatcher", "format_field", "source_field", "source_field_options", "target_field" do not exist. Defined options are: "action", "allow_extra_fields", "attr", "auto_initialize", "block_name", "by_reference", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "horizontal_input_wrapper_class", "horizontal_label_class", "horizontal_label_offset_class", "inherit_data", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "label_render", "mapped", "method", "post_max_size_message", "property_path", "required", "sonata_admin", "sonata_field_description", "sonata_help", "translation_domain", "trim", "validation_groups". 500 Internal Server Error - UndefinedOptionsException

我该如何解决这个问题?

symfony 3.1.4 有很多兼容性问题,option resolver is one of them。 我建议尝试 'formatter-bundle 4.x-dev',它已解决其他问题。

另外:

    form:
    resources:
        # ...
        - 'SonataFormatterBundle:Form:formatter.html.twig'

已弃用并且

    form_themes:    
        - 'SonataFormatterBundle:Form:formatter.html.twig'

应该改用。