gitignore, trinity updates, template and page updated

This commit is contained in:
Simon Vieille 2015-03-09 23:29:12 +01:00
parent 9dba57a7c4
commit 22f5f80f80
23 changed files with 226 additions and 49 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.svn
tags

View File

@ -6,6 +6,11 @@ use Trinity\Bundle\ContentManagerBundle\Model\Page;
class DefaultPage extends Page
{
public function __construct($template = 'TrinityContentManagerBundle::default.html.twig')
{
parent::__construct($template);
}
public function getConfiguration()
{
return $this->configuration

View File

@ -13,7 +13,7 @@
</header>
</article>
<div class="page-content">{{ render_block('content1') }}</div>
<div class="page-content">{{ render_block('content1')|transform_url }}</div>
{% endblock %}
{% import _self as macros %}
@ -22,7 +22,5 @@
{% endmacro %}
{% block aside %}
{{ parent() }}
{% endblock %}

View File

@ -104,7 +104,7 @@ class BaseAdminController extends Controller
$method = $this->getConfiguration()->getSort();
$method = $this->getConfiguration()->getRankable() ? 'orderByRank' : $this->configuration->getSort();
$method = $this->getConfiguration()->getRankable() ? 'orderByRank' : $method;
if (!$method) {
return false;
@ -558,7 +558,12 @@ class BaseAdminController extends Controller
}
$form = $this->getConfiguration()->getFormEdit();
$form = $this->createForm(new $form($this->getConfiguration()->getFormEditOptions()), $object);
if($this->has($form)){
$form = $this->createForm($this->get($form)->getName(), $object, $this->getConfiguration()->getFormEditOptions());
}else {
$form = $this->createForm(new $form($this->getConfiguration()->getFormEditOptions()), $object);
}
if ('POST' === $request->getMethod()) {
if (false !== $processForm = $this->processForm($form, $object, $request)) {
@ -591,8 +596,14 @@ class BaseAdminController extends Controller
{
$model = $this->getConfiguration()->getModel();
$object = new $model();
$form = $this->getConfiguration()->getFormNew();
$form = $this->createForm(new $form($this->getConfiguration()->getFormNewOptions()), $object);
if($this->has($form)){
$form = $this->createForm($this->get($form)->getName(), $object, $this->getConfiguration()->getFormNewOptions());
}else {
$form = $this->createForm(new $form($this->getConfiguration()->getFormNewOptions()), $object);
}
if ('POST' === $request->getMethod()) {
if (false !== $processForm = $this->processForm($form, $object, $request)) {
@ -717,7 +728,7 @@ class BaseAdminController extends Controller
protected function getFormFilter($new = false)
{
$form = $this->getConfiguration()->getFormFilter() ? $this->configuration->getFormFilter() : $this->configuration->getFormNew();
$form = $this->getConfiguration()->getFormFilter() ? $this->getConfiguration()->getFormFilter() : $this->getConfiguration()->getFormNew();
$form = $this->createForm(new $form($this->getConfiguration()->getFormFilterOptions()));

View File

@ -1296,7 +1296,7 @@ li.item p {
margin-top: 0;
}
.tab-content .mce-tinymce.mce-container.mce-panel,
.page-tab-content .mce-tinymce.mce-container.mce-panel,
.embeded-form .mce-tinymce.mce-container.mce-panel {
margin-left: 157px;
}

View File

@ -0,0 +1,24 @@
<?php
namespace Trinity\Bundle\ContentManagerBundle\Block;
use Trinity\Bundle\ContentManagerBundle\Model\Block;
class CheckboxBlock extends Block
{
const DEFAULT_TEMPLATE = 'TrinityContentManagerBundle:Block:block_checkbox.html.twig';
public function getTemplate()
{
if ($this->template === null) {
return $this::DEFAULT_TEMPLATE;
}
return parent::getTemplate();
}
public function getValue()
{
return (bool)parent::getValue();
}
}

View File

@ -39,7 +39,11 @@ EOF
$kernel = $this->getContainer()->get('kernel');
$output->writeln(sprintf('Clearing the cache for the routing <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
$output->writeln(sprintf(
'Clearing the cache for the routing <info>%s</info> environment with debug <info>%s</info>',
$kernel->getEnvironment(),
var_export($kernel->isDebug(), true)
));
$finder = new Finder();
$files = $finder->name('*Url*')->in(sprintf('%s/../', $realCacheDir))->depth('== 1');

View File

@ -12,8 +12,7 @@ class BlockConfiguration
{
$this->setName($name)
->setType($type)
->setOptions($options)
;
->setOptions($options);
}
public function setName($name)

View File

@ -35,6 +35,8 @@ class PageAdminController extends BaseAdminController
protected $navs;
protected $use_nav_name;
public function __construct()
{
$this->menus = MenuPeer::findMenusWithNodes();
@ -81,10 +83,17 @@ class PageAdminController extends BaseAdminController
*/
public function removeAction($object, $token, Request $request)
{
$this->use_nav_name = $this->container->getParameter('trinity_content_manager.index_use_nav_name');
if ($object->getNodeRelatedByNodeId() !== null) {
$event = new LuceneEvent();
$event->setObject($object);
$event->setIndex($object->getNodeRelatedByNodeId()->getNav()->getCulture());
$nav = $object->getNodeRelatedByNodeId()->getNav();
if($this->use_nav_name){
$event->setIndex($nav->getName());
}else {
$event->setIndex($nav->getCulture());
}
$this->get("event_dispatcher")->dispatch(
TrinitySearchEvents::LUCENE_REMOVE_INDEX, $event
@ -305,7 +314,7 @@ class PageAdminController extends BaseAdminController
protected function processForm(&$form, &$object, Request $request)
{
$form->bind($request);
$form->submit($request);
if ($form->isValid()) {
$this->preSave($object);
@ -421,12 +430,19 @@ class PageAdminController extends BaseAdminController
public function postSave($object, $was_new = false)
{
$this->use_nav_name = $this->container->getParameter('trinity_content_manager.index_use_nav_name');
$node = $object->getNodeRelatedByNodeId();
if ($node) {
$event = new LuceneEvent();
$event->setObject($object);
$event->setIndex($node->getNav()->getCulture());
$nav = $node->getNav();
if($this->use_nav_name){
$event->setIndex($nav->getName());
}else {
$event->setIndex($nav->getCulture());
}
$this->get("event_dispatcher")->dispatch(
TrinitySearchEvents::LUCENE_UPDATE_INDEX, $event

View File

@ -23,6 +23,8 @@ class Configuration implements ConfigurationInterface
$rootNode->children()
->scalarNode('decorator_strategy')->isRequired()->end()
->booleanNode('index_use_nav_name')->defaultFalse()->end()
->arrayNode('ignore_route_patterns')
->defaultValue(array(
'(.*)admin(.*)', # ignore admin route, ie route containing 'admin'

View File

@ -33,5 +33,7 @@ class TrinityContentManagerExtension extends Extension
->replaceArgument(1, $config['ignore_route_patterns'])
->replaceArgument(2, $config['ignore_uri_patterns'])
;
$container->setParameter('trinity_content_manager.index_use_nav_name', $config['index_use_nav_name']);
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace Trinity\Bundle\ContentManagerBundle\Form\Type;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class BlockCheckBoxType extends BlockType
{
protected $options = array(
'data_class' => 'Trinity\Bundle\ContentManagerBundle\Block\CheckboxBlock',
);
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'value',
'checkbox',
array(
'required' => false,
)
);
}
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults($this->options);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'checkbox_block';
}
}

View File

@ -10,10 +10,10 @@ class NodeQuery extends BaseNodeQuery
public static function getReferences(Node $node)
{
return self::create()
->where(sprintf('%s <> ?', NodePeer::ID), $node->getId())
->where(sprintf('%s <> 1', NodePeer::TREE_LEFT))
->orderByTreeLeft()
;
->filterById($node->getId(), \Criteria::NOT_EQUAL)
->filterByTreeLeft(1, \Criteria::NOT_EQUAL)
->filterByNavId($node->getNavId())
->orderByTreeLeft();
}
/**

View File

@ -121,8 +121,8 @@ class Page extends BasePage implements SeoPageInterface, IndexableInterface
$block->save();
}
} elseif ($this->getConfiguration()) {
foreach ($this->getConfiguration()->getBlocks() as $block_configuration) {
$this->getBlock($block_configuration->getName())->save($con);
foreach ($this->getConfiguration()->getBlocks() as $blockConfiguration) {
$this->getBlock($blockConfiguration->getName())->save($con);
}
}
@ -137,7 +137,23 @@ class Page extends BasePage implements SeoPageInterface, IndexableInterface
$qBlock = BlockQuery::create()->filterByName($name)->filterByPageId($this->getId())->findOne();
$block = $qBlock ? $qBlock : $this->getNewBlock($name, $this->getId());
if ($qBlock) {
if (!$this->getConfiguration()->getBlock($name)) {
$block = $qBlock;
} else {
$type = $this->getConfiguration()->getBlock($name)->getType();
$form = new $type();
$formModel = $form->getOption('data_class') ? $form->getOption('data_class') : null;
if (null !== $formModel && !$qBlock instanceof $formModel) {
$block = $this->getNewBlock($name, $this->getId());
} else {
$block = $qBlock;
}
}
} else {
$block = $this->getNewBlock($name, $this->getId());
}
if (!$this->hasBlock($block->getName())) {
$this->setBlock($block);
@ -180,11 +196,13 @@ class Page extends BasePage implements SeoPageInterface, IndexableInterface
{
$type = $this->getConfiguration()->getBlock($name)->getType();
$form = new $type();
$form_model = $form->getOption('data_class') ? $form->getOption('data_class') : 'Block';
$form = new $type();
$formModel = $form->getOption('data_class') ? $form->getOption('data_class') : 'Trinity\Bundle\ContentManagerBundle\Model\Block';
$block = new $form_model();
$block->setname($name);
$block = new $formModel();
$block
->setname($name)
->setClassKey($formModel);
if (null !== $pageId) {
$block->setPageId($pageId);
@ -241,7 +259,7 @@ class Page extends BasePage implements SeoPageInterface, IndexableInterface
*/
public function getIndexKey()
{
return 'cms_page_'.$this->getId();
return 'cms_page_' . $this->getId();
}
/**
@ -260,15 +278,15 @@ class Page extends BasePage implements SeoPageInterface, IndexableInterface
}
$document = new Document();
$nav = $this->getNode()->getNav();
$nav = $this->getNode()->getNav();
if ($nav->getCulture() != $locale) {
if ($nav->getCulture() != $locale && $nav->getName() != $locale) {
return null;
}
$document->addField(Field::keyword('pk', 'cms_page_'.$this->getId()));
$document->addField(Field::keyword('pk', 'cms_page_' . $this->getId()));
$document->addField(Field::keyword('model', 'Page'));
$document->addField(Field::keyword('nav', 'nav_'.$nav->getId()));
$document->addField(Field::keyword('nav', 'nav_' . $nav->getId()));
$document->addField($this->generateField('meta_title', $this->getSeoTitle(), 3));
$document->addField($this->generateField('meta_description', $this->getMetaDescription(), 3));
@ -278,8 +296,8 @@ class Page extends BasePage implements SeoPageInterface, IndexableInterface
$blocksConfiguration = $this->getConfiguration()->getBlocks();
foreach ($this->getBlocks() as $block) {
if (array_key_exists($block->getName(), $blocksConfiguration) && $block->getClassKey(
) == 'Trinity\Bundle\ContentManagerBundle\Block\TextBlock'
if (array_key_exists($block->getName(),
$blocksConfiguration) && $block->getClassKey() == 'Trinity\Bundle\ContentManagerBundle\Block\TextBlock'
) {
switch ($block->getName()) {
case 'title':
@ -298,7 +316,7 @@ class Page extends BasePage implements SeoPageInterface, IndexableInterface
$document->addField($this->generateField('excerpt', $block->getValue(), 2));
break;
default:
$content .= $block->getValue().' ';
$content .= $block->getValue() . ' ';
break;
}
}
@ -372,7 +390,7 @@ class Page extends BasePage implements SeoPageInterface, IndexableInterface
public function getMetaWords()
{
if ($class = $this->getDataModel()) {
$model = new $class();
$model = new $class();
$this->addMetaWordsByMap($model->getPeer()->getTableMap());
@ -387,7 +405,7 @@ class Page extends BasePage implements SeoPageInterface, IndexableInterface
public function addMetaWord($word)
{
$word = '%'.trim($word, '%').'%';
$word = '%' . trim($word, '%') . '%';
if (!in_array($word, $this->metaWords)) {
$this->metaWords[] = $word;
@ -406,7 +424,9 @@ class Page extends BasePage implements SeoPageInterface, IndexableInterface
continue;
}
if (array_key_exists('uploadable', $behaviors) && preg_match('`.*' . $column->getName() . '.*`', $behaviors['uploadable']['fields'])) {
if (array_key_exists('uploadable', $behaviors) && preg_match('`.*' . $column->getName() . '.*`',
$behaviors['uploadable']['fields'])
) {
continue;
}

View File

@ -2,6 +2,10 @@
<database name="default" namespace="Trinity\Bundle\ContentManagerBundle\Model" defaultIdMethod="native" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xsd.propelorm.org/1.6/database.xsd">
<table name="cms_nav" phpName="Nav">
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
</vendor>
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />
<column name="name" type="VARCHAR" required="true" size="50" />
<column name="position" type="INTEGER" required="true" />
@ -17,6 +21,10 @@
</table>
<table name="cms_node" phpName="Node">
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
</vendor>
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />
<column name="title" type="VARCHAR" required="true" size="255" />
<column name="status" type="VARCHAR" size="255" />
@ -64,6 +72,10 @@
</table>
<table name="cms_page" phpName="Page">
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
</vendor>
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />
<column name="name" type="VARCHAR" required="true" size="255" />
<column name="template" type="VARCHAR" size="255" />
@ -94,6 +106,10 @@
</table>
<table name="cms_block" phpName="Block">
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
</vendor>
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />
<column name="name" type="VARCHAR" required="true" size="255" />
<column name="value" type="LONGVARCHAR" />
@ -113,6 +129,10 @@
</table>
<table name="cms_menu" phpName="Menu">
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
</vendor>
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />
<column name="name" type="VARCHAR" required="true" size="255" />
<column name="title" type="VARCHAR" required="true" size="255" />
@ -128,5 +148,4 @@
<reference local="nav_id" foreign="id" />
</foreign-key>
</table>
</database>

View File

@ -0,0 +1 @@
{{ block.value ? "1" : "0" }}

View File

@ -142,7 +142,7 @@
</div>
{% endif %}
<div class="tab-content">
<div class="tab-content page-tab-content">
<div class="tab-pane {% if show == 'form_metas' %}active{% endif %}" id="edit_page_metas">
<fieldset>
<div class="control-group well">

View File

@ -15,9 +15,11 @@ class UserCrudConfiguration extends \Trinity\Bundle\AdminBundle\Configuration\Cr
->setRoutePrefix('FOSUserBundleUserAdmin')
->setFormNamespace('Trinity\\Bundle\\UserBundle\\Form\\Type')
->setFormEdit('UserType')
->setFormEdit('trinity.user.form.type', false)
->setFormNew('trinity.user.form.type', false)
->setFormFilter('UserFilterType')
->setFormNew('UserType')
->setRedirectIfOneResult(false)
->setFieldsets(array(
' ' => array(

View File

@ -40,8 +40,8 @@ class UserAdminController extends BaseAdminController
*/
public function newAction(Request $request)
{
$this->configuration->setFormNewOptions(array('roles' => $this->container->getParameter('trinity_user.roles')));
$this->configuration->setFormFilterOptions(array('roles' => $this->container->getParameter('trinity_user.roles')));
$this->getConfiguration()->setFormNewOptions(array('roles' => $this->container->getParameter('trinity_user.roles')));
$this->getConfiguration()->setFormFilterOptions(array('roles' => $this->container->getParameter('trinity_user.roles')));
return parent::newAction($request);
}
@ -53,8 +53,8 @@ class UserAdminController extends BaseAdminController
*/
public function editAction($object, Request $request)
{
$this->configuration->setFormEditOptions(array('roles' => $this->container->getParameter('trinity_user.roles')));
$this->configuration->setFormFilterOptions(array('roles' => $this->container->getParameter('trinity_user.roles')));
$this->getConfiguration()->setFormEditOptions(array('roles' => $this->container->getParameter('trinity_user.roles')));
$this->getConfiguration()->setFormFilterOptions(array('roles' => $this->container->getParameter('trinity_user.roles')));
return parent::editAction($object, $request);
}
@ -147,4 +147,26 @@ class UserAdminController extends BaseAdminController
{
$this->get('fos_user.user_manager')->updateUser($object);
}
/**
* @return mixed
* @throws \LogicException
*/
public function getConfiguration()
{
// DI first
if($this->has('trinity.user.crud.configuration')){
$this->configuration = $this->get('trinity.user.crud.configuration');
}
if (empty($this->configuration)) {
throw new \LogicException('You must specify a crud configuration.');
}
if (null === $this->configuration->getStorageNamespace()) {
$this->configuration->setStorageNamespace(get_class($this));
}
return $this->configuration;
}
}

View File

@ -79,16 +79,20 @@ class UserType extends BaseAbstractType
'validation_groups' => 'Profile',
'data_class' => 'FOS\UserBundle\Propel\User',
'cascade_validation' => true,
'roles' => array()
)
);
parent::setDefaultOptions($resolver);
}
/**
* {@inheritdoc}
* Name must be the same as the service alias for tag form
*/
public function getName()
{
return 'user';
return 'trinity_user_admin_form';
}
public static function getRoles()

View File

@ -11,6 +11,7 @@
<parameter key="trinity.authentication.success_handler.class">Trinity\Bundle\UserBundle\Handler\AuthenticationSuccessHandler</parameter>
<parameter key="trinity.authentication.failure_handler.class">Trinity\Bundle\UserBundle\Handler\AuthenticationFailureHandler</parameter>
<parameter key="trinity.profile.form.class">Trinity\Bundle\UserBundle\Form\Type\MyProfileType</parameter>
<parameter key="trinity.user.form.class">Trinity\Bundle\UserBundle\Form\Type\UserType</parameter>
<parameter key="trinity.user_register.class">Trinity\Bundle\UserBundle\User\UserRegister</parameter>
<parameter key="trinity.user_log.class">Trinity\Bundle\UserBundle\User\UserLog</parameter>
</parameters>
@ -47,5 +48,9 @@
<tag name="form.type" alias="trinity_user_profile" />
<argument>%fos_user.model.user.class%</argument>
</service>
<service id="trinity.user.form.type" class="%trinity.user.form.class%">
<tag name="form.type" alias="trinity_user_admin_form" />
</service>
</services>
</container>

View File

@ -32,8 +32,8 @@ class UploadableBehavior extends \Behavior
protected function generateConfiguration()
{
$this->fields = array_map('trim', explode(',', $this->getParameter('fields')));
$path = array_map('trim', explode(',', $this->getParameter('paths')));
$this->fields = array_map('trim', explode(',', $this->getParameter('fields')));
$path = array_map('trim', explode(',', $this->getParameter('paths')));
if(count($this->fields) != count($path)) {
throw new InvalidArgumentException(sprintf(
@ -63,8 +63,6 @@ class UploadableBehavior extends \Behavior
return isset($this->dirs[$field]) ? $this->dirs[$field] : null;
}
public function modifyTable()
{
$this->generateConfiguration();