Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version upgrades and cleanups #58

Closed
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Tests/Resources/app/cache
Tests/Resources/app/logs
bin/
composer.lock
vendor
vendor/
.idea
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the responsibility of the global git configuration of the developer, it is not specific to the project but to specific development environments. please remove this line.

4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ php:

env:
- SYMFONY_VERSION=2.5.*

matrix:
allow_failures:
- env: SYMFONY_VERSION=dev-master
Expand All @@ -18,8 +18,6 @@ matrix:
env: SYMFONY_VERSION=2.4.*
- php: 5.5
env: SYMFONY_VERSION=dev-master



before_script:
- composer self-update
Expand Down
52 changes: 31 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,46 @@ 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('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')
;
}
}
69 changes: 36 additions & 33 deletions Admin/PostAdmin.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\Form\DataTransformer\CsvToArrayTransformer;

/**
* Post Admin
Expand All @@ -28,46 +25,52 @@
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.

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


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line

namespace Symfony\Cmf\Bundle\BlogBundle\Controller;

use Knp\Component\Pager\Paginator;
use Symfony\Cmf\Bundle\BlogBundle\Model\Post;
use Symfony\Cmf\Bundle\BlogBundle\Model\Blog;
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\Bundle\FrameworkBundle\Templating\EngineInterface;
use FOS\RestBundle\View\ViewHandlerInterface;
use FOS\RestBundle\View\View;

/**
* Base Controller
*
* @author Daniel Leech <[email protected]>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't write this :)

*/
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