diff --git a/Admin/BlogAdmin.php b/Admin/BlogAdmin.php
index fb7a11b..4b228bb 100644
--- a/Admin/BlogAdmin.php
+++ b/Admin/BlogAdmin.php
@@ -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
@@ -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')
+ ;
}
}
diff --git a/Admin/PostAdmin.php b/Admin/PostAdmin.php
index df1fa90..4f87a89 100644
--- a/Admin/PostAdmin.php
+++ b/Admin/PostAdmin.php
@@ -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;
/**
@@ -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);
diff --git a/CmfBlogBundle.php b/CmfBlogBundle.php
index 802bdaa..45a9f9c 100644
--- a/CmfBlogBundle.php
+++ b/CmfBlogBundle.php
@@ -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')
+ )
+ );
+ }
+ }
}
diff --git a/Controller/BlogController.php b/Controller/BlogController.php
index fb77135..3f49805 100644
--- a/Controller/BlogController.php
+++ b/Controller/BlogController.php
@@ -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;
@@ -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.
@@ -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;
}
/**
@@ -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;
@@ -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(),
));
diff --git a/DependencyInjection/CmfBlogExtension.php b/DependencyInjection/CmfBlogExtension.php
index a5dd1b7..9dbd3bb 100644
--- a/DependencyInjection/CmfBlogExtension.php
+++ b/DependencyInjection/CmfBlogExtension.php
@@ -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);
@@ -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),
@@ -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']);
}
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 9c94521..50c852b 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -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()
diff --git a/Document/Blog.php b/Document/Blog.php
index 5d235c1..9e3b38e 100644
--- a/Document/Blog.php
+++ b/Document/Blog.php
@@ -54,6 +54,11 @@ public function getId()
return $this->id;
}
+ public function setId($id)
+ {
+ $this->id = $id;
+ }
+
public function getName()
{
return $this->name;
@@ -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;
@@ -82,6 +103,7 @@ public function getPosts()
public function setPosts($posts)
{
$this->posts = array();
+
foreach ($posts as $post) {
$this->addPost($post);
}
diff --git a/README.md b/README.md
index 459126f..356a8c8 100644
--- a/README.md
+++ b/README.md
@@ -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)
diff --git a/Resources/config/blog-admin.xml b/Resources/config/admin.xml
similarity index 51%
rename from Resources/config/blog-admin.xml
rename to Resources/config/admin.xml
index 1e1c518..1f4f1c2 100644
--- a/Resources/config/blog-admin.xml
+++ b/Resources/config/admin.xml
@@ -4,43 +4,33 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
-
-
-
-
-
-
-
-
-
+
%cmf_blog.blog_class%
SonataAdminBundle:CRUD
+ %cmf_blog.blog_basepath%
-
-
- %cmf_blog.blog_basepath%
-
-
-
+
%cmf_blog.post_class%
diff --git a/Resources/config/cmf_routing_auto.yml b/Resources/config/cmf_routing_auto.yml
new file mode 100644
index 0000000..71c46fd
--- /dev/null
+++ b/Resources/config/cmf_routing_auto.yml
@@ -0,0 +1,11 @@
+Symfony\Cmf\Bundle\BlogBundle\Document\Blog:
+ uri_schema: /blogs/{blog}
+ token_providers:
+ blog: [content_method, { method: getName }]
+
+Symfony\Cmf\Bundle\BlogBundle\Document\Post:
+ uri_schema: /blogs/{blog}/{date}/{title}
+ token_providers:
+ blog: [content_method, { method: getBlog }]
+ date: [content_datetime, { method: getDate }]
+ title: [content_method, { method: getTitle }]
diff --git a/Resources/config/controllers.xml b/Resources/config/controllers.xml
deleted file mode 100644
index 846eab2..0000000
--- a/Resources/config/controllers.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
- Symfony\Cmf\Bundle\BlogBundle\Controller\BlogController
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Resources/config/doctrine/Blog.phpcr.xml b/Resources/config/doctrine-phpcr/Blog.phpcr.xml
similarity index 83%
rename from Resources/config/doctrine/Blog.phpcr.xml
rename to Resources/config/doctrine-phpcr/Blog.phpcr.xml
index ddfe29b..43c8de9 100644
--- a/Resources/config/doctrine/Blog.phpcr.xml
+++ b/Resources/config/doctrine-phpcr/Blog.phpcr.xml
@@ -2,23 +2,28 @@
xmlns="http://doctrine-project.org/schemas/phpcr-odm/phpcr-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/phpcr-odm/phpcr-mapping
- https://github.com/doctrine/phpcr-odm/raw/master/doctrine-phpcr-odm-mapping.xsd"
->
+ https://github.com/doctrine/phpcr-odm/raw/master/doctrine-phpcr-odm-mapping.xsd">
+ >
+
+
-
+
-
+
+
+
+
+
diff --git a/Resources/config/doctrine/Post.phpcr.xml b/Resources/config/doctrine-phpcr/Post.phpcr.xml
similarity index 89%
rename from Resources/config/doctrine/Post.phpcr.xml
rename to Resources/config/doctrine-phpcr/Post.phpcr.xml
index daed590..deba37c 100644
--- a/Resources/config/doctrine/Post.phpcr.xml
+++ b/Resources/config/doctrine-phpcr/Post.phpcr.xml
@@ -2,8 +2,7 @@
xmlns="http://doctrine-project.org/schemas/phpcr-odm/phpcr-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/phpcr-odm/phpcr-mapping
- https://github.com/doctrine/phpcr-odm/raw/master/doctrine-phpcr-odm-mapping.xsd"
->
+ https://github.com/doctrine/phpcr-odm/raw/master/doctrine-phpcr-odm-mapping.xsd">
+
+
+
+
@@ -21,11 +24,14 @@
-
-
+
-
+
+
+
+
+
diff --git a/Resources/config/doctrine/TagRoute.phpcr.xml b/Resources/config/doctrine-phpcr/TagRoute.phpcr.xml
similarity index 94%
rename from Resources/config/doctrine/TagRoute.phpcr.xml
rename to Resources/config/doctrine-phpcr/TagRoute.phpcr.xml
index 423400e..4064dd7 100644
--- a/Resources/config/doctrine/TagRoute.phpcr.xml
+++ b/Resources/config/doctrine-phpcr/TagRoute.phpcr.xml
@@ -2,8 +2,7 @@
xmlns="http://doctrine-project.org/schemas/phpcr-odm/phpcr-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/phpcr-odm/phpcr-mapping
- https://github.com/doctrine/phpcr-odm/raw/master/doctrine-phpcr-odm-mapping.xsd"
->
+ https://github.com/doctrine/phpcr-odm/raw/master/doctrine-phpcr-odm-mapping.xsd">
+
+
+
+
+
+
+ CmfBlogBundle
+
+ %cmf_blog.blog_basepath%
+
+
+
+
+
+
diff --git a/Resources/config/menu.xml b/Resources/config/menu.xml
index 02c70dc..c5a309a 100644
--- a/Resources/config/menu.xml
+++ b/Resources/config/menu.xml
@@ -12,7 +12,9 @@
%cmf_blog.content_key%
%cmf_blog.post_class%
-
+
+
+
diff --git a/Resources/config/routing/autoroute_default.yml b/Resources/config/routing/autoroute_default.yml
deleted file mode 100644
index 688ab72..0000000
--- a/Resources/config/routing/autoroute_default.yml
+++ /dev/null
@@ -1,30 +0,0 @@
-cmf_routing_auto:
- mappings:
- Symfony\Cmf\Bundle\BlogBundle\Document\Blog:
- content_path:
- routing_path:
- provider: [specified, { path: cms/routes }]
- exists_action: use
- not_exists_action: throw_exception
- namespace:
- provider: [specified, { path: blog }]
- exists_action: use
- not_exists_action: create
- content_name:
- provider: [content_method,{ method: getName }]
- exists_action: auto_increment
- not_exists_action: create
- Symfony\Cmf\Bundle\BlogBundle\Document\Post:
- content_path:
- routing_path:
- provider: [content_object, { method: getBlog }]
- exists_action: use
- not_exists_action: throw_exception
- date:
- provider: [content_datetime, {method: getDate}]
- exists_action: use
- not_exists_action: create
- content_name:
- provider: [content_method, {method: getTitle}]
- exists_action: auto_increment
- not_exists_action: create
diff --git a/Resources/config/services.xml b/Resources/config/services.xml
new file mode 100644
index 0000000..83f0f17
--- /dev/null
+++ b/Resources/config/services.xml
@@ -0,0 +1,35 @@
+
+
+
+ Symfony\Cmf\Bundle\BlogBundle\Controller\BlogController
+
+
+
+
+
+
+
+
+
+
+
+
+ %cmf_blog.blog_class%
+
+
+
+ %cmf_blog.post_class%
+
+
+
+
+
+
diff --git a/Resources/doc/building-a-blog.rst b/Resources/doc/building-a-blog.rst
index 62f15dc..a71ab89 100644
--- a/Resources/doc/building-a-blog.rst
+++ b/Resources/doc/building-a-blog.rst
@@ -15,6 +15,6 @@ Register the routes in config.yml
dynamic:
...
controllers_by_class:
- Symfony\Cmf\Bundle\BlogBundle\Document\Blog: cmf_blog.blog_controller:list
- Symfony\Cmf\Bundle\BlogBundle\Document\Post: cmf_blog.blog_controller:viewPost
- Symfony\Cmf\Bundle\BlogBundle\Document\Tag: cmf_blog.blog_controller:list
+ Symfony\Cmf\Bundle\BlogBundle\Document\Blog: cmf_blog.blog_controller:listAction
+ Symfony\Cmf\Bundle\BlogBundle\Document\Post: cmf_blog.blog_controller:viewPostAction
+ Symfony\Cmf\Bundle\BlogBundle\Document\Tag: cmf_blog.blog_controller:listAction
diff --git a/Resources/translations/CmfBlogBundle.en.xliff b/Resources/translations/CmfBlogBundle.en.xliff
index 6a5122e..225b183 100644
--- a/Resources/translations/CmfBlogBundle.en.xliff
+++ b/Resources/translations/CmfBlogBundle.en.xliff
@@ -107,8 +107,8 @@
Name
-
-
+
+
Parent
diff --git a/Resources/translations/CmfBlogBundle.fr.xliff b/Resources/translations/CmfBlogBundle.fr.xliff
index 5e3437e..3b83108 100644
--- a/Resources/translations/CmfBlogBundle.fr.xliff
+++ b/Resources/translations/CmfBlogBundle.fr.xliff
@@ -107,8 +107,8 @@
Nom
-
-
+
+
Parent
diff --git a/Resources/translations/CmfBlogBundle.pl.xliff b/Resources/translations/CmfBlogBundle.pl.xliff
index 8af6ef1..d837f91 100644
--- a/Resources/translations/CmfBlogBundle.pl.xliff
+++ b/Resources/translations/CmfBlogBundle.pl.xliff
@@ -107,8 +107,8 @@
Nazwa
-
-
+
+
Nadrzędny
diff --git a/Resources/translations/CmfBlogBundle.ru.xliff b/Resources/translations/CmfBlogBundle.ru.xliff
index 2ea6e83..ba018bd 100644
--- a/Resources/translations/CmfBlogBundle.ru.xliff
+++ b/Resources/translations/CmfBlogBundle.ru.xliff
@@ -107,8 +107,8 @@
Имя
-
-
+
+
Родитель
diff --git a/Resources/translations/CmfBlogBundle.sk.xliff b/Resources/translations/CmfBlogBundle.sk.xliff
index a089db6..b5b68a2 100644
--- a/Resources/translations/CmfBlogBundle.sk.xliff
+++ b/Resources/translations/CmfBlogBundle.sk.xliff
@@ -107,8 +107,8 @@
Názov
-
-
+
+
Rodič
diff --git a/Resources/translations/CmfBlogBundle.sl.xliff b/Resources/translations/CmfBlogBundle.sl.xliff
index 2a9d863..2be0ffd 100644
--- a/Resources/translations/CmfBlogBundle.sl.xliff
+++ b/Resources/translations/CmfBlogBundle.sl.xliff
@@ -107,8 +107,8 @@
Ime
-
-
+
+
Vrhnji
diff --git a/composer.json b/composer.json
index 387ec94..ef17776 100644
--- a/composer.json
+++ b/composer.json
@@ -1,5 +1,5 @@
{
- "name": "briancappello/blog-bundle",
+ "name": "symfony-cmf/blog-bundle",
"type": "symfony-bundle",
"description": "Symfony CMF Blog Bundle",
"keywords": ["Symfony CMF"],