diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index 7f58240..0248b71 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -341,6 +341,114 @@ function _field_ui_field_name_exists($value) { } /** + * @see field_ui_field_overview_form_validate() + */ +function field_ui_field_overview_form_submit($form, &$form_state) { + $form_values = $form_state['values']['fields']; + $entity_type = $form['#entity_type']; + $bundle = $form['#bundle']; + $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle); + + $bundle_settings = field_bundle_settings($entity_type, $bundle); + + // Update field weights. + foreach ($form_values as $key => $values) { + if (in_array($key, $form['#fields'])) { + $instance = field_read_instance($entity_type, $key, $bundle); + $instance['widget']['weight'] = $values['weight']; + field_update_instance($instance); + } + elseif (in_array($key, $form['#extra'])) { + $bundle_settings['extra_fields']['form'][$key]['weight'] = $values['weight']; + } + } + + field_bundle_settings($entity_type, $bundle, $bundle_settings); + + $destinations = array(); + + // Create new field. + $field = array(); + if (!empty($form_values['_add_new_field']['field_name'])) { + $values = $form_values['_add_new_field']; + + $field = array( + 'field_name' => $values['field_name'], + 'type' => $values['type'], + 'translatable' => $values['translatable'], + ); + $instance = array( + 'field_name' => $field['field_name'], + 'entity_type' => $entity_type, + 'bundle' => $bundle, + 'label' => $values['label'], + 'widget' => array( + 'type' => $values['widget_type'], + 'weight' => $values['weight'], + ), + ); + + // Create the field and instance. + try { + field_create_field($field); + field_create_instance($instance); + + // Always show the field settings step, as the cardinality needs to be + // configured for new fields. + $destinations[] = $admin_path . '/fields/' . $field['field_name'] . '/field-settings'; + $destinations[] = $admin_path . '/fields/' . $field['field_name']; + + // Store new field information for any additional submit handlers. + $form_state['fields_added']['_add_new_field'] = $field['field_name']; + } + catch (Exception $e) { + drupal_set_message(t('There was a problem creating field %label: !message', array('%label' => $instance['label'], '!message' => $e->getMessage())), 'error'); + } + } + + // Add existing field. + if (!empty($form_values['_add_existing_field']['field_name'])) { + $values = $form_values['_add_existing_field']; + $field = field_info_field($values['field_name']); + if (!empty($field['locked'])) { + drupal_set_message(t('The field %label cannot be added because it is locked.', array('%label' => $values['label'])), 'error'); + } + else { + $instance = array( + 'field_name' => $field['field_name'], + 'entity_type' => $entity_type, + 'bundle' => $bundle, + 'label' => $values['label'], + 'widget' => array( + 'type' => $values['widget_type'], + 'weight' => $values['weight'], + ), + ); + + try { + field_create_instance($instance); + $destinations[] = $admin_path . '/fields/' . $instance['field_name']; + // Store new field information for any additional submit handlers. + $form_state['fields_added']['_add_existing_field'] = $instance['field_name']; + } + catch (Exception $e) { + drupal_set_message(t('There was a problem creating field instance %label: @message.', array('%label' => $instance['label'], '@message' => $e->getMessage())), 'error'); + } + } + } + + if ($destinations) { + $destination = drupal_get_destination(); + $destinations[] = $destination['destination']; + unset($_GET['destination']); + $form_state['redirect'] = field_ui_get_destinations($destinations); + } + else { + drupal_set_message(t('Your settings have been saved.')); + } +} + +/** * Returns the built and processed 'Manage display' form of a bundle. * * The resulting form allows fields and pseudo-fields to be re-ordered. @@ -596,6 +716,7 @@ function field_ui_field_settings_form($form, &$form_state, $instance) { } $form['#entity_type'] = $entity_type; $form['#bundle'] = $bundle; + $form['#field'] = $field; $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save field settings')); @@ -1078,7 +1123,7 @@ function field_ui_field_edit_form_submit($form, &$form_state) { $entity = $form['#entity']; // Merge incoming values into the field. - $field = array_merge($field, $form_state['values']['field']); + $field = array_merge($field, $form_state['values']['instance']); try { field_update_field($field); } diff --git a/core/modules/translation_entity/translation_entity.module b/core/modules/translation_entity/translation_entity.module index b0c8526..437be1e 100644 --- a/core/modules/translation_entity/translation_entity.module +++ b/core/modules/translation_entity/translation_entity.module @@ -558,7 +558,7 @@ function translation_entity_field_extra_fields() { /** * Implements hook_form_FORM_ID_alter(). */ -function translation_entity_form_field_ui_field_edit_form_alter(array &$form, array &$form_state, $form_id) { +function translation_entity_form_field_ui_field_settings_form_alter(array &$form, array &$form_state, $form_id) { $field = $form['#field']; $field_name = $field['field_name']; $translatable = $field['translatable'];