Skip to content

Commit

Permalink
Code clean up >= Sulu 1.5 (#98)
Browse files Browse the repository at this point in the history
* Removed not needed js component

* Implemented AuthorBehavior

* Fixed bug

* Fixed PHPDocs
  • Loading branch information
trickreich authored and wachterjohannes committed Mar 14, 2017
1 parent 46584a4 commit ce4fe65
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 248 deletions.
27 changes: 0 additions & 27 deletions Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,6 @@ public function postAction(Request $request)
$locale = $this->getRequestParameter($request, 'locale', true);
$data = $request->request->all();

$document->setAuthored(new \DateTime());
if (array_key_exists('authored', $data)) {
$document->setAuthored(new \DateTime($data['authored']));
}
$document->setAuthor($this->getAuthor($data));

$this->persistDocument($data, $document, $locale);
$this->handleActionParameter($action, $document, $locale);
$this->getDocumentManager()->flush();
Expand Down Expand Up @@ -260,11 +254,6 @@ public function putAction(Request $request, $uuid)

$this->get('sulu_hash.request_hash_checker')->checkHash($request, $document, $document->getUuid());

if (array_key_exists('authored', $data)) {
$document->setAuthored(new \DateTime($data['authored']));
}
$document->setAuthor($this->getAuthor($data));

$this->persistDocument($data, $document, $locale);
$this->handleActionParameter($action, $document, $locale);
$this->getDocumentManager()->flush();
Expand Down Expand Up @@ -412,22 +401,6 @@ private function persistDocument($data, $document, $locale)
);
}

/**
* Returns author or current user.
*
* @param array $data
*
* @return int
*/
private function getAuthor(array $data)
{
if (!array_key_exists('author', $data)) {
return $this->getUser()->getContact()->getId();
}

return $data['author'];
}

/**
* Returns document-manager.
*
Expand Down
36 changes: 11 additions & 25 deletions Document/ArticleDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Sulu\Bundle\ArticleBundle\Document\Behavior\DateShardingBehavior;
use Sulu\Bundle\RouteBundle\Model\RoutableInterface;
use Sulu\Bundle\RouteBundle\Model\RouteInterface;
use Sulu\Component\Content\Document\Behavior\AuthorBehavior;
use Sulu\Component\Content\Document\Behavior\ExtensionBehavior;
use Sulu\Component\Content\Document\Behavior\LocalizedAuditableBehavior;
use Sulu\Component\Content\Document\Behavior\LocalizedStructureBehavior;
Expand Down Expand Up @@ -46,7 +47,8 @@ class ArticleDocument implements
RoutableInterface,
ExtensionBehavior,
WorkflowStageBehavior,
VersionBehavior
VersionBehavior,
AuthorBehavior
{
/**
* @var string
Expand Down Expand Up @@ -421,51 +423,35 @@ public function getPublished()
}

/**
* Set authored.
*
* @param \DateTime $authored
*
* @return $this
* {@inheritdoc}
*/
public function setAuthored(\DateTime $authored = null)
public function getAuthored()
{
$this->authored = $authored;

return $this;
return $this->authored;
}

/**
* Returns date-time of authoring this article.
*
* @return \DateTime
* {@inheritdoc}
*/
public function getAuthored()
public function setAuthored($authored)
{
return $this->authored;
$this->authored = $authored;
}

/**
* Returns id of author.
*
* @return int
* {@inheritdoc}
*/
public function getAuthor()
{
return $this->author;
}

/**
* Sets id of author.
*
* @param int $author
*
* @return $this
* {@inheritdoc}
*/
public function setAuthor($author)
{
$this->author = $author;

return $this;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions Document/Form/ArticleDocumentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Sulu\Bundle\ArticleBundle\Document\Form;

use Sulu\Bundle\ContentBundle\Form\Type\AbstractStructureBehaviorType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
Expand All @@ -36,6 +37,12 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->add('resourceSegment', TextType::class, ['mapped' => false]);
$builder->add('navigationContexts', TextType::class, ['mapped' => false]);
$builder->add('shadowLocaleEnabled', TextType::class, ['mapped' => false]);
$builder->add(
'authored',
DateType::class,
['widget' => 'single_text', 'model_timezone' => 'UTC', 'view_timezone' => 'UTC']
);
$builder->add('author', TextType::class);
}

/**
Expand Down
14 changes: 0 additions & 14 deletions Document/Subscriber/ArticleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,20 +339,6 @@ public function handleMetadataLoad(MetadataLoadEvent $event)
'property' => 'routePath',
]
);
$metadata->addFieldMapping(
'authored',
[
'encoding' => 'system_localized',
'property' => 'authored',
]
);
$metadata->addFieldMapping(
'author',
[
'encoding' => 'system_localized',
'property' => 'author',
]
);
}

/**
Expand Down

This file was deleted.

Loading

0 comments on commit ce4fe65

Please sign in to comment.