2015-03-02 21:57:49 +01:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Trinity\Bundle\ContentManagerBundle\Form\Type;
|
|
|
|
|
|
|
|
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
2015-05-04 19:34:46 +02:00
|
|
|
|
use Trinity\Bundle\ContentManagerBundle\Model\PageQuery;
|
2015-03-02 21:57:49 +01:00
|
|
|
|
|
|
|
|
|
class PagePermissionsType extends PageType
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
|
|
|
{
|
|
|
|
|
$builder->add(
|
|
|
|
|
'classKey',
|
|
|
|
|
'choice',
|
|
|
|
|
array(
|
|
|
|
|
'choices' => $this->getPagesModels(),
|
|
|
|
|
'required' => true,
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
|
'template',
|
|
|
|
|
'choice',
|
|
|
|
|
array(
|
|
|
|
|
'choices' => $this->getTemplates($builder->getData()),
|
|
|
|
|
'required' => true,
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$dataModels = $builder->getData()->getConfiguration()->getDataModels();
|
|
|
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
|
'dataModel',
|
|
|
|
|
'choice',
|
|
|
|
|
array(
|
|
|
|
|
'choices' => $dataModels,
|
|
|
|
|
'required' => false,
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
|
'dataModelId',
|
|
|
|
|
'choice',
|
|
|
|
|
array(
|
2015-05-04 19:34:46 +02:00
|
|
|
|
'choices' => PageQuery::getModelForDataModels($dataModels),
|
2015-03-02 21:57:49 +01:00
|
|
|
|
'required' => false,
|
2015-05-04 19:34:46 +02:00
|
|
|
|
// 'attr' => array(
|
|
|
|
|
// 'class' => 'chosen-select',
|
|
|
|
|
// ),
|
2015-03-02 21:57:49 +01:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getTemplates(\Trinity\Bundle\ContentManagerBundle\Model\Page $page = null)
|
|
|
|
|
{
|
|
|
|
|
$templates = array();
|
|
|
|
|
|
|
|
|
|
if (null !== $page) {
|
|
|
|
|
$models = $this->getOption('models');
|
|
|
|
|
|
|
|
|
|
if (isset($models[$page->getClassKey()])) {
|
|
|
|
|
$_templates = $models[$page->getClassKey()]['templates'];
|
|
|
|
|
|
|
|
|
|
foreach ($_templates as $_template) {
|
|
|
|
|
$templates[$_template['template']] = $_template['title'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $templates;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getPagesModels()
|
|
|
|
|
{
|
|
|
|
|
$models = array();
|
|
|
|
|
|
|
|
|
|
foreach ($this->getOption('models') as $model => $settings) {
|
|
|
|
|
$models[$model] = $settings['title'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $models;
|
|
|
|
|
}
|
|
|
|
|
}
|