To make a listing have an expiry date, the existing code is:

  $form['required']['job_posting_expires'] = array(
    '#type' => 'radios',
    '#title' => t('Expires'),
    '#description' => t('Choose whether you want this job posting to have an
      application deadline associated with it. Expiring nodes are automatically 
      de-activated and purged from display views once the specified deadline 
      passes. Pick false if you want this posting to remain active until manually 
      removed.'),
    '#options' => array(1 => t('True'), 0 => t('False')),
    '#required' => TRUE,
    '#default_value' => isset($node->job_posting_expires) ? $node->job_posting_expires : 1,
    '#weight' => -6,
  );

And, to make it hidden I have it changed to this:

  $form['required']['job_posting_expires'] = array(
    '#type' => 'hidden',
    '#value' => isset($node->job_posting_expires) ? $node->job_posting_expires : 1,
  );

Once the job listing has reached its deadline it still exists (although, people can not apply for it). But, is there a way to have it disappear forever at deadline?

Have I done something wrong that would effect the job not to be 'de-activated and purged' from display views as it states in the description in original code?

Comments

Andy Galaxy’s picture

Sorry, make it:

And, to make it hidden I have it changed to this:

 $form['required']['job_posting_expires'] = array(
    '#type' => 'hidden',
    '#value' => True,
  );
gmarus’s picture

That comment you're referring to regarding 'display views' only applies to the built-in node *listings* provided via the job_posting_list_nodes() and job_posting_block() functions which contain SQL to limit their result set based on whether a particular node is 'expirable' (sic?) and/or its deadline has passed.

The node display itself is not automatically deleted from the system and remains until it's removed manually just like any other node type. I did it this way partly to avoid 404s for search engines and anyone who bookmarks a particular listing before it expires. Many organizations might prefer to have these job postings remain in a sort of archival state anyway.

On a side note, if you want the job_posting_expires field to be 'read-only' you might consider using the 'value' type instead of 'hidden' so that it doesn't even appear in the markup:

$form['required']['job_posting_expires'] = array(
    '#type' => 'value',
    '#value' => isset($node->job_posting_expires) ? $node->job_posting_expires : 1,
);
Andy Galaxy’s picture

Thanks gmarus. You are a lifesaver. I do understand...

As I have taken out #type' => 'radios' and #options' => array(1 => t('Yes'), 0 => t('No')), would it not be

$form['required']['job_posting_expires'] = array(
    '#type' => 'value',
    '#value' => True,
);
gmarus’s picture

Yes. The ternary expression isn't needed since type is always going to be the same value. I don't think it matters much whether you use True or 1 since the value is ultimately stored in mysql as an int anyway (not sure about postgres, though so maybe True is slightly better) and PHP does type conversion.

Andy Galaxy’s picture

Thanks gmarus. This module is great.

Andy Galaxy’s picture

Hi gmarus
Looks like the client wants the job to "disappear" automatically once reaching deadline. Is this possible?
Regards

Andy Galaxy’s picture

I ended up paying someone to do this. Don't ask me what he did, but it works. All posts "unpublish" when deadline is reached.

gmarus’s picture

Status: Active » Closed (fixed)