diff --git a/content.install b/content.install old mode 100644 new mode 100755 index 86d1d2a..42c7cfd --- a/content.install +++ b/content.install @@ -80,7 +80,7 @@ function content_types_install() { * Implementation of hook_install(). */ function content_install() { - variable_set('content_schema_version', 6009); + variable_set('content_schema_version', 6011); drupal_install_schema('content'); } @@ -153,6 +153,7 @@ function content_schema() { 'widget_settings' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE, 'serialize' => TRUE), 'display_settings' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE, 'serialize' => TRUE), 'description' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE), + 'minimum_widgets' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 2), 'widget_module' => array('type' => 'varchar', 'length' => 127, 'not null' => TRUE, 'default' => ''), 'widget_active' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0), ), @@ -617,4 +618,19 @@ function content_update_6010(&$sandbox) { $ret['#finished'] = 1 - count($sandbox['tables']) / $sandbox['count']; } return $ret; -} \ No newline at end of file +} + +/** + * Add 'minimum_widgets' property for fields. + */ +function content_update_6011() { + if ($abort = content_check_update()) { + return $abort; + } + + $ret = array(); + drupal_load('module', 'content'); + db_add_field($ret, content_instance_tablename(), 'minimum_widgets', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 2)); + variable_set('content_schema_version', 6011); + return $ret; +} diff --git a/content.module b/content.module old mode 100644 new mode 100755 diff --git a/includes/content.admin.inc b/includes/content.admin.inc old mode 100644 new mode 100755 index 040b468..62758c0 --- a/includes/content.admin.inc +++ b/includes/content.admin.inc @@ -1054,6 +1054,14 @@ function content_field_edit_form(&$form_state, $type_name, $field_name) { '#required' => FALSE, ); + $form['widget']['minimum_widgets'] = array( + '#type' => 'select', + '#title' => t('Number of widgets'), + '#description' => t('The number of widgets showing on the input form when there\'s no value entered, if this field takes unlimited values.'), + '#options' => drupal_map_assoc(range(1,10)), + '#default_value' => $form['#field']['widget']['minimum_widgets'], + ); + // Add handling for default value if not provided by field. if (content_callback('widget', 'default value', $field) == CONTENT_CALLBACK_DEFAULT) { diff --git a/includes/content.crud.inc b/includes/content.crud.inc index 4e9178c..61d196b 100644 --- a/includes/content.crud.inc +++ b/includes/content.crud.inc @@ -73,6 +73,7 @@ function content_instance_default_values($field_name, $type_name, $widget_type) 'weight' => 0, 'label' => $field_name, 'description' => '', + 'minimum_widgets' => 2, 'widget_type' => $widget_type, 'widget_module' => $module, 'display_settings' => array(), @@ -111,6 +112,7 @@ function content_field_instance_expand($field) { $field['widget']['label'] = !empty($field['label']) ? $field['label'] : $field['field_name']; $field['widget']['weight'] = !empty($field['weight']) ? $field['weight'] : 0; $field['widget']['description'] = !empty($field['description']) ? $field['description'] : ''; + $field['widget']['minimum_widgets'] = !empty($field['minimum_widgets']) ? $field['minimum_widgets'] : 2; if (!empty($field['widget_type'])) { $field['widget']['type'] = $field['widget_type']; @@ -125,6 +127,7 @@ function content_field_instance_expand($field) { unset($field['weight']); unset($field['label']); unset($field['description']); + unset($field['minmum_widgets']); unset($field['widget_module']); unset($field['widget_settings']); @@ -152,6 +155,7 @@ function content_field_instance_collapse($field) { $field['weight'] = !empty($field['widget']['weight']) ? $field['widget']['weight'] : 0; $field['label'] = !empty($field['widget']['label']) ? $field['widget']['label'] : $field['field_name']; $field['description'] = !empty($field['widget']['description']) ? $field['widget']['description'] : ''; + $field['minimum_widgets'] = !empty($field['widget']['minimum_widgets']) ? $field['widget']['minimum_widgets'] : 2; $field['type_name'] = !empty($field['type_name']) ? $field['type_name'] : ''; if (!empty($field['widget']['module'])) { @@ -169,6 +173,7 @@ function content_field_instance_collapse($field) { unset($field['widget_settings']['weight']); unset($field['widget_settings']['label']); unset($field['widget_settings']['description']); + unset($field['widget_settings']['minimum_widgets']); unset($field['widget_settings']['module']); unset($field['widget']); return $field; diff --git a/includes/content.node_form.inc b/includes/content.node_form.inc old mode 100644 new mode 100755 index be339aa..8ecc3e3 --- a/includes/content.node_form.inc +++ b/includes/content.node_form.inc @@ -150,21 +150,28 @@ function content_multiple_value_form(&$form, &$form_state, $field, $items) { $field_name = $field['field_name']; switch ($field['multiple']) { - case 0: + case 0: // 1 field, no multiple $max = 0; break; - case 1: - $filled_items = content_set_empty($field, $items); + case 1: // unlimited + $filled_items = content_set_empty($field, $items); + // make the count different for no item (filled with an empty item by content_set_empty) and 1 item with data + $hook_is_empty = $field['module'] .'_content_is_empty'; + if (count($items) == 1 && $hook_is_empty($items[0], $field)) { + $minimum_item_count = $field['widget']['minimum_widgets'] - 1; + } + else{ + $minimum_item_count = count($items); + } $current_item_count = isset($form_state['item_count'][$field_name]) ? $form_state['item_count'][$field_name] - : count($items); + : $minimum_item_count; // We always want at least one empty icon for the user to fill in. $max = ($current_item_count > count($filled_items)) ? $current_item_count - 1 : $current_item_count; - break; - default: + default: // fixed number of $field['multiple'] fields $max = $field['multiple'] - 1; break; }