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

Code clean up >= Sulu 1.5 #98

Merged
Merged
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
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