Index: better-formats-defaults-admin-form.tpl.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/better_formats/better-formats-defaults-admin-form.tpl.php,v retrieving revision 1.3.2.6 diff -u -p -r1.3.2.6 better-formats-defaults-admin-form.tpl.php --- better-formats-defaults-admin-form.tpl.php 5 Jun 2009 23:28:55 -0000 1.3.2.6 +++ better-formats-defaults-admin-form.tpl.php 14 Aug 2009 15:04:07 -0000 @@ -21,11 +21,13 @@ drupal_add_tabledrag('node-format-defaults', 'order', 'sibling', 'better-formats-role-node-weight'); drupal_add_tabledrag('comment-format-defaults', 'order', 'sibling', 'better-formats-role-comment-weight'); drupal_add_tabledrag('block-format-defaults', 'order', 'sibling', 'better-formats-role-block-weight'); + drupal_add_tabledrag('cck-format-defaults', 'order', 'sibling', 'better-formats-role-cck-weight'); ?>
' . t('Defaults only affect NEW content NOT existing content.') . '

'; ?> ' . t('Place roles in order of precedence by dragging more important roles to the top.') . '

'; ?>
+
@@ -49,7 +51,8 @@
- + +
@@ -73,7 +76,32 @@
- + + +
+ CCK Defaults + + + + + + + + + + + $data): ?> + + + + + + + + +
role; ?>format_select; ?>weight_select; ?>
+
+
Index: better_formats_cck_text_add.info =================================================================== RCS file: better_formats_cck_text_add.info diff -N better_formats_cck_text_add.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ better_formats_cck_text_add.info 14 Aug 2009 15:04:07 -0000 @@ -0,0 +1,7 @@ +; $Id: better_formats_cck_text_add.info + +name = Better Formats additional CCK text widgets +description = "Adds better format functionality to individual CCK textfields by providing a new text widget" +core = 6.x +dependencies[] = text +dependencies[] = better_formats \ No newline at end of file Index: better_formats_cck_text_add.module =================================================================== RCS file: better_formats_cck_text_add.module diff -N better_formats_cck_text_add.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ better_formats_cck_text_add.module 14 Aug 2009 15:04:07 -0000 @@ -0,0 +1,286 @@ +format] = $format->name; + } + + $key = 'better_formats'; + $form['widget'][$key] = array( + '#type' => 'fieldset', + '#title' => t('Input format settings'), + '#access' => user_access('administer filters'), + '#collapsible' => TRUE, + // Setting collapsed to false because the wieght will not be hidden otherwise + // the fieldset will be collapsed via JS if enabled. + '#collapsed' => FALSE, + '#attributes' => array('class' => 'input-format-settings'), + ); + $allowed_key = $key . '_allowed'; + $form['widget'][$key][$allowed_key] = array( + '#type' => 'checkboxes', + '#title' => t('Allowed formats'), + '#default_value' => variable_get($allowed_key . '_cck_' . $field_name, array()), + '#options' => $format_boxes, + '#description' => t('Limit the formats users have to choose from even if they have permission to use that format. This will NOT allow a user to use a format they do not have access rights to use. It will only hide additional formats they do have access rights to. If no boxes are checked, all formats that the user has permission to use will be allowed.'), + '#attributes' => array('class' => 'bf-allowed-formats'), + ); + + $dform = array( + '#tree' => TRUE, + '#theme' => 'better_formats_defaults_admin_form', + ); + + module_load_include('admin.inc', 'better_formats', 'better_formats_defaults'); + $nform = better_formats_get_role_default_fields('cck', $field_name); + if (count($nform) == 0) { + // get default values for node if not set already + $nform = better_formats_get_role_default_fields_cck(); + } + $form['widget'][$key]['better_formats_defaults'] = array_merge($dform, $nform); + + // Attach our validate and submit handlers. + $form['#validate'][] = 'better_formats_cck_text_add_text_widget_form_validate'; + $form['#submit'][] = 'better_formats_cck_text_add_text_widget_form_submit'; +} + +/** + * Handles validation of the addition to the content field edit form. + */ +function better_formats_cck_text_add_text_widget_form_validate($form, &$form_state) { + module_load_include('admin.inc', 'better_formats', 'better_formats_defaults'); + better_formats_defaults_admin_form_validate($form, $form_state); +} + +/** + * Handles submission of the addition to the content field edit form. + */ +function better_formats_cck_text_add_text_widget_form_submit($form, &$form_state) { + $field_name = $form['#field']['field_name']; + // Remove current db entries. + $sql = "DELETE FROM {better_formats_defaults} + WHERE type='cck/%s'"; + db_query($sql, $field_name); + + // Insert defualt values into DB. + $sql = "INSERT INTO {better_formats_defaults} + VALUES (%d, '%s', %d, %d, %d)"; + foreach ($form_state['values']['better_formats_defaults'] as $key => $values) { + list($type, $rid) = explode('-', $key); + db_query($sql, $rid, 'cck/' . $field_name, $values['format'], 2, $values['weight']); + } + + //save allowed values + variable_set('better_formats_allowed_cck_' .$field_name, $form_state['values']['better_formats_allowed']); +} + +/* + * Function to convert default node formats to cck formats + */ +function better_formats_get_role_default_fields_cck() { + $nform = better_formats_get_role_default_fields('node'); + $cckform = array(); + foreach ($nform as $key => $value) { + list($type, $fieldno) = explode('-', $key); + $cckform['cck-'. $fieldno] = $value; + } + return $cckform; +} + + +/* CCK hooks */ +/** + * Implementation of hook_widget_info(). + */ +function better_formats_cck_text_add_widget_info() { + return array( + 'text_textfield_better_formats' => array( + 'label' => t('Text field using Better Formats module'), + 'field types' => array('text'), + 'multiple values' => CONTENT_HANDLE_CORE, + 'callbacks' => array( + 'default value' => CONTENT_CALLBACK_DEFAULT, + ), + 'module' => 'better_formats_cck_text_add' + ), + 'text_textarea_better_formats' => array( + 'label' => t('Text area using Better Formats module'), + 'field types' => array('text'), + 'multiple values' => CONTENT_HANDLE_CORE, + 'callbacks' => array( + 'default value' => CONTENT_CALLBACK_DEFAULT, + ), + 'module' => 'better_formats_cck_text_add' + ), + ); +} + +/** + * Implementation of FAPI hook_elements(). + * + * Any FAPI callbacks needed for individual widgets can be declared here, + * and the element will be passed to those callbacks for processing. + * + * Drupal will automatically theme the element using a theme with + * the same name as the hook_elements key. + */ +function better_formats_cck_text_add_elements() { + return array( + 'text_textfield_better_formats' => array( + '#input' => TRUE, + '#columns' => array('value'), '#delta' => 0, + '#process' => array('text_textfield_process', 'better_formats_cck_text_add_text_process'), + '#autocomplete_path' => FALSE, + ), + 'text_textarea_better_formats' => array( + '#input' => TRUE, + '#columns' => array('value', 'format'), '#delta' => 0, + '#process' => array('text_textarea_process', 'better_formats_cck_text_add_text_process'), + '#filter_value' => FILTER_FORMAT_DEFAULT, + ), + ); +} + +/** + * Implementation of hook_widget_settings(). + */ +function better_formats_cck_text_add_widget_settings($op, $widget) { + + switch ($op) { + case 'form': + $form = array(); + $rows = (isset($widget['rows']) && is_numeric($widget['rows'])) ? $widget['rows'] : 5; + $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; + if ($widget['type'] == 'text_textfield_better_formats') { + $form['rows'] = array('#type' => 'hidden', '#value' => $rows); + $form['size'] = array( + '#type' => 'textfield', + '#title' => t('Size of textfield'), + '#default_value' => $size, + '#element_validate' => array('_text_widget_settings_size_validate'), + '#required' => TRUE, + ); + } + else { + $form['rows'] = array( + '#type' => 'textfield', + '#title' => t('Rows'), + '#default_value' => $rows, + '#element_validate' => array('_text_widget_settings_row_validate'), + '#required' => TRUE, + ); + $form['size'] = array('#type' => 'hidden', '#value' => $size); + } + return $form; + + case 'save': + return array('rows', 'size'); + } +} + +/** + * Implementation of hook_widget(). + */ +function better_formats_cck_text_add_widget(&$form, &$form_state, $field, $items, $delta = 0) { + $element = array( + '#type' => $field['widget']['type'], + '#default_value' => isset($items[$delta]) ? $items[$delta] : '', + ); + return $element; +} + +/** + * Process an individual element. + * + * Add the Better Formats form + */ +function better_formats_cck_text_add_text_process($element, $edit, $form_state, $form) { + better_formats_set_cck_format($element, $form_state); + return $element; +} + +/** + * FAPI theme for an individual text elements. + * + * The textfield or textarea is already rendered by the + * textfield or textarea themes and the html output + * lives in $element['#children']. Override this theme to + * make custom changes to the output. + * + * $element['#field_name'] contains the field name + * $element['#delta] is the position of this element in the group + */ +function better_formats_cck_text_add_theme() { + return array( + 'text_textarea_better_formats' => array( + 'arguments' => array('element' => NULL), + ), + 'text_textfield_better_formats' => array( + 'arguments' => array('element' => NULL), + ), + ); +} + +function theme_text_textarea_better_formats($element) { + return $element['#children']; +} + +function theme_text_textfield_better_formats($element) { + return $element['#children']; +} + +function better_formats_set_cck_format(&$element, $form_state) { + if (isset($element['format'])) { + $filter_key = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format'; + $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : $element['#default_value'][$filter_key]; + $parents = array_merge($element['#parents'] , array($filter_key)); + $default = better_formats_get_default_format('cck', $element['#field_name']); + // Overwrite format default if new node. + if (!isset($form_state['values']['nid']) || !isset($format)) { + $format = $default; + } + $format = filter_resolve_format($format); + // Set default format for cck textarea. + $element['#value'][$filter_key] = $format; + // Set filter selection form. + $element[$filter_key] = better_formats_filter_form($format, $default, 'CCK field', 'cck_' .$element['#field_name'], 1, $parents); + } +} \ No newline at end of file Index: better_formats_defaults.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/better_formats/better_formats_defaults.admin.inc,v retrieving revision 1.3.2.8 diff -u -p -r1.3.2.8 better_formats_defaults.admin.inc --- better_formats_defaults.admin.inc 31 May 2009 15:24:00 -0000 1.3.2.8 +++ better_formats_defaults.admin.inc 14 Aug 2009 15:04:07 -0000 @@ -49,7 +49,7 @@ function better_formats_defaults_admin_f $admin_roles = better_formats_get_roles_by_perm('administer filters'); foreach ($form_state['values'] as $key => $values) { - if (strpos($key, 'node-') === 0 || strpos($key, 'comment-') === 0 || strpos($key, 'block-') === 0) { + if (strpos($key, 'node-') === 0 || strpos($key, 'comment-') === 0 || strpos($key, 'block-') === 0 || strpos($key, 'cck-') === 0) { list($type, $rid) = explode('-', $key); if (in_array($rid, $admin_roles)) { // Role has the 'administer filters' permission so it can use all formats.