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

Add last modified date to settings tab #655

Merged
merged 3 commits into from
Jun 7, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
coverage: none

- name: Remove not required tooling
run: composer remove php-cs-fixer/shim --dev --no-interaction --no-update
run: composer remove php-cs-fixer/shim "*phpstan*" --dev --no-interaction --no-update

- name: Require elasticsearch dependency
run: composer require --dev elasticsearch/elasticsearch:"${{ matrix.elasticsearch-package-constraint }}" --no-interaction --no-update
Expand Down
1 change: 1 addition & 0 deletions Content/ArticleDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ protected function getConfigurationBuilder(): BuilderInterface
['column' => 'created', 'title' => 'sulu_admin.created'],
['column' => 'title.raw', 'title' => 'sulu_admin.title'],
['column' => 'author_full_name.raw', 'title' => 'sulu_admin.author'],
['column' => 'last_modified_or_authored', 'title' => 'sulu_article.last_modified_or_authored'],
]
);

Expand Down
8 changes: 8 additions & 0 deletions Content/ArticleResourceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public function getPublished(): \DateTime
return $this->article->getPublished();
}

/**
Prokyonn marked this conversation as resolved.
Show resolved Hide resolved
* Returns lastModified.
*/
public function getLastModified(): ?\DateTime
{
return $this->article->getLastModified();
}

/**
* Returns authored.
*/
Expand Down
5 changes: 4 additions & 1 deletion DependencyInjection/SuluArticleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Sulu\Bundle\ArticleBundle\Document\ArticlePageDocument;
use Sulu\Bundle\ArticleBundle\Document\Form\ArticleDocumentType;
use Sulu\Bundle\ArticleBundle\Document\Form\ArticlePageDocumentType;
use Sulu\Bundle\ArticleBundle\Document\LocalizedLastModifiedBehavior;
use Sulu\Bundle\ArticleBundle\Document\Structure\ArticleBridge;
use Sulu\Bundle\ArticleBundle\Document\Structure\ArticlePageBridge;
use Sulu\Bundle\ArticleBundle\Exception\ArticlePageNotFoundException;
Expand Down Expand Up @@ -188,7 +189,9 @@ public function prepend(ContainerBuilder $container)
],
'forms' => [
'directories' => [
__DIR__ . '/../Resources/config/forms',
\class_exists(LocalizedLastModifiedBehavior::class)
? __DIR__ . '/../Resources/config/forms'
: __DIR__ . '/../Resources/config/forms_sulu_25_or_lower',
],
],
'resources' => [
Expand Down
34 changes: 33 additions & 1 deletion Document/ArticleDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class ArticleDocument implements UuidBehavior,
ChildrenBehavior,
ArticleInterface,
ShadowLocaleBehavior,
WebspaceBehavior
WebspaceBehavior,
LocalizedLastModifiedBehavior
{
public const RESOURCE_KEY = 'articles';

Expand Down Expand Up @@ -147,6 +148,11 @@ class ArticleDocument implements UuidBehavior,
*/
protected $changed;

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

/**
* @var int
*/
Expand Down Expand Up @@ -427,6 +433,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
52 changes: 52 additions & 0 deletions Document/ArticleViewDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,27 @@ class ArticleViewDocument implements ArticleViewDocumentInterface
*/
protected $seo;

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

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

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

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

public function getLastModified()
{
return $this->lastModified;
}

public function setLastModified($lastModified)
{
$this->lastModified = $lastModified;
$this->updateLastModifiedOrAuthored();

return $this;
}

public function getLastModifiedOrAuthored(): \DateTime
{
return $this->lastModified ?? $this->authored;
}

/**
* @internal setter is required for ONGR but should not be used
*
* @return static
*/
public function setLastModifiedOrAuthored(\DateTime $lastModifiedOrAuthored)
{
$this->lastModifiedOrAuthored = $lastModifiedOrAuthored;

return $this;
}

public function updateLastModifiedOrAuthored()
{
$this->lastModifiedOrAuthored = $this->lastModified ?? $this->authored;

return $this;
}

public function getAuthored()
{
return $this->authored;
Expand All @@ -492,6 +543,7 @@ public function getAuthored()
public function setAuthored(?\DateTime $authored = null)
{
$this->authored = $authored;
$this->updateLastModifiedOrAuthored();

return $this;
}
Expand Down
28 changes: 28 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 All @@ -271,6 +287,18 @@ public function getAuthored();
*/
public function setAuthored(?\DateTime $authored = null);

/**
* Returns lastModified or authored date.
*
* @return \DateTime|null
*/
public function getLastModifiedOrAuthored();

/**
* @return $this
*/
public function updateLastModifiedOrAuthored();

/**
* Returns author full name.
*
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 @@ -187,6 +187,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
30 changes: 30 additions & 0 deletions Document/LocalizedLastModifiedBehavior.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Document;

use Sulu\Component\DocumentManager\Behavior\LocalizedLastModifiedBehavior as SuluLocalizedLastModifiedBehavior;

if (\interface_exists(SuluLocalizedLastModifiedBehavior::class)) {
/**
* @internal BC Layer for Sulu <2.6
*/
interface LocalizedLastModifiedBehavior extends SuluLocalizedLastModifiedBehavior
{
}
} else {
/**
* @internal BC Layer for Sulu <2.6
*/
interface LocalizedLastModifiedBehavior
{
}
}
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_article.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_article.last_modified_date</title>
</meta>
</property>
<property name="authored" type="datetime" colspan="6">
<meta>
<title>sulu_page.authored_date</title>
Expand Down
Loading
Loading