Disable node_expire completely for certain node types

aaronbauman - August 11, 2009 - 20:55
Project:Node Expire
Version:6.x-2.03
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs work
Issue tags:content types, cron, default date, disable, enable, patch
Description

For some node types, I don't want any node_expire hooks to fire. Ever.

Even when I empty all the default values from the fields, node_expire field still shows up on node forms for nodes which have no business expiring, e.g. content_profile nodes.

This patch adds a checkbox to the admin node_type edit form to turn off node_expire by content type.

AttachmentSize
node_expire.patch2.3 KB

#1

david.lukac - August 27, 2009 - 16:26

Hi,

I installed the patch but it causes following problem: when editing any content type, by default the "Disable node expire for this content type." is allways checked, even after saving this content type after unchecking the box. Of course node_expire settings never appear when creating/editing content.

Thanks,
David

#2

rvallejo - October 7, 2009 - 05:47

I think the problem with the disabled setting always being checked is because its not saving the value into the node_expire_ntypes array. You need to add the following to the end of the "if" statement in node_expire.ntype.inc file: $ntypes[$form_state['values']['type']]['disable'] = $form_state['values']['node_expire_disable'];

I think that should do it. I'm trying to modify this a little bit to make it an enable function rather than disable, and automatically unsetting the required value if disabled. Not much of a programmer myself, but I'll post it up if it'll be helpful for others.

#3

rvallejo - October 7, 2009 - 08:22
Status:active» needs work

Alright, here's my stab at a patch. This compiles a few fixes - disabling/enabling for certain node types as well as cron issues (patch at http://drupal.org/node/426636#comment-1651286) and the empty default issue (patch at http://drupal.org/node/405608, with changes in comment #11). Also fixed a couple of small grammatical errors, and added a line to the description on node creation to let users know if/what the limit on the expiration date is.

Its functional for what I'm doing, but it is my first patch and I'm not really much of a programmer or anything so there may very well be better ways to get the same results.

And just as a note, I made it so when Expiration is disabled, the Default and Max fields don't show on content type configuration pages. I thought it might be good to use javascript to show these when enabling Expiration, but for now you'd have to click Enabled or Required, save, and go back to edit the content type to get the forms. To keep the forms at all times, just add the lines below after where the patch says to delete from node_expire.module (line 71), and ignore the rest of the changes for that file (*don't delete where it says to delete).

+ $form['workflow']['node_expire_settings'] = array(
+ '#type' => 'radios',
+ '#title' => t('Node Expire'),
+ '#default_value' => variable_get('node_expire_settings_'. $form['#node_type']->type, 0),
+ '#options' => array(t('Disabled'), t('Enabled'), t('Required')),
+ );

AttachmentSize
node_expire.patch 7.86 KB

#4

rvallejo - October 9, 2009 - 04:17

Additional note on the last piece of my comment: to show default and max expiration date fields all the time, add the new form array (node_expire_settings) to the beginning of the section, and delete the last form array (node_expire_required). So, it would look like this:

+ $form['workflow']['node_expire_settings'] = array(
+ '#type' => 'radios',
+ '#title' => t('Node Expire'),
+ '#default_value' => variable_get('node_expire_settings_'. $form['#node_type']->type, 0),
+ '#options' => array(t('Disabled'), t('Enabled'), t('Required')),
+ );
$form['workflow']['node_expire'] = array(
'#title' => t('Expiration Date'),
'#description' => t('Default date to consider the node expired.') .' '. t('Format: PHP strtotime format.') .' '. t('Leave it blank if this content type never expires.'),
'#type' => 'textfield',
'#default_value' => empty($ntypes[$ntype]['default']) ? '' : $ntypes[$ntype]['default'],
);
$form['workflow']['node_expire_max'] = array(
'#title' => t('Expiration Date Limit'),
'#description' => t('The max date to consider the node expired.') .' '. t('Format: PHP strtotime format.') .' '. t('Leave it blank if this there is no limit date.'),
'#type' => 'textfield',
'#default_value' => empty($ntypes[$ntype]['max']) ? '' : $ntypes[$ntype]['max'],
);
- $form['workflow']['node_expire_required'] = array(
- '#title' => t('Expiration Date Required'),
- '#type' => 'checkbox',
- '#default_value' => !empty($ntypes[$ntype]['required']),
- );

#5

bomarmonk - October 26, 2009 - 06:21

I tried this patch against a clean copy of 6.x node_expire, but I get a patch malformed message. Maybe I'm doing the patch command wrong? Could you post a complete zip of your working module as the official dev verion is fairly useless right now.

#6

aaronbauman - October 26, 2009 - 13:51

I switched to scheduler module, fwiw
Does everything I used node_expire for, and then some.

#7

rvallejo - October 28, 2009 - 18:50

Its likely I didn't make the patch right, but here's a zip of the patched module I'm working with.

AttachmentSize
node_expire.zip 15.53 KB

#8

marshallexcavating - November 7, 2009 - 05:09

Thank you rvallejo (#7) for attaching the zipped patch; it works great for me.

#9

marshallexcavating - November 17, 2009 - 01:07

I spoke to soon. I have the node_expire disabled on one of my content node types but after each cron they get unpublished. when i republish them the attached file shows the error.

Any help would be appreciated.

AttachmentSize
Screenshot.png 92.09 KB
 
 

Drupal is a registered trademark of Dries Buytaert.