deblan.tv/vendor/trinity/src/Trinity/Bundle/ContentManagerBundle/Form/Type/NodeType.php

269 lines
5.8 KiB
PHP
Raw Normal View History

2015-03-02 21:57:49 +01:00
<?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',
2015-05-04 19:34:46 +02:00
'text'
2015-03-02 21:57:49 +01:00
);
$builder->add(
'url',
'text',
array(
'required' => false,
)
);
$builder->add(
'pageContentType',
'choice',
array(
2015-05-04 19:34:46 +02:00
'mapped' => false,
'choices' => $this->getPageContentTypes(),
'required' => true,
2015-03-02 21:57:49 +01:00
)
);
$builder->add(
'externalUrl',
'text',
array(
'required' => false,
'attr' => array(
2015-05-04 19:34:46 +02:00
'placeholder' => 'https://',
2015-03-02 21:57:49 +01:00
),
)
);
$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(
2015-05-04 19:34:46 +02:00
'class' => 'Trinity\Bundle\ContentManagerBundle\Model\Page',
'query' => \Trinity\Bundle\ContentManagerBundle\Model\PageQuery::getOrphansQuery(),
2015-03-02 21:57:49 +01:00
'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,
2015-05-04 19:34:46 +02:00
'mapped' => false,
'choices' => $this->getPagesModels(),
'required' => true,
2015-03-02 21:57:49 +01:00
)
);
}
/**
* {@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;
}
}