Any plans here? It looks like it would be pretty easy.

Comments

gloomcheng’s picture

StatusFileSize
new8.25 KB

There is my first try to port module to Drupal 7, but I'm newbie for module development so that couldn't fix some errors after rewrite this module. The error message was "Fatal error: Call to undefined function _content_widget_types()".

Does someone know how to fix this error? How could I get field widget type on Drupal 7?
Sorry for my poor English writing, you could ask me to description detail for this issue if you didn't know what I saying. And I really need your help, please.

gloomcheng’s picture

StatusFileSize
new7.99 KB

Dears,

I've rewrite the basic function of Required for Publishing module as attachment file for 5 hours effort.
Now you could set fields as required for publishing at each field settings page after enabled this module on Drupal 7.

This version really very initial and lack of full functionality, it still have some bugs need to report/fix.
There is an issue for this version that Undefined Index alert message, like:

1. Notice: Undefined index: #node_edit_form in required_for_pub_element_process() (line 97 of public_html/sites/all/modules/custom/required_for_pub/required_for_pub.module) shown on field settings page like admin/structure/types/manage/[node-type]/fields/[field_name]

2. Notice: Undefined index: log in required_for_pub_element_process() (line 97 of public_html/sites/all/modules/custom/required_for_pub/required_for_pub.module) shown on node edit page like node/[nid]/edit or node/add/[node-type]

I guess this problem cause by hook_element_info() below, the question is how could I pass fields only need process required_for_pub_element_process function instead of pass all fields?

/**
 * Implements of hook_element_info().
 */
function required_for_pub_element_info() {
  // ToDo: $element must be a field then pass to process.
  // Because not every element has #field_name.
  $types['textfield'] = array(
    '#input' => TRUE,
    '#process' => array('required_for_pub_element_process'),
    '#element_validate' => array('required_for_pub_element_validate'),
    '#post_render' => array('required_for_pub_element_required'),
	  '#required_for_pub' => FALSE,
  );
  $types['textarea'] = array(
    '#input' => TRUE,
    '#process' => array('required_for_pub_element_process'),
    '#element_validate' => array('required_for_pub_element_validate'),
    '#post_render' => array('required_for_pub_element_required'),
	  '#required_for_pub' => FALSE,
  );
  return $types;
}

/**
 * Form element process function to add required for publishing.
 */
function required_for_pub_element_process($element, &$form_state, $complete_form) {
  // Do nothing if it's not a node editing form or it required_for_pub is not enabled in this field.
  if ($complete_form['#node_edit_form'] != TRUE || !$form_state['field'][$element['#parents'][0]]['und']['instance']['required_for_pub']) {
    return $element;
  }
  // Set the #required_for_pub property on the element itself.
  if ($element['#required_for_pub'] == FALSE && isset($form_state['field'][$element['#parents'][0]])) {
    $element['#required_for_pub'] = $form_state['field'][$element['#parents'][0]]['und']['instance']['required_for_pub'] == 1 ? TRUE : FALSE;
  }
  return $element;
}
gloomcheng’s picture

StatusFileSize
new7.98 KB

Dears,

I've fixed the "Undefined index" error from previous comment as attachment files.
This version of module could only be used in specific scenario that:
1. Enabled Save & Edit Module, and hidden default Save button, rename Publish button to 'Submit'.
2. Fields enabled required for publishing option will validate when click 'Submit' button, and only validated when you submit node.
3. Validation mechanism only effect on field type is textfield or textarea.

If you test this module and find some bugs, please file a issues here let me know, appreciate your kindly help.

eaton’s picture

Any updated status on this one?

It looks like there hasn't been much work on the project since the D6 days, this would be a real boost for D7 sites as well.

xbrianx’s picture

Is there anything like this for D7 this seems like such a great advantage for creating nodes with many fields.

dooug’s picture

An alternative possible solution for this in D7 is the Save Draft module with the patch: #1786442: Allow saving drafts with missing required fields. That will allow to save an unpublished node without filling in all required fields. Though it is all or nothing for required fields.

mrf’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new13.18 KB

Here is #3 in patch format for your reviewing pleasure.

mrf’s picture

We've been putting quite a bit of work into the D7 port.

https://github.com/chapter-three/require-to-publish

Pull request welcome!

Dentorat’s picture

I downloaded #8 from github and I can't seem to modify the node after it's been published, I'm looking through it right now, but nothing so far