1

By default, every entry has an expiration date field allowing the editor to expire an entry. I'm currently working on an application with some sections where expiring an entry doesn't make much sense and could break some parts of the site. So I would like to remove the "expiration date" field from some sections, to prevent someone accidentally setting an expiration date, or setting the field believing it to work in a different way than it actually does.

I've found no way to properly remove the field, at least there's no option for that in the section settings. I could just hide the field with CSS and JS, but of course that's not a solid solution. I would prefer a solution that's enforced on API level. Maybe it can be done with a hook? Or is there a better solution for this (except building a custom element type from scratch)?

2

I'm not aware of any straightforward way to remove that field from the Entry form. You might want to consider creating a small site module, adding some logic in an event handler to re-write/remove the contents of the expiration date as necessary?

3
  • Thanks, that's a possible avenue. So use CSS to hide the field in the editor and use custom validations to prevent the entry from being saved if the postdate is not empty. That should work at least. Though I'm worried the postdate might still show up elsewhere ... it would be great if it was possible to remove the field "natively" altogether. – MoritzLost May 4 at 12:42
  • postDate is not the same as expiryDate, but I'll assume you know that and your namings are mixed up! I don't even think I'd validate the expiration date - if you really don't want it to be set through CP, have the module set the entry's expiryDate to null in the EVENT_BEFORE_SAVE event. You can't do this with postDate, Craft will set it to current date/time. – Andy May 4 at 14:24
  • Yeah I got that mixed up, I meant the expiration date, just corrected it in the question, thanks! Clearing the expiryDate in a hook is probably the way to go – of course I'll have to hide the field in CSS then, to make sure nobody tries to set it and get frustrated. Thanks for the suggestions! – MoritzLost May 6 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.