269 lines
5.8 KiB
PHP
269 lines
5.8 KiB
PHP
<?php
|
||
|
||
namespace Trinity\Bundle\ContentManagerBundle\Form\Type;
|
||
|
||
use Symfony\Component\Form\AbstractType;
|
||
use Symfony\Component\Form\FormBuilderInterface;
|
||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||
|
||
class NodeType extends AbstractType
|
||
{
|
||
protected $options = array();
|
||
|
||
public function __construct($mergeOptions = null)
|
||
{
|
||
if ($mergeOptions) {
|
||
$this->mergeOptions($mergeOptions);
|
||
}
|
||
}
|
||
|
||
public function setOption($name, $value)
|
||
{
|
||
$this->options[$name] = $value;
|
||
}
|
||
|
||
public function getOption($name)
|
||
{
|
||
return $this->options[$name];
|
||
}
|
||
|
||
public function setOptions($options)
|
||
{
|
||
$this->options = $options;
|
||
}
|
||
|
||
public function getOptions()
|
||
{
|
||
return $this->options;
|
||
}
|
||
|
||
public function mergeOptions($options)
|
||
{
|
||
$this->options = array_merge($this->options, $options);
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||
{
|
||
$builder->add(
|
||
'title',
|
||
'text'
|
||
);
|
||
|
||
$builder->add(
|
||
'url',
|
||
'text',
|
||
array(
|
||
'required' => false,
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'pageContentType',
|
||
'choice',
|
||
array(
|
||
'mapped' => false,
|
||
'choices' => $this->getPageContentTypes(),
|
||
'required' => true,
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'externalUrl',
|
||
'text',
|
||
array(
|
||
'required' => false,
|
||
'attr' => array(
|
||
'placeholder' => 'https://',
|
||
),
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'routeName',
|
||
'text',
|
||
array(
|
||
'required' => false,
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'controller',
|
||
'text',
|
||
array(
|
||
'required' => false,
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'defaultParams',
|
||
'text',
|
||
array(
|
||
'required' => false,
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'requirements',
|
||
'text',
|
||
array(
|
||
'required' => false,
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'httpMethod',
|
||
'choice',
|
||
array(
|
||
'choices' => $this->getHttpMethods(),
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'format',
|
||
'choice',
|
||
array(
|
||
'choices' => $this->getFormats(),
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'page',
|
||
'model',
|
||
array(
|
||
'class' => 'Trinity\Bundle\ContentManagerBundle\Model\Page',
|
||
'query' => \Trinity\Bundle\ContentManagerBundle\Model\PageQuery::getOrphansQuery(),
|
||
'required' => false,
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'nodeAliasId',
|
||
'choice',
|
||
array(
|
||
'choices' => \Trinity\Bundle\ContentManagerBundle\Model\MenuPeer::getMenuWithNodesForType('- - '),
|
||
'required' => false,
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'visible',
|
||
'checkbox',
|
||
array(
|
||
'required' => false,
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'accessible',
|
||
'checkbox',
|
||
array(
|
||
'required' => false,
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'permissions',
|
||
'choice',
|
||
array(
|
||
'choices' => $this->getPermissions(),
|
||
'multiple' => true,
|
||
'expanded' => true,
|
||
'required' => false,
|
||
)
|
||
);
|
||
|
||
$builder->add(
|
||
'pageModel',
|
||
'choice',
|
||
array(
|
||
// 'property_path' => false,
|
||
'mapped' => false,
|
||
'choices' => $this->getPagesModels(),
|
||
'required' => true,
|
||
)
|
||
);
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||
{
|
||
$resolver->setDefaults(array(
|
||
'data_class' => 'Trinity\Bundle\ContentManagerBundle\Model\Node',
|
||
));
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function getName()
|
||
{
|
||
return 'node';
|
||
}
|
||
|
||
public function getFormats()
|
||
{
|
||
return array(
|
||
'html' => 'HTML',
|
||
'json' => 'JSON',
|
||
'xml' => 'XML',
|
||
);
|
||
}
|
||
|
||
public function getHttpMethods()
|
||
{
|
||
return array(
|
||
'[GET, POST]' => 'GET and POST',
|
||
'GET' => 'Only GET',
|
||
'POST' => 'Only POST',
|
||
);
|
||
}
|
||
|
||
public function getPermissions()
|
||
{
|
||
$options = $this->options;
|
||
unset($options['models']);
|
||
|
||
return $options;
|
||
}
|
||
|
||
public static function validatorGetHttpMethods()
|
||
{
|
||
return array('[GET, POST]', 'GET', 'POST');
|
||
}
|
||
|
||
public static function validatorFormats()
|
||
{
|
||
return array('html', 'json', 'xml');
|
||
}
|
||
|
||
public static function getPageContentTypes()
|
||
{
|
||
return array(
|
||
'keeppage' => 'Keep current page',
|
||
'newpage' => 'New page',
|
||
'page' => 'Page',
|
||
'alias' => 'Alias',
|
||
'url' => 'URL',
|
||
'nopage' => 'No page',
|
||
);
|
||
}
|
||
|
||
public function getPagesModels()
|
||
{
|
||
$models = array();
|
||
|
||
if (is_array($this->getOption('models'))) {
|
||
foreach ($this->getOption('models') as $model => $settings) {
|
||
$models[$model] = $settings['title'];
|
||
}
|
||
}
|
||
|
||
return $models;
|
||
}
|
||
}
|