Skip to content

Commit

Permalink
Add updated date to settings tab
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlagler committed Jan 11, 2024
1 parent 8ccbbf7 commit 173a923
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 122 deletions.
16 changes: 16 additions & 0 deletions Content/ArticleResourceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ public function getPublished(): \DateTime
return $this->article->getPublished();
}

/**
* Returns isUpdated.
*/
public function getIsUpdated(): bool
{
return $this->article->getIsUpdated();

Check failure on line 118 in Content/ArticleResourceItem.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Call to an undefined method Sulu\Bundle\ArticleBundle\Document\ArticleViewDocumentInterface::getIsUpdated().
}

/**
* Returns updated.
*/
public function getUpdated(): ?\DateTime
{
return $this->article->getLastModified();
}

/**
* Returns authored.
*/
Expand Down
31 changes: 31 additions & 0 deletions Document/ArticleDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ class ArticleDocument implements UuidBehavior,
*/
protected $changed;

/**
* @var \DateTime|null
*/
protected $lastModified;

/**
* @var int
*/
Expand Down Expand Up @@ -427,6 +432,32 @@ public function getAuthored()
return $this->authored;
}

/**
* @return bool
*/
public function getLastModifiedEnabled()
{
return null !== $this->lastModified;
}

/**
* @param \DateTime|null $lastModified
*
* @return void
*/
public function setLastModified($lastModified)
{
$this->lastModified = $lastModified;
}

/**
* @return \DateTime|null
*/
public function getLastModified()
{
return $this->lastModified;
}

public function setAuthored($authored)
{
$this->authored = $authored;
Expand Down
27 changes: 27 additions & 0 deletions Document/ArticleViewDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ class ArticleViewDocument implements ArticleViewDocumentInterface
*/
protected $seo;

/**
* @var \DateTime|null
*
* @Property(type="date")
*/
protected $lastModified;

/**
* @var \DateTime
*
Expand Down Expand Up @@ -484,6 +491,26 @@ public function setSeo(SeoViewObject $seo)
return $this;
}

/**
* @return \DateTime|null
*/
public function getLastModified()
{
return $this->lastModified;
}

/**
* @param \DateTime|null $lastModified
*
* @return $this|ArticleViewDocument
*/
public function setLastModified($lastModified)
{
$this->lastModified = $lastModified;

return $this;
}

public function getAuthored()
{
return $this->authored;
Expand Down
16 changes: 16 additions & 0 deletions Document/ArticleViewDocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ public function getSeo();
*/
public function setSeo(SeoViewObject $seo);

/**
* Returns lastModified.
*
* @return \DateTime|null
*/
public function getLastModified();

/**
* Set lastModified date.
*
* @param \DateTime|null $lastModified
*
* @return $this
*/
public function setLastModified($lastModified);

/**
* Returns authored.
*
Expand Down
7 changes: 7 additions & 0 deletions Document/Form/ArticleDocumentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]
);

$builder->add(
'lastModified',
DateTimeType::class,
[
'widget' => 'single_text',
]
);
$builder->add('author', TextType::class);
$builder->add(
'authored',
Expand Down
1 change: 1 addition & 0 deletions Document/Index/ArticleIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ protected function createOrUpdateArticle(
$this->setParentPageUuid($document, $article);
$article->setChanged($document->getChanged());
$article->setCreated($document->getCreated());
$article->setLastModified($document->getLastModified());
$article->setAuthored($document->getAuthored());
if ($document->getAuthor() && $author = $this->contactRepository->find($document->getAuthor())) {
$article->setAuthorId($author->getId());
Expand Down
15 changes: 15 additions & 0 deletions Resources/config/forms/article_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@
<title>sulu_page.editing_information</title>
</meta>
<properties>
<property name="lastModifiedEnabled" type="checkbox" colspan="6">
<meta>
<title>sulu_page.last_modified_enabled</title>
</meta>

<params>
<param name="type" value="toggler"/>
<param name="default_value" value="false"/>
</params>
</property>
<property name="lastModified" type="datetime" colspan="6" disabledCondition="!lastModifiedEnabled">
<meta>
<title>sulu_page.last_modified_date</title>
</meta>
</property>
<property name="authored" type="datetime" colspan="6">
<meta>
<title>sulu_page.authored_date</title>
Expand Down
2 changes: 2 additions & 0 deletions Resources/config/serializer/Document.ArticleDocument.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<property name="published" type="DateTime" groups="website,defaultArticle,smallArticle,preview"/>
<property name="author" type="integer" groups="website,defaultArticle,preview"/>
<property name="authored" type="DateTime" groups="website,defaultArticle,smallArticle,preview"/>
<virtual-property method="getLastModifiedEnabled" name="lastModifiedEnabled" serialized-name="lastModifiedEnabled" groups="website,defaultArticle,smallArticle,preview"/>
<property name="lastModified" type="DateTime" groups="website,defaultArticle,smallArticle,preview"/>
<property name="extensions" type="Sulu\Component\Content\Document\Extension\ExtensionContainer" serialized-name="ext" groups="defaultArticle,preview"/>

<property name="shadowLocale" type="string" serialized-name="shadowBaseLanguage" groups="defaultArticle"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<property name="changerFullName" type="string" expose="true"/>
<property name="created" type="DateTime" expose="true"/>
<property name="changed" type="DateTime" expose="true"/>
<property name="updated" type="DateTime" expose="true"/>
<property name="authored" type="DateTime" expose="true"/>
<property name="published" type="DateTime" expose="true"/>
<property name="publishedState" type="boolean" expose="true"/>
Expand Down
21 changes: 21 additions & 0 deletions Trash/ArticleTrashItemHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ public function store(object $article, array $options = []): TrashItemInterface
$structureData[RoutableSubscriber::ROUTE_FIELD] = $localizedArticle->getRoutePath();

$articleTitles[$locale] = $localizedArticle->getTitle();
$lastModified = $localizedArticle->getLastModified() ? $localizedArticle->getLastModified()->format('c') : null;

$data['locales'][] = [
'title' => $localizedArticle->getTitle(),
'locale' => $locale,
'creator' => $localizedArticle->getCreator(),
'created' => $localizedArticle->getCreated()->format('c'),
'lastModified' => $lastModified,
'author' => $localizedArticle->getAuthor(),
'authored' => $localizedArticle->getAuthored()->format('c'),
'structureType' => $localizedArticle->getStructureType(),
Expand Down Expand Up @@ -147,6 +149,23 @@ public function restore(TrashItemInterface $trashItem, array $restoreFormData =
}
}

/** @var array{
* title: string,
* locale: string,
* creator: ?int,
* created: string,
* lastModified: ?string,
* author: ?int,
* authored: string,
* structureType: string,
* structureData: mixed,
* extensionsData: mixed,
* shadowLocaleEnabled: bool,
* shadowLocale: ?string,
* mainWebspace: ?string,
* additionalWebspaces: ?array<string>,
* } $localeData
*/
foreach ($sortedLocales as $localeData) {
$locale = $localeData['locale'];

Expand All @@ -159,11 +178,13 @@ public function restore(TrashItemInterface $trashItem, array $restoreFormData =
$localizedArticle->setParent($this->documentManager->find($data['parentUuid']));
$localizedArticle->setUuid($uuid);
}
$lastModified = $localeData['lastModified'] ? new \DateTime($localeData['lastModified']) : null;

$localizedArticle->setTitle($localeData['title']);
$localizedArticle->setLocale($locale);
$localizedArticle->setCreator($localeData['creator']);
$localizedArticle->setCreated(new \DateTime($localeData['created']));
$localizedArticle->setLastModified($lastModified);
$localizedArticle->setAuthor($localeData['author']);
$localizedArticle->setAuthored(new \DateTime($localeData['authored']));
$localizedArticle->setStructureType($localeData['structureType']);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"handcraftedinthealps/elasticsearch-dsl": "^5.0.7.1 || ^6.2.0.1 || ^7.2.0.1",
"jms/serializer": "^3.3",
"jms/serializer-bundle": "^3.3 || ^4.0",
"sulu/sulu": "~2.4.13 || ^2.5.9@dev",
"sulu/sulu": "dev-feature/updated-date as 2.5.99",
"symfony/config": "^4.3 || ^5.0 || ^6.0",
"symfony/dependency-injection": "^4.3 || ^5.0 || ^6.0",
"symfony/http-foundation": "^4.3 || ^5.0 || ^6.0",
Expand Down
Loading

0 comments on commit 173a923

Please sign in to comment.