public function buildForm(FormBuilderInterface $builder, array $options)
{
$app = $this->app;
$builder->add('name', 'text', array('label' => 'ブロック名', 'required' => true, 'constraints' => array(new Assert\NotBlank(), new Assert\Length(array('max' => $app['config']['stext_len'])))))->add('file_name', 'text', array('label' => 'ファイル名', 'required' => true, 'constraints' => array(new Assert\NotBlank(), new Assert\Length(array('max' => $app['config']['stext_len'])), new Assert\Regex(array('pattern' => '/^[0-9a-zA-Z\\/_]+$/')))))->add('block_html', 'textarea', array('label' => 'ブロックデータ', 'mapped' => false, 'required' => false, 'constraints' => array()))->add('DeviceType', 'entity', array('class' => 'Eccube\\Entity\\Master\\DeviceType', 'property' => 'id'))->add('id', 'hidden')->addEventListener(FormEvents::POST_SUBMIT, function ($event) use($app) {
$form = $event->getForm();
$file_name = $form['file_name']->getData();
$DeviceType = $form['DeviceType']->getData();
$block_id = $form['id']->getData();
$qb = $app['orm.em']->createQueryBuilder();
$qb->select('b')->from('Eccube\\Entity\\Block', 'b')->where('b.file_name = :file_name')->setParameter('file_name', $file_name)->andWhere('b.DeviceType = :DeviceType')->setParameter('DeviceType', $DeviceType);
if (isset($block_id)) {
$qb->andWhere('b.id <> :block_id')->setParameter('block_id', $block_id);
}
$Block = $qb->getQuery()->getResult();
if (count($Block) > 0) {
$form['file_name']->addError(new FormError('※ 同じファイル名のデータが存在しています。別のファイル名を入力してください。'));
}
});
}