Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Tests/Resources/app/cache
Tests/Resources/app/logs
bin/
composer.lock
vendor
vendor/
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ php:
- 5.5

env:
- SYMFONY_VERSION=2.5.*
- SYMFONY_VERSION=2.6.*

matrix:
allow_failures:
- env: SYMFONY_VERSION=dev-master
- env: SYMFONY_VERSION=2.7.*
include:
- php: 5.5
env: SYMFONY_VERSION=2.3.*
- php: 5.5
env: SYMFONY_VERSION=2.4.*
- php: 5.5
env: SYMFONY_VERSION=dev-master


env: SYMFONY_VERSION=2.5.*
- php: 5.5
env: SYMFONY_VERSION=2.7.*

before_script:
- composer self-update
Expand Down
55 changes: 32 additions & 23 deletions Admin/BlogAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@
* file that was distributed with this source code.
*/


namespace Symfony\Cmf\Bundle\BlogBundle\Admin;

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
* Blog Admin.
*
* @author Daniel Leech <[email protected]>
*/
Expand All @@ -30,33 +26,46 @@ class BlogAdmin extends Admin
protected $translationDomain = 'CmfBlogBundle';
protected $blogRoot;

protected function configureFormFields(FormMapper $mapper)
{
$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)
/**
* Constructor.
*
* @param string $code
* @param string $class
* @param string $baseControllerName
* @param string $blogRoot
*/
public function __construct($code, $class, $baseControllerName, $blogRoot)
{
$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('description', 'textarea')
->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')
;
}
}
72 changes: 37 additions & 35 deletions Admin/PostAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,65 +9,67 @@
* file that was distributed with this source code.
*/


namespace Symfony\Cmf\Bundle\BlogBundle\Admin;

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\Form\DataTransformer\CsvToArrayTransformer;

/**
* Post Admin
* Post Admin.
*
* @author Daniel Leech <[email protected]>
*/
class PostAdmin extends Admin
{
protected $translationDomain = 'CmfBlogBundle';
protected $blogClass;

protected function configureFormFields(FormMapper $mapper)
/**
* Constructor.
*
* @param string $code
* @param string $class
* @param string $baseControllerName
* @param string $blogClass
*/
public function __construct($code, $class, $baseControllerName, $blogClass)
{
// @todo: I think this would be better as a service,
// but I don't know how integrate the form
// AND have all the Sonata magic from the
// FormMapper->add method.

// $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',
));

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

// $mapper->add($tags);
parent::__construct($code, $class, $baseControllerName);
$this->blogClass = $blogClass;
}

protected function configureDatagridFilters(DatagridMapper $dm)
protected function configureFormFields(FormMapper $formMapper)
{
$dm->add('title', 'doctrine_phpcr_string');
$formMapper
->with('dashboard.label_post')
->add('title')
->add('date', 'datetime', array(
'widget' => 'single_text',
))
->add('bodyPreview', 'textarea')
->add('body', 'textarea')
->add('blog', 'phpcr_document', array(
'class' => $this->blogClass,
))
->end()
;
}

protected function configureListFields(ListMapper $dm)
protected function configureDatagridFilters(DatagridMapper $filterMapper)
{
$dm->add('blog');
$dm->add('date', 'datetime');
$dm->addIdentifier('title');
$filterMapper
->add('title', 'doctrine_phpcr_string')
;
}

public function validate(ErrorElement $ee, $obj)
protected function configureListFields(ListMapper $listMapper)
{
$ee->with('title')->assertNotBlank()->end();
$listMapper
->addIdentifier('title')
->add('blog')
->add('date', 'datetime')
;
}
}
62 changes: 0 additions & 62 deletions Block/TagCloudBlock.php

This file was deleted.

20 changes: 19 additions & 1 deletion CmfBlogBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,29 @@
* file that was distributed with this source code.
*/


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\Doctrine\Phpcr',
),
array('cmf_blog.persistence.phpcr.manager_name'),
false,
array('CmfBlogBundle' => 'Symfony\Cmf\Bundle\BlogBundle\Doctrine\Phpcr')
)
);
}
}
}
77 changes: 77 additions & 0 deletions Controller/BaseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Cmf\Bundle\BlogBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use FOS\RestBundle\View\ViewHandlerInterface;
use FOS\RestBundle\View\View;

/**
* Base Controller.
*/
abstract class BaseController
{
/**
* @var EngineInterface
*/
protected $templating;

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

/**
* @var ViewHandlerInterface
*/
protected $viewHandler;

/**
* Constructor.
*
* @param EngineInterface $templating
* @param SecurityContextInterface $securityContext
* @param ViewHandlerInterface $viewHandler
*/
public function __construct(
EngineInterface $templating,
SecurityContextInterface $securityContext,
ViewHandlerInterface $viewHandler = null
) {
$this->templating = $templating;
$this->securityContext = $securityContext;
$this->viewHandler = $viewHandler;
}

protected function renderResponse($contentTemplate, $params)
{
if ($this->viewHandler) {
$view = new View($params);
$view->setTemplate($contentTemplate);

return $this->viewHandler->handle($view);
}

return $this->templating->renderResponse($contentTemplate, $params);
}

protected function getTemplateForResponse(Request $request, $contentTemplate)
{
return str_replace(
array('{_format}', '{_locale}'),
array($request->getRequestFormat(), $request->getLocale()),
$contentTemplate
);
}
}
Loading