Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian committed Dec 4, 2014
1 parent 6666e4b commit 0dd64f5
Show file tree
Hide file tree
Showing 26 changed files with 235 additions and 171 deletions.
51 changes: 30 additions & 21 deletions Admin/BlogAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@

use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
use Symfony\Cmf\Bundle\BlogBundle\Form\PostType;
use Symfony\Cmf\Bundle\BlogBundle\Routing\BlogRouteManager;

/**
* Blog Admin
Expand All @@ -30,33 +27,45 @@ class BlogAdmin extends Admin
protected $translationDomain = 'CmfBlogBundle';
protected $blogRoot;

protected function configureFormFields(FormMapper $mapper)
/**
* Constructor
*
* @param string $code
* @param string $class
* @param string $baseControllerName
* @param string $blogRoot
*/
public function __construct($code, $class, $baseControllerName, $blogRoot)
{
$mapper->add('name', 'text');
$mapper->add('parent', 'doctrine_phpcr_odm_tree', array(
'root_node' => $this->blogRoot,
'choice_list' => array(),
'select_root_node' => true)
);
}

protected function configureDatagridFilters(DatagridMapper $dm)
{
$dm->add('name', 'doctrine_phpcr_string');
parent::__construct($code, $class, $baseControllerName);
$this->blogRoot = $blogRoot;
}

protected function configureListFields(ListMapper $dm)
protected function configureFormFields(FormMapper $formMapper)
{
$dm->addIdentifier('name');
$formMapper
->with('dashboard.label_blog')
->add('name', 'text')
->add('parentDocument', 'doctrine_phpcr_odm_tree', array(
'root_node' => $this->blogRoot,
'choice_list' => array(),
'select_root_node' => true,
))
->end()
;
}

public function setBlogRoot($blogRoot)
protected function configureDatagridFilters(DatagridMapper $filterMapper)
{
$this->blogRoot = $blogRoot;
$filterMapper
->add('name', 'doctrine_phpcr_string')
;
}

public function validate(ErrorElement $ee, $obj)
protected function configureListFields(ListMapper $listMapper)
{
$ee->with('name')->assertNotBlank()->end();
$listMapper
->addIdentifier('name')
;
}
}
22 changes: 12 additions & 10 deletions Admin/PostAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
use Symfony\Cmf\Bundle\BlogBundle\Form\PostType;
use Symfony\Cmf\Bundle\BlogBundle\Form\DataTransformer\CsvToArrayTransformer;

/**
Expand All @@ -38,15 +37,18 @@ protected function configureFormFields(FormMapper $mapper)

// $csvToArrayTransformer = new CsvToArrayTransformer;

$mapper->add('title');
$mapper->add('date', 'datetime', array(
'widget' => 'single_text',
));

$mapper->add('body', 'textarea');
$mapper->add('blog', 'phpcr_document', array(
'class' => 'Symfony\Cmf\Bundle\BlogBundle\Document\Blog',
));
$mapper
->with('dashboard.label_post')
->add('title')
->add('date', 'datetime', array(
'widget' => 'single_text',
))
->add('body', 'textarea')
->add('blog', 'phpcr_document', array(
'class' => 'Symfony\Cmf\Bundle\BlogBundle\Document\Blog',
))
->end()
;

//$tags = $mapper->create('tags', 'text')
// ->addModelTransformer($csvToArrayTransformer);
Expand Down
19 changes: 19 additions & 0 deletions CmfBlogBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,27 @@

namespace Symfony\Cmf\Bundle\BlogBundle;

use Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class CmfBlogBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);

if (class_exists('Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass')) {
$container->addCompilerPass(
DoctrinePhpcrMappingsPass::createXmlMappingDriver(
array(
realpath(__DIR__ . '/Resources/config/doctrine-phpcr') => 'Symfony\Cmf\Bundle\BlogBundle\Document',
),
array('cmf_blog.persistence.phpcr.manager_name'),
false,
array('CmfBlogBundle' => 'Symfony\Cmf\Bundle\BlogBundle\Document')
)
);
}
}
}
26 changes: 10 additions & 16 deletions Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

namespace Symfony\Cmf\Bundle\BlogBundle\Controller;

use Doctrine\ODM\PHPCR\DocumentManager;
use Symfony\Cmf\Bundle\BlogBundle\Document\Post;
use Symfony\Cmf\Bundle\BlogBundle\Repository\PostRepository;
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use FOS\RestBundle\View\ViewHandlerInterface;
use FOS\RestBundle\View\View;

Expand All @@ -40,14 +40,14 @@ class BlogController
protected $viewHandler;

/**
* @var DocumentManager
* @var SecurityContextInterface
*/
protected $dm;
protected $securityContext;

/**
* @var SecurityContextInterface
* @var PostRepository
*/
protected $securityContext;
protected $postRepository;

/**
* The permission to check for when doing the publish workflow check.
Expand All @@ -56,17 +56,16 @@ class BlogController
*/
private $publishWorkflowPermission = PublishWorkflowChecker::VIEW_ATTRIBUTE;


public function __construct(
EngineInterface $templating,
ViewHandlerInterface $viewHandler = null,
DocumentManager $dm,
SecurityContextInterface $securityContext
SecurityContextInterface $securityContext,
PostRepository $postRepository
) {
$this->templating = $templating;
$this->viewHandler = $viewHandler;
$this->dm = $dm;
$this->securityContext = $securityContext;
$this->postRepository = $postRepository;
}

/**
Expand All @@ -91,11 +90,6 @@ protected function renderResponse($contentTemplate, $params)
return $this->templating->renderResponse($contentTemplate, $params);
}

protected function getPostRepo()
{
return $this->dm->getRepository('Symfony\Cmf\Bundle\BlogBundle\Document\Post');
}

public function viewPostAction(Post $contentDocument, $contentTemplate = null)
{
$post = $contentDocument;
Expand All @@ -119,7 +113,7 @@ public function listAction(Request $request, $contentDocument, $contentTemplate
$tag = $request->get('tag', null);

// @todo: Pagination
$posts = $this->getPostRepo()->search(array(
$posts = $this->postRepository->search(array(
'tag' => $tag,
'blog_id' => $blog->getId(),
));
Expand Down
12 changes: 3 additions & 9 deletions DependencyInjection/CmfBlogExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function load(array $configs, ContainerBuilder $container)
$config = $this->processConfiguration($configuration, $configs);

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('controllers.xml');
$loader->load('services.xml');
$loader->load('initializer-phpcr.xml');

if ($config['use_sonata_admin']) {
$this->loadSonataAdmin($config, $loader, $container);
Expand All @@ -44,13 +45,6 @@ public function load(array $configs, ContainerBuilder $container)
$this->loadMenuIntegration($config, $loader, $container);
}

$config['class'] = array_merge(array(
'blog_admin' => 'Symfony\Cmf\Bundle\BlogBundle\Admin\BlogAdmin',
'post_admin' => 'Symfony\Cmf\Bundle\BlogBundle\Admin\PostAdmin',
'blog' => 'Symfony\Cmf\Bundle\BlogBundle\Document\Blog',
'post' => 'Symfony\Cmf\Bundle\BlogBundle\Document\Post',
), isset($config['class']) ? $config['class'] : array());

foreach ($config['class'] as $type => $classFqn) {
$container->setParameter(
$param = sprintf('cmf_blog.%s_class', $type),
Expand All @@ -66,7 +60,7 @@ private function loadSonataAdmin($config, XmlFileLoader $loader, ContainerBuilde
return;
}

$loader->load('blog-admin.xml');
$loader->load('admin.xml');
$container->setParameter($this->getAlias() . '.blog_basepath', $config['blog_basepath']);
}

Expand Down
27 changes: 18 additions & 9 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,35 @@ public function getConfigTreeBuilder()
->end()
->scalarNode('blog_basepath')
->isRequired()
->defaultValue('/cms/blog')
->end()
->scalarNode('routing_post_controller')
->scalarNode('routing_post_controller') # unused
->defaultValue('cmf_blog.blog_controller:viewPostAction')
->end()
->scalarNode('routing_post_prefix')
->scalarNode('routing_post_prefix') # unused
->defaultValue('posts')
->end()
->scalarNode('routing_tag_controller')
->scalarNode('routing_tag_controller') # unused
->defaultValue('cmf_blog.blog_controller:listAction')
->end()
->scalarNode('routing_tag_prefix')
->scalarNode('routing_tag_prefix') # unused
->defaultValue('tag')
->end()
->arrayNode('class')
->addDefaultsIfNotSet()
->children()
# defaults defined in CmfBlogExtension
->scalarNode('blog_admin')->end()
->scalarNode('post_admin')->end()
->scalarNode('blog')->end()
->scalarNode('post')->end()
->scalarNode('blog_admin')
->defaultValue('Symfony\Cmf\Bundle\BlogBundle\Admin\BlogAdmin')
->end()
->scalarNode('post_admin')
->defaultValue('Symfony\Cmf\Bundle\BlogBundle\Admin\PostAdmin')
->end()
->scalarNode('blog')
->defaultValue('Symfony\Cmf\Bundle\BlogBundle\Document\Blog')
->end()
->scalarNode('post')
->defaultValue('Symfony\Cmf\Bundle\BlogBundle\Document\Post')
->end()
->end()
->end()
->end()
Expand Down
22 changes: 22 additions & 0 deletions Document/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public function getId()
return $this->id;
}

public function setId($id)
{
$this->id = $id;
}

public function getName()
{
return $this->name;
Expand All @@ -64,16 +69,32 @@ public function setName($name)
$this->name = $name;
}

/**
* @deprecated Use getParentDocument instead
*/
public function getParent()
{
return $this->parent;
}

public function getParentDocument()
{
return $this->parent;
}

/**
* @deprecated Use setParentDocument instead
*/
public function setParent($parent)
{
$this->parent = $parent;
}

public function setParentDocument($parent)
{
$this->parent = $parent;
}

public function getPosts()
{
return $this->posts;
Expand All @@ -82,6 +103,7 @@ public function getPosts()
public function setPosts($posts)
{
$this->posts = array();

foreach ($posts as $post) {
$this->addPost($post);
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Pending features:

## Requirements

* Symfony 2.2.x
* Symfony 2.3+
* [CoreBundle](https://github.com/symfony-cmf/CoreBundle)
* [RoutingAutoBundle](https://github.com/symfony-cmf/RoutingAutoBundle)

Expand Down
Loading

0 comments on commit 0dd64f5

Please sign in to comment.