- Posts: 12
COMMUNITY FORUM
Add a default date for 'Finish publishing'
- Chris Lawson
- Topic Author
- Offline
- New Member
Less
More
7 years 2 months ago #164393
by Chris Lawson
Add a default date for 'Finish publishing' was created by Chris Lawson
I have a website that has a lot of zombie content.
I have asked my users to set a 'Finish publishing' date themselves, but they just don't.
I would like to change the K2 Item default value for "Finish publishing' to now + 2 years or something similar so that by default, new items have a content lifespan of some sort.
Can I override the template for the new item form? Or is there some other way I can accomplish this?
cmkl
I have asked my users to set a 'Finish publishing' date themselves, but they just don't.
I would like to change the K2 Item default value for "Finish publishing' to now + 2 years or something similar so that by default, new items have a content lifespan of some sort.
Can I override the template for the new item form? Or is there some other way I can accomplish this?
cmkl
Please Log in or Create an account to join the conversation.
- william white
- Offline
- Platinum Member
Less
More
- Posts: 3722
7 years 1 month ago - 7 years 1 month ago #164396
by william white
Replied by william white on topic Add a default date for 'Finish publishing'
I would start by overiding itemform and testing it with a change to "prove it"
investigate stackoverflow.com/questions/18269556/php-date-add-1-year-to-current-date
manipulate the code in the overrideand test to see what you can get it to do for you
This may not be the correct place but mabee a starting point
You may have to go into the class k2ItemFormDateField to change it
investigate stackoverflow.com/questions/18269556/php-date-add-1-year-to-current-date
manipulate the code in the override
<?php echo JText::_('K2_FINISH_PUBLISHING'); ?>
</td>
<td class="k2ItemFormDateField">
<?php echo $this->lists['publish_down']; ?>
</td>
This may not be the correct place but mabee a starting point
You may have to go into the class k2ItemFormDateField to change it
Last edit: 7 years 1 month ago by william white.
Please Log in or Create an account to join the conversation.
- Chris Lawson
- Topic Author
- Offline
- New Member
Less
More
- Posts: 12
7 years 1 month ago #164403
by Chris Lawson
Replied by Chris Lawson on topic Add a default date for 'Finish publishing'
I wrote a (really bad) little routine that checks to see ifis set and, if it isn't to generate a date two years from now and write it into the value of the form.
But even if a K2 Item's "Finish publishing" date is blank, the array value "publish_down" is set. I can't see what the variable holds. When I view the rendered source of the form, the value for the "publish_down" element is blank.
What am I missing?
cmkl
$this->lists['publish_down']
<?php
$twoyearsout = date('Y-m-d H:i:s',strtotime(date("Y-m-d H:i:s", mktime()) . " + 2 year"));
if (isset($this->lists['publish_down'])) {
$content_sunset = $this->lists['publish_down'];
} else {
$content_sunset = $twoyearsout;
}
?>
<input type="text" data-k2-datetimepicker id="publish_down" name="publish_down" value="<?php echo $content_sunset; ?>" autocomplete="off" />
But even if a K2 Item's "Finish publishing" date is blank, the array value "publish_down" is set. I can't see what the variable holds. When I view the rendered source of the form, the value for the "publish_down" element is blank.
What am I missing?
cmkl
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
7 years 1 month ago #164404
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Add a default date for 'Finish publishing'
What does <?php var_dump($content_sunset) ?> produce?
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Chris Lawson
- Topic Author
- Offline
- New Member
Less
More
- Posts: 12
7 years 1 month ago #164405
by Chris Lawson
Replied by Chris Lawson on topic Add a default date for 'Finish publishing'
For an item that has no Finish publishing date it shows:
For an item with a Finish publishing date it shows:
string(0) ""
For an item with a Finish publishing date it shows:
string(19) "2017-10-31 12:00:00"
Please Log in or Create an account to join the conversation.
- Chris Lawson
- Topic Author
- Offline
- New Member
Less
More
- Posts: 12
7 years 1 month ago #164407
by Chris Lawson
Replied by Chris Lawson on topic Add a default date for 'Finish publishing'
So it's the isset vs !empty thing.
If instead of using isset, I use:
...it works as expected -- existing publish_down dates are retained. Blank ones have a 'default' added that's two years from today.
This is why I call myself a site builder, not a programmer.
If instead of using isset, I use:
if (!empty($this->lists['publish_down'])) {
$content_sunset = $this->lists['publish_down'];
// echo $this->lists['publish_down'];
} else {
$content_sunset = $twoyearsout;
}
...it works as expected -- existing publish_down dates are retained. Blank ones have a 'default' added that's two years from today.
This is why I call myself a site builder, not a programmer.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
7 years 1 month ago #164423
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Add a default date for 'Finish publishing'
isset($this->lists) will not work, it is best to check !empty() or $this->lists !== '' as you have already done :)
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.