sfアプリケーションの場合、FOSUserBundleのプロファイル編集フォームからパスワードチェックを削除したいと思います。
プロファイルフォームを上書きして「現在の」フィールドを削除するだけでも、「パスワードが無効です」という検証メッセージが表示されます。これは、次のコードによってFOSUSerBundleのProfileFormHandlerクラスが原因で発生します。
 $this->form->setData(new CheckPassword($user));
したがって、フォームハンドラーもオーバーライドし、上記のコードを次のように置き換えました
 $this->form->setData($user);
これまでのところ、これは機能し、フォームタイプが表示され、フォームハンドラーがフォームを処理しますが、次のエラーが発生します
The CSRF token is invalid. Please try to resubmit the form
実際、csrfトークンはフォームに追加されなくなりました。率直に言って、私は何を間違えたのかわかりません;(
thx、ベン
フォーム、ハンドラー、テンプレートの完全なコードは次のとおりです。
<?php
namespace Application\Sonata\UserBundle\Form\Type;
use Symfony\Component\Form\FormBuilder;
class ProfileFormType extends \FOS\UserBundle\Form\Type\ProfileFormType
{
    private $class;
    /**
     * @param string $class The User class name
     */
    public function __construct($class)
    {
        $this->class = $class;
    }
    public function buildForm(FormBuilder $builder, array $options)
    {
       $builder
           ->add('first_name')
            ->add('last_name')
            ->add('phone')
            ->add('location','room13_geo_location')
            ->add('birthday','birthday')
            ->add('smoker')
            ->add('newsletter')
        ;
    }
    public function getName()
    {
        return 'balkanride_user_profile';
    }
    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => $this->class,
            'intention'  => 'profile',
        );
    }
}
-
<?php
namespace Application\Sonata\UserBundle\Form\Handler;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use FOS\UserBundle\Form\Model\CheckPassword;
class ProfileFormHandler
{
    protected $request;
    protected $userManager;
    protected $form;
    public function __construct(Form $form, Request $request, UserManagerInterface $userManager)
    {
        $this->form = $form;
        $this->request = $request;
        $this->userManager = $userManager;
    }
    public function process(UserInterface $user)
    {
        $this->form->setData($user);
        if ('POST' === $this->request->getMethod())
        {
            $this->form->bindRequest($this->request);
            //var_dump($this->form->getErrors());
            //die();
            if ($this->form->isValid())
            {
                $this->onSuccess($user);
                return true;
            }
            // Reloads the user to reset its username. This is needed when the
            // username or password have been changed to avoid issues with the
            // security layer.
            $this->userManager->reloadUser($user);
        }
        return false;
    }
    protected function onSuccess(UserInterface $user)
    {
        $this->userManager->updateUser($user);
    }
}
-
{% extends "ApplicationSonataUserBundle::layout.html.twig" %}
{% block page_body %}
<section>
    <form id="ProfileForm" action="{{ path('fos_user_profile_edit') }}" {{ form_enctype(form) }} method="POST" class="fos_user_profile_edit">
        {{ form_widget(form) }}
        <div>
            <div class="form-actions">
                <input type="submit" value="{{ 'profile.edit.submit'|trans }}" class="btn btn-primary" />
                <a href="{{path('fos_user_profile_show')}}" class="btn">{{ 'profile.edit.cancel'|trans }}</a>
            </div>
        </div>
    </form>
</section>
{% endblock page_body %}