Skip to content

Commit 544488c

Browse files
committed
Merge pull request #108 from symfony-cmf/adjust-page-document
have additionalInfoBlock and remove createDate from page
2 parents 21958e3 + 75922a8 commit 544488c

File tree

7 files changed

+61
-38
lines changed

7 files changed

+61
-38
lines changed

Admin/PageAdmin.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ protected function configureListFields(ListMapper $listMapper)
4040
->addIdentifier('title', 'text')
4141
->add('label', 'text')
4242
->add('name', 'text')
43-
->add('createDate', 'date')
4443
;
4544
}
4645

@@ -60,7 +59,6 @@ protected function configureFormFields(FormMapper $formMapper)
6059
->add('label', null, array('required' => false))
6160
->add('title')
6261
->add('body', 'textarea')
63-
->add('createDate')
6462
->end()
6563
->with('form.group_advanced', array(
6664
'translation_domain' => 'CmfRoutingBundle',
@@ -112,7 +110,7 @@ protected function ensureOrderByDate($page)
112110
$itemsByDate = array();
113111
/** @var $item Page */
114112
foreach ($items as $item) {
115-
$itemsByDate[$item->getDate()->format('U')][$item->getCreateDate()->format('U')][] = $item;
113+
$itemsByDate[$item->getDate()->format('U')][$item->getPublishStartDate()->format('U')][] = $item;
116114
}
117115

118116
if ('asc' == $this->sortOrder) {
@@ -127,8 +125,8 @@ protected function ensureOrderByDate($page)
127125
} else {
128126
krsort($itemsForDate);
129127
}
130-
foreach ($itemsForDate as $itemsForCreateDate) {
131-
foreach ($itemsForCreateDate as $item) {
128+
foreach ($itemsForDate as $itemsForPublishDate) {
129+
foreach ($itemsForPublishDate as $item) {
132130
$sortedItems[$item->getName()] = $item;
133131
}
134132
}

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ Changelog
44
1.1.0-RC2
55
---------
66

7+
* **2014-04-15**: Page now also provides the additionalInfoBlock child. Removed
8+
the createDate as its redundant with the publishStartDate.
9+
710
* **2014-04-11**: drop Symfony 2.2 compatibility
811

912
1.1.0-RC1
1013
---------
1114

1215
* **2014-04-01**: Refactored the RoutingBundle to provide all routing
1316
features needed by SimpleCmsBundle.
14-
* If you where only using the SimpleCmsBundle you now need to activate
15-
the dynamic router. SimpleCmsBundle automatically does this for you.
17+
* The dynamic router of RoutingBundle needs to be active. The
18+
SimpleCmsBundle automatically does this for you.
1619
* The configuration for document to route/template now all happens under
1720
cmf_routing.dynamic and the route enhancers also apply to simplecms Pages.
1821
You can configure additional base paths where to look for routes in the

Doctrine/Phpcr/Page.php

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use LogicException;
1616
use Knp\Menu\NodeInterface;
1717
use Doctrine\Common\Collections\ArrayCollection;
18+
use Sonata\BlockBundle\Model\BlockInterface;
1819
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishTimePeriodInterface;
1920
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishableInterface;
2021
use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface;
@@ -114,9 +115,12 @@ class Page extends Route implements
114115
protected $body;
115116

116117
/**
117-
* @var \DateTime
118+
* This will usually be a ContainerBlock but can be any block that will be
119+
* rendered in the additionalInfoBlock area.
120+
*
121+
* @var BlockInterface
118122
*/
119-
protected $createDate;
123+
protected $additionalInfoBlock;
120124

121125
/**
122126
* @var \DateTime
@@ -144,13 +148,6 @@ class Page extends Route implements
144148
*/
145149
protected $extras = array();
146150

147-
public function __construct(array $options = array())
148-
{
149-
parent::__construct($options);
150-
151-
$this->createDate = new \DateTime();
152-
}
153-
154151
/**
155152
* @deprecated use getOption('add_locale_pattern') instead
156153
*/
@@ -192,12 +189,25 @@ public function setLocale($locale)
192189
}
193190

194191
/**
195-
* Get the "date" of this page, which is the publishStartDate if set,
196-
* otherwise the createDate.
192+
* @deprecated Since 1.1 we only have the publish start date
193+
*
194+
* This method is kept for BC but will return the result of getDate().
195+
*
196+
* @return \DateTime
197+
*/
198+
public function getCreateDate()
199+
{
200+
return $this->getDate();
201+
}
202+
203+
/**
204+
* Get the "date" of this page, which is the publishStartDate.
205+
*
206+
* @return \DateTime
197207
*/
198208
public function getDate()
199209
{
200-
return $this->publishStartDate ? $this->publishStartDate : $this->createDate;
210+
return $this->getPublishStartDate();
201211
}
202212

203213
/**
@@ -251,7 +261,7 @@ public function setPublishable($publishable)
251261
/**
252262
* Get extras - a flat key-value hashmap
253263
*
254-
* @return array with only string values
264+
* @return array hashmap with only string values
255265
*/
256266
public function getExtras()
257267
{
@@ -434,26 +444,23 @@ public function getBody()
434444
}
435445

436446
/**
437-
* Get the creation date
438-
*
439-
* @return \DateTime
447+
* @return BlockInterface
440448
*/
441-
public function getCreateDate()
449+
public function getAdditionalInfoBlock()
442450
{
443-
return $this->createDate;
451+
return $this->additionalInfoBlock;
444452
}
445453

446454
/**
447-
* Overwrite the creation date manually
448-
*
449-
* On creation of a Page, the createDate is automatically set to the
450-
* current time.
455+
* Set the additional info block for this content. Usually you want this to
456+
* be a container block in order to be able to add several blocks.
451457
*
452-
* @param \DateTime $createDate
458+
* @param BlockInterface $block must be persistable through cascade by the
459+
* persistence layer.
453460
*/
454-
public function setCreateDate(\DateTime $createDate = null)
461+
public function setAdditionalInfoBlock($block)
455462
{
456-
$this->createDate = $createDate;
463+
$this->additionalInfoBlock = $block;
457464
}
458465

459466
/**

Migrator/Phpcr/Page.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ public function migrate($path = '/', $depth = -1)
131131
$page->setBody($data['body']);
132132
}
133133

134-
if (isset($data['create_date'])) {
135-
$page->setCreateDate(date_create_from_format('U', strtotime($data['create_date'])));
136-
}
137-
138134
if (isset($data['publish_start_date'])) {
139135
$page->setPublishStartDate(date_create_from_format('U', strtotime($data['publish_start_date'])));
140136
}

Resources/config/doctrine-phpcr/Page.phpcr.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
<field name="title" type="string" translated="true"/>
1515
<field name="label" type="string" translated="true" nullable="true"/>
1616
<field name="body" type="string" translated="true" nullable="true"/>
17-
<field name="createDate" type="date"/>
17+
<child name="additionalInfoBlock">
18+
<cascade><cascade-persist /></cascade>
19+
</child>
1820
<field name="publishable" type="boolean"/>
1921
<field name="publishStartDate" type="date" nullable="true"/>
2022
<field name="publishEndDate" type="date" nullable="true"/>

Tests/Functional/Doctrine/Phpcr/PageTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public function testPage()
3939
$page->setTitle('Page Title');
4040
$page->setLabel('Page Label');
4141
$page->setBody('This is body');
42-
$page->setCreateDate(new \DateTime('2013-07-05'));
4342
$page->setPublishable(false);
4443
$page->setPublishStartDate(new \DateTime('2013-06-18'));
4544
$page->setPublishEndDate(new \DateTime('2013-06-18'));

UPGRADE-1.1.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
UPGRADE FROM 1.0 TO 1.1
2+
=======================
3+
4+
Removed all custom routing service as RoutingBundle is now flexible enough.
5+
* Move all routing configuration from cmf_simple_cms to cmf_routing.dynamic
6+
* The configuration for locales is not needed anymore. Configuring it on the
7+
cmf_routing is enough.
8+
* The options for the format pattern, trailing slash and locale pattern are
9+
now moved into the route "options" and the Page Document now takes an
10+
array of options in the constructor instead of boolean flags.
11+
12+
The Page document has no `createDate` field anymore. Use the publishStartDate
13+
for this purpose. If you where using the createDate and want to keep that
14+
information, you can move it to the publishStartDate with the following query:
15+
16+
$ php app/console doctrine:phpcr:nodes:update \
17+
--query="SELECT * FROM [nt:unstructured] WHERE [phpcr:class] = \"Symfony\\Cmf\\Bundle\\SimpleCmsBundle\\Doctrine\\Phpcr\\Page\"" \
18+
--apply-closure="if (!\$node->getPublishStartDate()) \$node->setProperty('publishStartDate', \$node->getPropertyValue('createDate'));"

0 commit comments

Comments
 (0)