formmailer Posted December 6, 2011 Share Posted December 6, 2011 I am not sure if the following should be considered as a bug or not, but it was somewhat unwanted: I sorted my news pages by modified date, which would make that, if I modified one page it would be on top again. Now I realized that if someone writes a comment using the comments module, the page is modified as well. In this case I can work with the created date, but I can think of situations where this isn't an option. Would there be a way around this? /Jasper Link to comment Share on other sites More sharing options...
ryan Posted December 6, 2011 Share Posted December 6, 2011 The behavior is intentional. Any time a page is saved (whether just a field from it or the whole thing), the modified date is updated. There isn't currently a way to bypass that. Though if there's demand for it, I'm sure we could find a way. I'm going to marinate on the idea a bit to see if there are any simple solutions that I'm not thinking of yet. But one question would be why wouldn't you want the modified date updated? (preference to only show admin modifications?) I'm just wondering about the broader context, to get a sense of the situations where one would want this disabled. 1 Link to comment Share on other sites More sharing options...
apeisa Posted December 6, 2011 Share Posted December 6, 2011 I am actually using $page->modified to show when page was last updated on few templates. Flagging page as updated when someone adds a comment kind of ruins it. Not actual problem in my case (no comments on those templates) and I am not sure if it is good idea to have exceptions like "$page->modified changes always when one or more fields updates - expect on comments fields". Link to comment Share on other sites More sharing options...
formmailer Posted December 7, 2011 Author Share Posted December 7, 2011 I am actually using $page->modified to show when page was last updated on few templates. Flagging page as updated when someone adds a comment kind of ruins it. This is exactly what i meant, but in my case I do have comments on the page. I agree with apeisa that creating exceptions just for comments might not be the way to go. It might even cause problems for others who use the modified date. Maybe an additional field like $page-admin_modified would be a solution? The best way would of course a change in the comments module (instead of something in core), so that it doesn't change the pages modified date. But I don't think this is possible, is it? Just now it's just the comments module, but we'll probably get more modules that allow visitors to change things in a page (maybe the can place a marker on a map or they canupload a photo) and these modules will have the same issues. /Jasper Link to comment Share on other sites More sharing options...
ryan Posted December 7, 2011 Share Posted December 7, 2011 The best way would of course a change in the comments module (instead of something in core), so that it doesn't change the pages modified date. But I don't think this is possible, is it? That's correct. The 'modified' field is meant as a system field and nothing else in the API has access to change it (or prevent changes to it). I'm thinking I can provide an override for cases where we are just saving a field ($pages->saveField($page, 'field') or $page->save('field')) as opposed to the whole page. I can set it so that if $page->modified < 0, then it'll ignore it when doing the save, leaving the existing modified time in place. Then a module like the Comments module could feasibly tell the $page not to update it's modified date. Link to comment Share on other sites More sharing options...
Nico Knoll Posted December 7, 2011 Share Posted December 7, 2011 Would be great if we could set "modified" and "created" (maybe in the "settings" tab) cause I needed it while I was importing the website of my school from Typo3. Link to comment Share on other sites More sharing options...
formmailer Posted December 7, 2011 Author Share Posted December 7, 2011 That's correct. The 'modified' field is meant as a system field and nothing else in the API has access to change it (or prevent changes to it). I'm thinking I can provide an override for cases where we are just saving a field ($pages->saveField($page, 'field') or $page->save('field')) as opposed to the whole page. I can set it so that if $page->modified < 0, then it'll ignore it when doing the save, leaving the existing modified time in place. Then a module like the Comments module could feasibly tell the $page not to update it's modified date. While thinking about it one more time, it may not be needed to change the behaviour. I could just add a datefield to the template with a default date today and change it manually if the page gets updated afterwards. Or maybe I could make a module that asks if this date should be updated when the page gets saved through the admin. Is there a hook for admin saves? /Jasper Link to comment Share on other sites More sharing options...
apeisa Posted December 7, 2011 Share Posted December 7, 2011 That kind of hook might be easiest to do with javascript, something like soma's page save reminder module. Link to comment Share on other sites More sharing options...
formmailer Posted December 7, 2011 Author Share Posted December 7, 2011 Yes, I was thinking of that one too. I'll take a look at it and "steal some code". ;D Link to comment Share on other sites More sharing options...
ryan Posted December 8, 2011 Share Posted December 8, 2011 You can also detect if a hook is coming from an admin save by checking the value of wire('process') in your $pages->save() hook: <?php $process = wire('process'); if($process && $process->className() == 'ProcessPageEdit') { // this is an admin save } Link to comment Share on other sites More sharing options...
formmailer Posted December 8, 2011 Author Share Posted December 8, 2011 Thanks Ryan. That might be easier (considering my lack of javascript knowledge, which reminds me once again that I should learn it....). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now