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 Dec 21, 2023
1 parent 8ccbbf7 commit d597b39
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 0 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();
}

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

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

/**
* @var bool
*/
protected $isUpdated;

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

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

public function setIsUpdated($isUpdated)

Check failure on line 440 in Document/ArticleDocument.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Method Sulu\Bundle\ArticleBundle\Document\ArticleDocument::setIsUpdated() has no return type specified.

Check failure on line 440 in Document/ArticleDocument.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Method Sulu\Bundle\ArticleBundle\Document\ArticleDocument::setIsUpdated() has parameter $isUpdated with no type specified.
{
$this->isUpdated = $isUpdated;
}

public function getIsUpdated()

Check failure on line 445 in Document/ArticleDocument.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Method Sulu\Bundle\ArticleBundle\Document\ArticleDocument::getIsUpdated() has no return type specified.
{
return $this->isUpdated;
}

public function setUpdated($updated)

Check failure on line 450 in Document/ArticleDocument.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Method Sulu\Bundle\ArticleBundle\Document\ArticleDocument::setUpdated() has no return type specified.

Check failure on line 450 in Document/ArticleDocument.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Method Sulu\Bundle\ArticleBundle\Document\ArticleDocument::setUpdated() has parameter $updated with no type specified.
{
$this->updated = $updated;
}

public function getUpdated()

Check failure on line 455 in Document/ArticleDocument.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Method Sulu\Bundle\ArticleBundle\Document\ArticleDocument::getUpdated() has no return type specified.
{
return $this->updated;
}

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

/**
* @var bool
*
* @Property(type="boolean")
*/
protected $isUpdated;

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

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

public function getIsUpdated()
{
return $this->isUpdated;
}

public function setIsUpdated($isUpdated)
{
$this->isUpdated = $isUpdated;

return $this;
}

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

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

return $this;
}

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

/**
* Returns isUpdated.
*
* @return bool
*/
public function getIsUpdated();

/**
* Set updated date.
*
* @param bool $isUpdated
*
* @return $this
*/
public function setIsUpdated($isUpdated);

/**
* Returns updated.
*
* @return \DateTime|null
*/
public function getUpdated();

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

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

$builder->add('isUpdated', CheckboxType::class);
$builder->add(
'updated',
DateTimeType::class,
[
'widget' => 'single_text',
]
);
$builder->add('author', TextType::class);
$builder->add(
'authored',
Expand Down
2 changes: 2 additions & 0 deletions Document/Index/ArticleIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ protected function createOrUpdateArticle(
$this->setParentPageUuid($document, $article);
$article->setChanged($document->getChanged());
$article->setCreated($document->getCreated());
$article->setIsUpdated($document->getIsUpdated());
$article->setUpdated($document->getUpdated());
$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="isUpdated" type="checkbox" colspan="6">
<meta>
<title>sulu_page.is_updated</title>
</meta>

<params>
<param name="type" value="toggler"/>
<param name="default_value" value="false"/>
</params>
</property>
<property name="updated" type="datetime" colspan="6" disabledCondition="!isUpdated">
<meta>
<title>sulu_page.updated_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"/>
<property name="updated" type="DateTime" groups="website,defaultArticle,smallArticle,preview"/>
<property name="isUpdated" type="boolean" 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
2 changes: 2 additions & 0 deletions Resources/config/serializer/Document.ArticleViewDocument.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<property name="changerFullName" type="string" expose="true"/>
<property name="created" type="DateTime" expose="true"/>
<property name="changed" type="DateTime" expose="true"/>
<property name="isUpdated" type="bool" 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
6 changes: 6 additions & 0 deletions Trash/ArticleTrashItemHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,15 @@ public function store(object $article, array $options = []): TrashItemInterface
$structureData[RoutableSubscriber::ROUTE_FIELD] = $localizedArticle->getRoutePath();

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

$data['locales'][] = [
'title' => $localizedArticle->getTitle(),
'locale' => $locale,
'creator' => $localizedArticle->getCreator(),
'created' => $localizedArticle->getCreated()->format('c'),
'isUpdated' => $localizedArticle->getIsUpdated(),
'updated' => $updated,
'author' => $localizedArticle->getAuthor(),
'authored' => $localizedArticle->getAuthored()->format('c'),
'structureType' => $localizedArticle->getStructureType(),
Expand Down Expand Up @@ -159,11 +162,14 @@ public function restore(TrashItemInterface $trashItem, array $restoreFormData =
$localizedArticle->setParent($this->documentManager->find($data['parentUuid']));
$localizedArticle->setUuid($uuid);
}
$updated = $localeData['updated'] ? new \DateTime($localeData['updated']) : null;

Check failure on line 165 in Trash/ArticleTrashItemHandler.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Cannot access offset 'updated' on mixed.

Check failure on line 165 in Trash/ArticleTrashItemHandler.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Ignored error pattern #^Parameter \#1 \$datetime of class DateTime constructor expects string, mixed given\.$# in path /home/runner/work/SuluArticleBundle/SuluArticleBundle/Trash/ArticleTrashItemHandler.php is expected to occur 2 times, but occurred 3 times.

$localizedArticle->setTitle($localeData['title']);
$localizedArticle->setLocale($locale);
$localizedArticle->setCreator($localeData['creator']);
$localizedArticle->setCreated(new \DateTime($localeData['created']));
$localizedArticle->setIsUpdated($localeData['isUpdated']);

Check failure on line 171 in Trash/ArticleTrashItemHandler.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Cannot access offset 'isUpdated' on mixed.
$localizedArticle->setUpdated($updated);
$localizedArticle->setAuthor($localeData['author']);
$localizedArticle->setAuthored(new \DateTime($localeData['authored']));

Check failure on line 174 in Trash/ArticleTrashItemHandler.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Parameter #1 $datetime of class DateTime constructor expects string, mixed given.
$localizedArticle->setStructureType($localeData['structureType']);
Expand Down

0 comments on commit d597b39

Please sign in to comment.