Skip to content

Commit

Permalink
Rename Namespace and Bundle in News
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Kossin committed Dec 14, 2019
1 parent 976e838 commit d6102d2
Show file tree
Hide file tree
Showing 22 changed files with 462 additions and 372 deletions.
2 changes: 1 addition & 1 deletion Admin/DoctrineListRepresentationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Bundle\ArticleBundle\Admin;
namespace App\Bundle\NewsBundle\Admin;


use Sulu\Component\Rest\ListBuilder\Doctrine\FieldDescriptor\DoctrineFieldDescriptor;
Expand Down
84 changes: 45 additions & 39 deletions Admin/ArticleAdmin.php → Admin/NewsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace App\Bundle\ArticleBundle\Admin;
namespace App\Bundle\NewsBundle\Admin;

use App\Bundle\ArticleBundle\Entity\Article;
use App\Bundle\NewsBundle\Entity\News;
use Sulu\Bundle\AdminBundle\Admin\Admin;
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItem;
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItemCollection;
Expand All @@ -16,19 +16,19 @@
use Sulu\Component\Security\Authorization\SecurityCheckerInterface;
use Sulu\Component\Webspace\Manager\WebspaceManagerInterface;

class ArticleAdmin extends Admin
class NewsAdmin extends Admin
{
const ARTICLE_SECURITY_CONTEXT = 'sulu.article';
const NEWS_SECURITY_CONTEXT = 'sulu.news';

const IMAGE_LIST_KEY = 'articles';
const NEWS_LIST_KEY = 'news';

const IMAGE_FORM_KEY = 'article_details';
const NEWS_FORM_KEY = 'news_details';

const IMAGE_LIST_VIEW = 'app.articles_list';
const NEWS_LIST_VIEW = 'app.news_list';

const IMAGE_ADD_FORM_VIEW = 'app.article_add_form';
const NEWS_ADD_FORM_VIEW = 'app.news_add_form';

const IMAGE_EDIT_FORM_VIEW = 'app.article_edit_form';
const NEWS_EDIT_FORM_VIEW = 'app.news_edit_form';

/**
* @var ViewBuilderFactoryInterface
Expand All @@ -44,6 +44,12 @@ class ArticleAdmin extends Admin
*/
private $securityChecker;

/**
* ArticleAdmin constructor.
* @param ViewBuilderFactoryInterface $viewBuilderFactory
* @param WebspaceManagerInterface $webspaceManager
* @param SecurityCheckerInterface $securityChecker
*/
public function __construct(
ViewBuilderFactoryInterface $viewBuilderFactory,
WebspaceManagerInterface $webspaceManager,
Expand All @@ -60,15 +66,15 @@ public function __construct(
*/
public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void
{
if ($this->securityChecker->hasPermission(static::ARTICLE_SECURITY_CONTEXT, PermissionTypes::VIEW)) {
$module = new NavigationItem('app.article');
if ($this->securityChecker->hasPermission(static::NEWS_SECURITY_CONTEXT, PermissionTypes::VIEW)) {
$module = new NavigationItem('app.news');
$module->setPosition(20);
$module->setIcon('su-newspaper');

// Configure a NavigationItem with a View
$events = new NavigationItem('app.article');
$events = new NavigationItem('app.news');
$events->setPosition(10);
$events->setView(static::IMAGE_LIST_VIEW);
$events->setView(static::NEWS_LIST_VIEW);

$module->addChild($events);

Expand All @@ -83,40 +89,40 @@ public function configureViews(ViewCollection $viewCollection): void
{
$locales = $this->webspaceManager->getAllLocales();

// Configure article List View
// Configure news List View
$listToolbarActions = [new ToolbarAction('sulu_admin.add'), new ToolbarAction('sulu_admin.delete')];
$listView = $this->viewBuilderFactory->createListViewBuilder(self::IMAGE_LIST_VIEW, '/articles/:locale')
->setResourceKey(Article::RESOURCE_KEY)
->setListKey(self::IMAGE_LIST_KEY)
->setTitle('app.article')
$listView = $this->viewBuilderFactory->createListViewBuilder(self::NEWS_LIST_VIEW, '/news/:locale')
->setResourceKey(News::RESOURCE_KEY)
->setListKey(self::NEWS_LIST_KEY)
->setTitle('app.news')
->addListAdapters(['table'])
->addLocales($locales)
->setDefaultLocale($locales[0])
->setAddView(static::IMAGE_ADD_FORM_VIEW)
->setEditView(static::IMAGE_EDIT_FORM_VIEW)
->setAddView(static::NEWS_ADD_FORM_VIEW)
->setEditView(static::NEWS_EDIT_FORM_VIEW)
->addToolbarActions($listToolbarActions);
$viewCollection->add($listView);


$addFormView = $this->viewBuilderFactory->createResourceTabViewBuilder(self::IMAGE_ADD_FORM_VIEW, '/articles/:locale/add')
->setResourceKey(Article::RESOURCE_KEY)
->setBackView(static::IMAGE_LIST_VIEW)
$addFormView = $this->viewBuilderFactory->createResourceTabViewBuilder(self::NEWS_ADD_FORM_VIEW, '/news/:locale/add')
->setResourceKey(News::RESOURCE_KEY)
->setBackView(static::NEWS_LIST_VIEW)
->addLocales($locales);
$viewCollection->add($addFormView);

$addDetailsFormView = $this->viewBuilderFactory->createFormViewBuilder(self::IMAGE_ADD_FORM_VIEW . '.details', '/details')
->setResourceKey(Article::RESOURCE_KEY)
->setFormKey(self::IMAGE_FORM_KEY)
$addDetailsFormView = $this->viewBuilderFactory->createFormViewBuilder(self::NEWS_ADD_FORM_VIEW . '.details', '/details')
->setResourceKey(News::RESOURCE_KEY)
->setFormKey(self::NEWS_FORM_KEY)
->setTabTitle('sulu_admin.details')
->setEditView(static::IMAGE_EDIT_FORM_VIEW)
->setEditView(static::NEWS_EDIT_FORM_VIEW)
->addToolbarActions([new ToolbarAction('sulu_admin.save')])
->setParent(static::IMAGE_ADD_FORM_VIEW);
->setParent(static::NEWS_ADD_FORM_VIEW);
$viewCollection->add($addDetailsFormView);

// Configure news Edit View
$editFormView = $this->viewBuilderFactory->createResourceTabViewBuilder(static::IMAGE_EDIT_FORM_VIEW, '/articles/:locale/:id')
->setResourceKey(Article::RESOURCE_KEY)
->setBackView(static::IMAGE_LIST_VIEW)
$editFormView = $this->viewBuilderFactory->createResourceTabViewBuilder(static::NEWS_EDIT_FORM_VIEW, '/news/:locale/:id')
->setResourceKey(News::RESOURCE_KEY)
->setBackView(static::NEWS_LIST_VIEW)
->setTitleProperty('title')
->addLocales($locales);
$viewCollection->add($editFormView);
Expand All @@ -125,18 +131,18 @@ public function configureViews(ViewCollection $viewCollection): void
new ToolbarAction('sulu_admin.save'),
new ToolbarAction('sulu_admin.delete'),
new TogglerToolbarAction(
'app.enable_article',
'app.enable_news',
'enabled',
'enable',
'disable'
),
];
$editDetailsFormView = $this->viewBuilderFactory->createFormViewBuilder(static::IMAGE_EDIT_FORM_VIEW . '.details', '/details')
->setResourceKey(Article::RESOURCE_KEY)
->setFormKey(self::IMAGE_FORM_KEY)
$editDetailsFormView = $this->viewBuilderFactory->createFormViewBuilder(static::NEWS_EDIT_FORM_VIEW . '.details', '/details')
->setResourceKey(News::RESOURCE_KEY)
->setFormKey(self::NEWS_FORM_KEY)
->setTabTitle('sulu_admin.details')
->addToolbarActions($formToolbarActions)
->setParent(static::IMAGE_EDIT_FORM_VIEW);
->setParent(static::NEWS_EDIT_FORM_VIEW);
$viewCollection->add($editDetailsFormView);
}

Expand All @@ -147,8 +153,8 @@ public function getSecurityContexts()
{
return [
'Sulu' => [
'Article' => [
static::ARTICLE_SECURITY_CONTEXT => [
'News' => [
static::NEWS_SECURITY_CONTEXT => [
PermissionTypes::VIEW,
PermissionTypes::ADD,
PermissionTypes::EDIT,
Expand All @@ -161,6 +167,6 @@ public function getSecurityContexts()

public function getConfigKey(): ?string
{
return 'sulu_article';
return 'sulu_news';
}
}
34 changes: 17 additions & 17 deletions Api/Article.php → Api/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@
* with this source code in the file LICENSE.
*/

namespace App\Bundle\ArticleBundle\Api;
namespace App\Bundle\NewsBundle\Api;

use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\VirtualProperty;
use App\Bundle\ArticleBundle\Entity\Article as ArticleEntity;
use App\Bundle\NewsBundle\Entity\News as NewsEntity;
use Sulu\Bundle\ContactBundle\Api\Contact;
use Sulu\Bundle\MediaBundle\Api\Media;
use Sulu\Bundle\TagBundle\Tag\TagInterface;
use Sulu\Component\Rest\ApiWrapper;


/**
* The Article class which will be exported to the API.
* The News class which will be exported to the API.
*
* @ExclusionPolicy("all")
*/
class Article extends ApiWrapper
class News extends ApiWrapper
{
const TYPE = 'article';
const TYPE = 'news';


/**
Expand All @@ -38,11 +38,11 @@ class Article extends ApiWrapper
private $header = null;

/**
* @param ArticleEntity $contact
* @param NewsEntity $contact
*/
public function __construct(ArticleEntity $contact, $locale)
public function __construct(NewsEntity $contact, $locale)
{
/** @var ArticleEntity entity */
/** @var NewsEntity entity */
$this->entity = $contact;
$this->locale = $locale;
}
Expand All @@ -54,7 +54,7 @@ public function __construct(ArticleEntity $contact, $locale)
*
* @VirtualProperty
* @SerializedName("id")
* @Groups({"fullArticle"})
* @Groups({"fullNews"})
*/
public function getId()
{
Expand All @@ -76,7 +76,7 @@ public function setTitle($title)
*
* @VirtualProperty
* @SerializedName("title")
* @Groups({"fullArticle"})
* @Groups({"fullNews"})
*/
public function getTitle()
{
Expand All @@ -87,7 +87,7 @@ public function getTitle()
*
* @VirtualProperty
* @SerializedName("teaser")
* @Groups({"fullArticle"})
* @Groups({"fullNews"})
*/
public function getTeaser()
{
Expand All @@ -98,7 +98,7 @@ public function getTeaser()
*
* @VirtualProperty
* @SerializedName("content")
* @Groups({"fullArticle"})
* @Groups({"fullNews"})
*/
public function getContent()
{
Expand All @@ -109,7 +109,7 @@ public function getContent()
*
* @VirtualProperty
* @SerializedName("enabled")
* @Groups({"fullArticle"})
* @Groups({"fullNews"})
*/
public function isEnabeld(): bool
{
Expand All @@ -120,7 +120,7 @@ public function isEnabeld(): bool
*
* @VirtualProperty
* @SerializedName("published_at")
* @Groups({"fullArticle"})
* @Groups({"fullNews"})
*/
public function getPublishedAt()
{
Expand All @@ -143,7 +143,7 @@ public function setAvatar(Media $header)
*
* @param TagInterface $tag
*
* @return Article
* @return News
*/
public function addTag(TagInterface $tag)
{
Expand All @@ -168,7 +168,7 @@ public function removeTag(TagInterface $tag): void
*
* @VirtualProperty
* @SerializedName("tags")
* @Groups({"fullArticle"})
* @Groups({"fullNews"})
*/
public function getTags(): array
{
Expand All @@ -182,7 +182,7 @@ public function getTags(): array
*
* @VirtualProperty
* @SerializedName("header")
* @Groups({"fullArticle"})
* @Groups({"fullNews"})
*/
public function getHeader(): array
{
Expand Down
16 changes: 8 additions & 8 deletions Content/ArticleDataItem.php → Content/NewsDataItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

declare(strict_types=1);

namespace App\Bundle\ArticleBundle\Content;
namespace App\Bundle\NewsBundle\Content;


use App\Bundle\ArticleBundle\Entity\Article;
use App\Bundle\NewsBundle\Entity\News;
use JMS\Serializer\Annotation as Serializer;
use Sulu\Component\SmartContent\ItemInterface;

class ArticleDataItem implements ItemInterface
class NewsDataItem implements ItemInterface
{
/**
* @var Article
* @var News
*
* @Serializer\Exclude
*/
private $entity;

/**
* ArticleDataItem constructor.
* @param Article $entity
* NewsDataItem constructor.
* @param News $entity
*/
public function __construct(Article $entity)
public function __construct(News $entity)
{
$this->entity = $entity;
}
Expand Down Expand Up @@ -52,7 +52,7 @@ public function getImage()
}

/**
* @return Article|mixed
* @return News|mixed
*/
public function getResource()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace App\Bundle\ArticleBundle\Content;
namespace App\Bundle\NewsBundle\Content;

use Sulu\Component\SmartContent\Orm\BaseDataProvider;

class ArticleDataProvider extends BaseDataProvider
class NewsDataProvider extends BaseDataProvider
{
public function getConfiguration()
{
Expand All @@ -16,7 +16,7 @@ public function getConfiguration()
->enablePagination()
->enableSorting(
[
['column' => 'article_translation.title', 'title' => 'sulu_admin.title'],
['column' => 'news_translation.title', 'title' => 'sulu_admin.title'],
]
)
->getConfiguration();
Expand All @@ -29,7 +29,7 @@ protected function decorateDataItems(array $data)
{
return array_map(
function ($item) {
return new ArticleDataItem($item);
return new NewsDataItem($item);
},
$data
);
Expand Down
Loading

0 comments on commit d6102d2

Please sign in to comment.