Skip to content

Commit 0dd64f5

Browse files
author
Brian
committed
cleanups
1 parent 6666e4b commit 0dd64f5

26 files changed

+235
-171
lines changed

Admin/BlogAdmin.php

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414

1515
use Sonata\AdminBundle\Datagrid\ListMapper;
1616
use Sonata\AdminBundle\Datagrid\DatagridMapper;
17-
use Sonata\AdminBundle\Validator\ErrorElement;
1817
use Sonata\AdminBundle\Form\FormMapper;
1918
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
20-
use Symfony\Cmf\Bundle\BlogBundle\Form\PostType;
21-
use Symfony\Cmf\Bundle\BlogBundle\Routing\BlogRouteManager;
2219

2320
/**
2421
* Blog Admin
@@ -30,33 +27,45 @@ class BlogAdmin extends Admin
3027
protected $translationDomain = 'CmfBlogBundle';
3128
protected $blogRoot;
3229

33-
protected function configureFormFields(FormMapper $mapper)
30+
/**
31+
* Constructor
32+
*
33+
* @param string $code
34+
* @param string $class
35+
* @param string $baseControllerName
36+
* @param string $blogRoot
37+
*/
38+
public function __construct($code, $class, $baseControllerName, $blogRoot)
3439
{
35-
$mapper->add('name', 'text');
36-
$mapper->add('parent', 'doctrine_phpcr_odm_tree', array(
37-
'root_node' => $this->blogRoot,
38-
'choice_list' => array(),
39-
'select_root_node' => true)
40-
);
41-
}
42-
43-
protected function configureDatagridFilters(DatagridMapper $dm)
44-
{
45-
$dm->add('name', 'doctrine_phpcr_string');
40+
parent::__construct($code, $class, $baseControllerName);
41+
$this->blogRoot = $blogRoot;
4642
}
4743

48-
protected function configureListFields(ListMapper $dm)
44+
protected function configureFormFields(FormMapper $formMapper)
4945
{
50-
$dm->addIdentifier('name');
46+
$formMapper
47+
->with('dashboard.label_blog')
48+
->add('name', 'text')
49+
->add('parentDocument', 'doctrine_phpcr_odm_tree', array(
50+
'root_node' => $this->blogRoot,
51+
'choice_list' => array(),
52+
'select_root_node' => true,
53+
))
54+
->end()
55+
;
5156
}
5257

53-
public function setBlogRoot($blogRoot)
58+
protected function configureDatagridFilters(DatagridMapper $filterMapper)
5459
{
55-
$this->blogRoot = $blogRoot;
60+
$filterMapper
61+
->add('name', 'doctrine_phpcr_string')
62+
;
5663
}
5764

58-
public function validate(ErrorElement $ee, $obj)
65+
protected function configureListFields(ListMapper $listMapper)
5966
{
60-
$ee->with('name')->assertNotBlank()->end();
67+
$listMapper
68+
->addIdentifier('name')
69+
;
6170
}
6271
}

Admin/PostAdmin.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Sonata\AdminBundle\Validator\ErrorElement;
1818
use Sonata\AdminBundle\Form\FormMapper;
1919
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
20-
use Symfony\Cmf\Bundle\BlogBundle\Form\PostType;
2120
use Symfony\Cmf\Bundle\BlogBundle\Form\DataTransformer\CsvToArrayTransformer;
2221

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

3938
// $csvToArrayTransformer = new CsvToArrayTransformer;
4039

41-
$mapper->add('title');
42-
$mapper->add('date', 'datetime', array(
43-
'widget' => 'single_text',
44-
));
45-
46-
$mapper->add('body', 'textarea');
47-
$mapper->add('blog', 'phpcr_document', array(
48-
'class' => 'Symfony\Cmf\Bundle\BlogBundle\Document\Blog',
49-
));
40+
$mapper
41+
->with('dashboard.label_post')
42+
->add('title')
43+
->add('date', 'datetime', array(
44+
'widget' => 'single_text',
45+
))
46+
->add('body', 'textarea')
47+
->add('blog', 'phpcr_document', array(
48+
'class' => 'Symfony\Cmf\Bundle\BlogBundle\Document\Blog',
49+
))
50+
->end()
51+
;
5052

5153
//$tags = $mapper->create('tags', 'text')
5254
// ->addModelTransformer($csvToArrayTransformer);

CmfBlogBundle.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,27 @@
1212

1313
namespace Symfony\Cmf\Bundle\BlogBundle;
1414

15+
use Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1517
use Symfony\Component\HttpKernel\Bundle\Bundle;
1618

1719
class CmfBlogBundle extends Bundle
1820
{
21+
public function build(ContainerBuilder $container)
22+
{
23+
parent::build($container);
24+
25+
if (class_exists('Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass')) {
26+
$container->addCompilerPass(
27+
DoctrinePhpcrMappingsPass::createXmlMappingDriver(
28+
array(
29+
realpath(__DIR__ . '/Resources/config/doctrine-phpcr') => 'Symfony\Cmf\Bundle\BlogBundle\Document',
30+
),
31+
array('cmf_blog.persistence.phpcr.manager_name'),
32+
false,
33+
array('CmfBlogBundle' => 'Symfony\Cmf\Bundle\BlogBundle\Document')
34+
)
35+
);
36+
}
37+
}
1938
}

Controller/BlogController.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
namespace Symfony\Cmf\Bundle\BlogBundle\Controller;
1414

15-
use Doctrine\ODM\PHPCR\DocumentManager;
1615
use Symfony\Cmf\Bundle\BlogBundle\Document\Post;
16+
use Symfony\Cmf\Bundle\BlogBundle\Repository\PostRepository;
1717
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
1818
use Symfony\Component\HttpFoundation\Request;
1919
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2020
use Symfony\Component\Security\Core\SecurityContextInterface;
21-
use Symfony\Component\Templating\EngineInterface;
21+
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
2222
use FOS\RestBundle\View\ViewHandlerInterface;
2323
use FOS\RestBundle\View\View;
2424

@@ -40,14 +40,14 @@ class BlogController
4040
protected $viewHandler;
4141

4242
/**
43-
* @var DocumentManager
43+
* @var SecurityContextInterface
4444
*/
45-
protected $dm;
45+
protected $securityContext;
4646

4747
/**
48-
* @var SecurityContextInterface
48+
* @var PostRepository
4949
*/
50-
protected $securityContext;
50+
protected $postRepository;
5151

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

59-
6059
public function __construct(
6160
EngineInterface $templating,
6261
ViewHandlerInterface $viewHandler = null,
63-
DocumentManager $dm,
64-
SecurityContextInterface $securityContext
62+
SecurityContextInterface $securityContext,
63+
PostRepository $postRepository
6564
) {
6665
$this->templating = $templating;
6766
$this->viewHandler = $viewHandler;
68-
$this->dm = $dm;
6967
$this->securityContext = $securityContext;
68+
$this->postRepository = $postRepository;
7069
}
7170

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

94-
protected function getPostRepo()
95-
{
96-
return $this->dm->getRepository('Symfony\Cmf\Bundle\BlogBundle\Document\Post');
97-
}
98-
9993
public function viewPostAction(Post $contentDocument, $contentTemplate = null)
10094
{
10195
$post = $contentDocument;
@@ -119,7 +113,7 @@ public function listAction(Request $request, $contentDocument, $contentTemplate
119113
$tag = $request->get('tag', null);
120114

121115
// @todo: Pagination
122-
$posts = $this->getPostRepo()->search(array(
116+
$posts = $this->postRepository->search(array(
123117
'tag' => $tag,
124118
'blog_id' => $blog->getId(),
125119
));

DependencyInjection/CmfBlogExtension.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public function load(array $configs, ContainerBuilder $container)
3535
$config = $this->processConfiguration($configuration, $configs);
3636

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

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

47-
$config['class'] = array_merge(array(
48-
'blog_admin' => 'Symfony\Cmf\Bundle\BlogBundle\Admin\BlogAdmin',
49-
'post_admin' => 'Symfony\Cmf\Bundle\BlogBundle\Admin\PostAdmin',
50-
'blog' => 'Symfony\Cmf\Bundle\BlogBundle\Document\Blog',
51-
'post' => 'Symfony\Cmf\Bundle\BlogBundle\Document\Post',
52-
), isset($config['class']) ? $config['class'] : array());
53-
5448
foreach ($config['class'] as $type => $classFqn) {
5549
$container->setParameter(
5650
$param = sprintf('cmf_blog.%s_class', $type),
@@ -66,7 +60,7 @@ private function loadSonataAdmin($config, XmlFileLoader $loader, ContainerBuilde
6660
return;
6761
}
6862

69-
$loader->load('blog-admin.xml');
63+
$loader->load('admin.xml');
7064
$container->setParameter($this->getAlias() . '.blog_basepath', $config['blog_basepath']);
7165
}
7266

DependencyInjection/Configuration.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,35 @@ public function getConfigTreeBuilder()
5252
->end()
5353
->scalarNode('blog_basepath')
5454
->isRequired()
55+
->defaultValue('/cms/blog')
5556
->end()
56-
->scalarNode('routing_post_controller')
57+
->scalarNode('routing_post_controller') # unused
5758
->defaultValue('cmf_blog.blog_controller:viewPostAction')
5859
->end()
59-
->scalarNode('routing_post_prefix')
60+
->scalarNode('routing_post_prefix') # unused
6061
->defaultValue('posts')
6162
->end()
62-
->scalarNode('routing_tag_controller')
63+
->scalarNode('routing_tag_controller') # unused
6364
->defaultValue('cmf_blog.blog_controller:listAction')
6465
->end()
65-
->scalarNode('routing_tag_prefix')
66+
->scalarNode('routing_tag_prefix') # unused
6667
->defaultValue('tag')
6768
->end()
6869
->arrayNode('class')
70+
->addDefaultsIfNotSet()
6971
->children()
70-
# defaults defined in CmfBlogExtension
71-
->scalarNode('blog_admin')->end()
72-
->scalarNode('post_admin')->end()
73-
->scalarNode('blog')->end()
74-
->scalarNode('post')->end()
72+
->scalarNode('blog_admin')
73+
->defaultValue('Symfony\Cmf\Bundle\BlogBundle\Admin\BlogAdmin')
74+
->end()
75+
->scalarNode('post_admin')
76+
->defaultValue('Symfony\Cmf\Bundle\BlogBundle\Admin\PostAdmin')
77+
->end()
78+
->scalarNode('blog')
79+
->defaultValue('Symfony\Cmf\Bundle\BlogBundle\Document\Blog')
80+
->end()
81+
->scalarNode('post')
82+
->defaultValue('Symfony\Cmf\Bundle\BlogBundle\Document\Post')
83+
->end()
7584
->end()
7685
->end()
7786
->end()

Document/Blog.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public function getId()
5454
return $this->id;
5555
}
5656

57+
public function setId($id)
58+
{
59+
$this->id = $id;
60+
}
61+
5762
public function getName()
5863
{
5964
return $this->name;
@@ -64,16 +69,32 @@ public function setName($name)
6469
$this->name = $name;
6570
}
6671

72+
/**
73+
* @deprecated Use getParentDocument instead
74+
*/
6775
public function getParent()
6876
{
6977
return $this->parent;
7078
}
7179

80+
public function getParentDocument()
81+
{
82+
return $this->parent;
83+
}
84+
85+
/**
86+
* @deprecated Use setParentDocument instead
87+
*/
7288
public function setParent($parent)
7389
{
7490
$this->parent = $parent;
7591
}
7692

93+
public function setParentDocument($parent)
94+
{
95+
$this->parent = $parent;
96+
}
97+
7798
public function getPosts()
7899
{
79100
return $this->posts;
@@ -82,6 +103,7 @@ public function getPosts()
82103
public function setPosts($posts)
83104
{
84105
$this->posts = array();
106+
85107
foreach ($posts as $post) {
86108
$this->addPost($post);
87109
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Pending features:
3131

3232
## Requirements
3333

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

0 commit comments

Comments
 (0)