'link', '#title' => t('replace'), '#href' => $admin_path . '/fields/replace/' . $field_name, '#options' => array('attributes' => array('title' => t('Replace %field with a field instance.', array('%field' => $field_name)))), ); } else { $form['fields'][$field_name]['field_replacement'] = array(); } } } } /** * Generate a field replacement form. */ function title_field_replacement_form($form, $form_state, $entity_type, $bundle, $field_name) { $bundle_name = field_extract_bundle($entity_type, $bundle); $entity_info = entity_get_info($entity_type); $info = $entity_info['field replacement'][$field_name]; $instance = field_info_instance($entity_type, $info['field']['field_name'], $bundle_name); $enabled = !empty($instance); $form['#entity_type'] = $entity_type; $form['#bundle'] = $bundle_name; $form['#field_name'] = $field_name; $form['enabled'] = array( '#type' => 'checkbox', '#title' => t('Replace %field with a field instance.', array('%field' => $field_name)), '#description' => t('If this is enabled the %field legacy field will be replaced with a regular field and will disappear from the Manage fields page. It will get back if the replacing field instance is deleted.', array('%field' => $field_name)), '#default_value' => $enabled, '#disabled' => $enabled, ); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save settings')); return $form; } /** * Process field replacement form subissions. */ function title_field_replacement_form_submit($form, &$form_state) { if ($form_state['values']['enabled'] != $form['enabled']['#default_value']) { if (title_field_replacement_toggle($form['#entity_type'], $form['#bundle'], $form['#field_name'])) { drupal_set_message(t('%field replaced with a field instance.', array('%field' => $form['#field_name']))); title_field_replacement_batch_set($form['#entity_type'], $form['#bundle'], $form['#field_name']); } else { drupal_set_message(t('Field replacement removed.')); } } $form_state['redirect'] = _field_ui_bundle_admin_path($form['#entity_type'], $form['#bundle']) . '/fields'; }