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('url', 'text', array('label' => 'URL', '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('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('tpl_data', 'textarea', array('label' => false, 'mapped' => false, 'required' => true, 'constraints' => array()))->add('author', 'text', array('label' => 'author', 'required' => false, 'constraints' => array(new Assert\Length(array('max' => $app['config']['stext_len'])))))->add('description', 'text', array('label' => 'description', 'required' => false, 'constraints' => array(new Assert\Length(array('max' => $app['config']['stext_len'])))))->add('keyword', 'text', array('label' => 'keyword', 'required' => false, 'constraints' => array(new Assert\Length(array('max' => $app['config']['stext_len'])))))->add('meta_robots', 'text', array('label' => 'robots', 'required' => false, 'constraints' => array(new Assert\Length(array('max' => $app['config']['stext_len'])))))->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();
$url = $form['url']->getData();
$DeviceType = $form['DeviceType']->getData();
$page_id = $form['id']->getData();
$qb = $app['orm.em']->createQueryBuilder();
$qb->select('p')->from('Eccube\\Entity\\PageLayout', 'p')->where('p.url = :url')->setParameter('url', $url)->andWhere('p.DeviceType = :DeviceType')->setParameter('DeviceType', $DeviceType);
if (is_null($page_id)) {
$qb->andWhere('p.id IS NOT NULL');
} else {
$qb->andWhere('p.id <> :page_id')->setParameter('page_id', $page_id);
}
$PageLayout = $qb->getQuery()->getResult();
if (count($PageLayout) > 0) {
$form['url']->addError(new FormError('※ 同じURLのデータが存在しています。別のURLを入力してください。'));
}
});
}