Skip to content

Commit

Permalink
Merge pull request protalk#73 from Bendihossan/master
Browse files Browse the repository at this point in the history
Adds ability to manage pages in backend
  • Loading branch information
lineke committed Oct 23, 2012
2 parents 28683ab + f07fceb commit a3fe61b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 9 deletions.
5 changes: 5 additions & 0 deletions app/config/config.yml
Expand Up @@ -118,6 +118,11 @@ services:
tags:
- { name: sonata.admin, manager_type: orm, group: protalk_media, label: Rating }
arguments: [null, Protalk\MediaBundle\Entity\Rating, null]
protalk.media.admin.page:
class: Protalk\AdminBundle\Admin\PageAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: protalk_media, label: Page }
arguments: [null, Protalk\PageBundle\Entity\Page, null]

fos_user:
db_driver: orm
Expand Down
47 changes: 47 additions & 0 deletions src/Protalk/AdminBundle/Admin/PageAdmin.php
@@ -0,0 +1,47 @@
<?php

/**
* ProTalk
*
* Copyright (c) 2012, Steffan Harries <contact@steffanharries.me.uk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Protalk\AdminBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Form\FormMapper;

class PageAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('url')->add('pageTitle')->add('title')->add('content');
}

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('pageTitle');
}

protected function configureListFields(ListMapper $listMapper)
{
$listMapper->addIdentifier('title')->add('url');
}

public function validate(ErrorElement $errorElement, $object)
{
$errorElement
->with('pageTitle')
->assertMaxLength(array('limit' => 100))
->end()
->with('url')
->assertMaxLength(array('limit' => 100))
->end();
}
}
13 changes: 8 additions & 5 deletions src/Protalk/AdminBundle/Admin/TagAdmin.php
Expand Up @@ -21,21 +21,24 @@ class TagAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('name');
$formMapper->add('name')->add('slug');
}

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('name');
$datagridMapper->add('name')->add('slug');
}

protected function configureListFields(ListMapper $listMapper)
{
$listMapper->addIdentifier('name');
$listMapper->addIdentifier('name')->add('slug');
}

public function validate(ErrorElement $errorElement, $object)
{
$errorElement->with('name')->assertMaxLength(array('limit' => 50))->end();
$errorElement
->with('name')
->assertMaxLength(array('limit' => 50))
->end();
}
}
}
16 changes: 12 additions & 4 deletions src/Protalk/MediaBundle/Entity/Tag.php
Expand Up @@ -136,12 +136,21 @@ public function setSlug($slug)
$this->slug = $slug;
}

/*
* Maps to getSlugFields()
*
* Exists because the backend makes a call to getSlug()
* when creating/updating tags.
*/
public function getSlug() {
return $this->getSlugFields();
}

/*
* Get slug fields
*
* @return string
*/

public function getSlugFields() {
return $this->getName();
}
Expand All @@ -151,11 +160,10 @@ public function getSlugFields() {
*/
public function updateSlug()
{

$slugger = new Slugger();
$slugger = new Slugger(' ', ',');

$slug = $slugger->getSlug($this->getSlugFields());

return $this->setSlug($slug);
}
}
}

0 comments on commit a3fe61b

Please sign in to comment.