--- filterbynodetype.module 2007-06-11 00:55:25.000000000 -0500 +++ filterbynodetype.module.patched 2007-10-30 18:33:50.000000000 -0600 @@ -29,47 +29,61 @@ function filterbynodetype_menu($may_cach */ function filterbynodetype_form_alter($form_id, &$form) { if (isset($form['type']) && 'node-form' == $form['#id']) { - $type = $form['type']['#value']; - $formats =& $form['body_filter']['format']; - foreach (element_children($formats) as $element) { - if (! variable_get('filterbynodetype_' . $formats[$element]['#return_value'] . '_' . $type, 1)) { - unset($formats[$element]); - } - } - - if (2 == count(element_children($formats))) { // 1 format and 1 extra item for the link - // If there's only one filter left, fold it down to just the description - $formats = $form['body_filter']['format']; - unset($form['body_filter']['format']); - // We don't know what the IDs are of the two fields, so we have to iterate to get them. - foreach (element_children($formats) as $element) { - if (isset($formats[$element]['#title'])) { - // This is a filter, so we assign it to the filter set as the only option. - $form['body_filter']['format'][$element] = array( - '#type' => 'value', - '#value' => $element, - '#parents' => array('format'), - ); - $form['body_filter']['format']['format'] = array( // I have no idea why it uses this structure, but this is what filter.module does. - '#type' => 'item', - '#description' => $formats[$element]['#description'], - ); - } - else { - // It's the guidelines text. - $form['body_filter']['format']['guidelines_link'] = array( - '#value' => $formats[$element]['#value'], - ); - } - } - } - if (1 == count(element_children($formats))) { // 1 extra item for the link, which means there's no filters left - // Do nothing. The form becomes unsubmittable all on its own. - } - } + $type = $form['type']['#value']; + // process body + if (isset($form['body_filter'])) { + _filterbynodetype_form_alter_helper($type, $form['body_filter']['format'], 'body_filter'); + } + + // process cck text fields + if (module_exists('content') && module_exists('text')) { + $fields = db_query("SELECT field_name FROM {node_field_instance} WHERE type_name = '$type' AND widget_type = 'text';"); + while($field = db_fetch_object($fields)) { + foreach (element_children($form[$field->field_name]) as $element) { + if (isset($form[$field->field_name][$element]['format'])) { + _filterbynodetype_form_alter_helper($type, $form[$field->field_name][$element]['format'], $field->field_name); + } + } + } + } + } } +// helper function for filterbynodetype_form_alter() +function _filterbynodetype_form_alter_helper($type, &$formats, $form_elt_name) { + foreach (element_children($formats) as $element) { + if (! variable_get('filterbynodetype_' . $formats[$element]['#return_value'] . '_' . $type, 1)) { + unset($formats[$element]); + } + } + + if (2 == count(element_children($formats))) { // 1 format and 1 extra item for the link + // We don't know what the IDs are of the two fields, so we have to iterate to get them. + foreach (element_children($formats) as $element) { + if (isset($formats[$element]['#title'])) { + $formats['#access'] = false; + $formats[$element]['#default_value'] = $element; + } + } + } + elseif (1 == count(element_children($formats))) { // 1 extra item for the link, which means there's no filters left + // Do nothing. The form becomes unsubmittable all on its own. + } + else { + // check if the default input format has not been removed, and then set the first one as default + $default_filter = variable_get('filter_default_format',0); + if (!isset($formats[$default_filter])) { + $num = false; + foreach (element_children($formats) as $element) { + if (isset($formats[$element]['#title'])) { + if (!$num) $num = $element; + $formats[$element]['#default_value'] = $num; + } + } + } + } +} function filterbynodetype_settings() {