#569072 by rcross and yched: Clean field_attach_()* namespace by renaming and moving non-crud functions.
							parent
							
								
									0d8adb439d
								
							
						
					
					
						commit
						b47e68011f
					
				| 
						 | 
					@ -182,7 +182,7 @@ function _field_invoke($op, $obj_type, $object, &$a = NULL, &$b = NULL, $options
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Iterate through the object's field instances.
 | 
					  // Iterate through the object's field instances.
 | 
				
			||||||
  $return = array();
 | 
					  $return = array();
 | 
				
			||||||
  list(, , $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					  list(, , $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if ($options['deleted']) {
 | 
					  if ($options['deleted']) {
 | 
				
			||||||
    $instances = field_read_instances(array('bundle' => $bundle), array('include_deleted' => $options['deleted']));
 | 
					    $instances = field_read_instances(array('bundle' => $bundle), array('include_deleted' => $options['deleted']));
 | 
				
			||||||
| 
						 | 
					@ -299,7 +299,7 @@ function _field_invoke_multiple($op, $obj_type, $objects, &$a = NULL, &$b = NULL
 | 
				
			||||||
  // is deleted, so we reference field data via the
 | 
					  // is deleted, so we reference field data via the
 | 
				
			||||||
  // $object->$field_name property.
 | 
					  // $object->$field_name property.
 | 
				
			||||||
  foreach ($objects as $object) {
 | 
					  foreach ($objects as $object) {
 | 
				
			||||||
    list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					    list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ($options['deleted']) {
 | 
					    if ($options['deleted']) {
 | 
				
			||||||
      $instances = field_read_field(array('bundle' => $bundle, array('include_deleted' => $options['deleted'])));
 | 
					      $instances = field_read_field(array('bundle' => $bundle, array('include_deleted' => $options['deleted'])));
 | 
				
			||||||
| 
						 | 
					@ -489,7 +489,7 @@ function field_attach_form($obj_type, $object, &$form, &$form_state, $langcode =
 | 
				
			||||||
  $form += (array) _field_invoke_default('form', $obj_type, $object, $form, $form_state, $options);
 | 
					  $form += (array) _field_invoke_default('form', $obj_type, $object, $form, $form_state, $options);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Add custom weight handling.
 | 
					  // Add custom weight handling.
 | 
				
			||||||
  list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					  list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
  $form['#attached']['css'][] = drupal_get_path('module', 'field') . '/theme/field.css';
 | 
					  $form['#attached']['css'][] = drupal_get_path('module', 'field') . '/theme/field.css';
 | 
				
			||||||
  $form['#pre_render'][] = '_field_extra_weights_pre_render';
 | 
					  $form['#pre_render'][] = '_field_extra_weights_pre_render';
 | 
				
			||||||
  $form['#extra_fields'] = field_extra_fields($bundle);
 | 
					  $form['#extra_fields'] = field_extra_fields($bundle);
 | 
				
			||||||
| 
						 | 
					@ -608,7 +608,7 @@ function field_attach_load($obj_type, $objects, $age = FIELD_LOAD_CURRENT, $opti
 | 
				
			||||||
    if ($cache_write) {
 | 
					    if ($cache_write) {
 | 
				
			||||||
      foreach ($queried_objects as $id => $object) {
 | 
					      foreach ($queried_objects as $id => $object) {
 | 
				
			||||||
        $data = array();
 | 
					        $data = array();
 | 
				
			||||||
        list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					        list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
        $instances = field_info_instances($bundle);
 | 
					        $instances = field_info_instances($bundle);
 | 
				
			||||||
        foreach ($instances as $instance) {
 | 
					        foreach ($instances as $instance) {
 | 
				
			||||||
          $data[$instance['field_name']] = $queried_objects[$id]->{$instance['field_name']};
 | 
					          $data[$instance['field_name']] = $queried_objects[$id]->{$instance['field_name']};
 | 
				
			||||||
| 
						 | 
					@ -802,7 +802,7 @@ function field_attach_insert($obj_type, $object) {
 | 
				
			||||||
  // Field storage module saves any remaining unsaved fields.
 | 
					  // Field storage module saves any remaining unsaved fields.
 | 
				
			||||||
  module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_write', $obj_type, $object, FIELD_STORAGE_INSERT, $skip_fields);
 | 
					  module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_write', $obj_type, $object, FIELD_STORAGE_INSERT, $skip_fields);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  list($id, $vid, $bundle, $cacheable) = field_attach_extract_ids($obj_type, $object);
 | 
					  list($id, $vid, $bundle, $cacheable) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
  if ($cacheable) {
 | 
					  if ($cacheable) {
 | 
				
			||||||
    cache_clear_all("field:$obj_type:$id", 'cache_field');
 | 
					    cache_clear_all("field:$obj_type:$id", 'cache_field');
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -830,7 +830,7 @@ function field_attach_update($obj_type, $object) {
 | 
				
			||||||
  // Field storage module saves any remaining unsaved fields.
 | 
					  // Field storage module saves any remaining unsaved fields.
 | 
				
			||||||
  module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_write', $obj_type, $object, FIELD_STORAGE_UPDATE, $skip_fields);
 | 
					  module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_write', $obj_type, $object, FIELD_STORAGE_UPDATE, $skip_fields);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  list($id, $vid, $bundle, $cacheable) = field_attach_extract_ids($obj_type, $object);
 | 
					  list($id, $vid, $bundle, $cacheable) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
  if ($cacheable) {
 | 
					  if ($cacheable) {
 | 
				
			||||||
    cache_clear_all("field:$obj_type:$id", 'cache_field');
 | 
					    cache_clear_all("field:$obj_type:$id", 'cache_field');
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -855,7 +855,7 @@ function field_attach_delete($obj_type, $object) {
 | 
				
			||||||
    $function($obj_type, $object);
 | 
					    $function($obj_type, $object);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  list($id, $vid, $bundle, $cacheable) = field_attach_extract_ids($obj_type, $object);
 | 
					  list($id, $vid, $bundle, $cacheable) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
  if ($cacheable) {
 | 
					  if ($cacheable) {
 | 
				
			||||||
    cache_clear_all("field:$obj_type:$id", 'cache_field');
 | 
					    cache_clear_all("field:$obj_type:$id", 'cache_field');
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -1089,7 +1089,7 @@ function field_attach_view($obj_type, $object, $build_mode = 'full', $langcode =
 | 
				
			||||||
  $output = _field_invoke_default('view', $obj_type, $object, $build_mode, $null, $options);
 | 
					  $output = _field_invoke_default('view', $obj_type, $object, $build_mode, $null, $options);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Add custom weight handling.
 | 
					  // Add custom weight handling.
 | 
				
			||||||
  list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					  list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
  $output['#attached']['css'][] = drupal_get_path('module', 'field') . '/theme/field.css';
 | 
					  $output['#attached']['css'][] = drupal_get_path('module', 'field') . '/theme/field.css';
 | 
				
			||||||
  $output['#pre_render'][] = '_field_extra_weights_pre_render';
 | 
					  $output['#pre_render'][] = '_field_extra_weights_pre_render';
 | 
				
			||||||
  $output['#extra_fields'] = field_extra_fields($bundle);
 | 
					  $output['#extra_fields'] = field_extra_fields($bundle);
 | 
				
			||||||
| 
						 | 
					@ -1119,7 +1119,7 @@ function field_attach_view($obj_type, $object, $build_mode = 'full', $langcode =
 | 
				
			||||||
 *   values.
 | 
					 *   values.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_attach_preprocess($obj_type, $object, $element, &$variables) {
 | 
					function field_attach_preprocess($obj_type, $object, $element, &$variables) {
 | 
				
			||||||
  list(, , $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					  list(, , $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  foreach (field_info_instances($bundle) as $instance) {
 | 
					  foreach (field_info_instances($bundle) as $instance) {
 | 
				
			||||||
    $field_name = $instance['field_name'];
 | 
					    $field_name = $instance['field_name'];
 | 
				
			||||||
| 
						 | 
					@ -1243,85 +1243,6 @@ function field_attach_delete_bundle($bundle) {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Helper function to extract id, vid, and bundle name from an object.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param $obj_type
 | 
					 | 
				
			||||||
 *   The type of $object; e.g. 'node' or 'user'.
 | 
					 | 
				
			||||||
 * @param $object
 | 
					 | 
				
			||||||
 *   The object from which to extract values.
 | 
					 | 
				
			||||||
 * @return
 | 
					 | 
				
			||||||
 *   A numerically indexed array (not a hash table) containing these
 | 
					 | 
				
			||||||
 *   elements:
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 *   0: primary id of the object
 | 
					 | 
				
			||||||
 *   1: revision id of the object, or NULL if $obj_type is not versioned
 | 
					 | 
				
			||||||
 *   2: bundle name of the object
 | 
					 | 
				
			||||||
 *   3: whether $obj_type's fields should be cached (TRUE/FALSE)
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
function field_attach_extract_ids($obj_type, $object) {
 | 
					 | 
				
			||||||
  // TODO D7 : prevent against broken 3rd party $node without 'type'.
 | 
					 | 
				
			||||||
  $info = field_info_fieldable_types($obj_type);
 | 
					 | 
				
			||||||
  // Objects being created might not have id/vid yet.
 | 
					 | 
				
			||||||
  $id = isset($object->{$info['object keys']['id']}) ? $object->{$info['object keys']['id']} : NULL;
 | 
					 | 
				
			||||||
  $vid = ($info['object keys']['revision'] && isset($object->{$info['object keys']['revision']})) ? $object->{$info['object keys']['revision']} : NULL;
 | 
					 | 
				
			||||||
  // If no bundle key provided, then we assume a single bundle, named after the
 | 
					 | 
				
			||||||
  // type of the object.
 | 
					 | 
				
			||||||
  $bundle = $info['object keys']['bundle'] ? $object->{$info['object keys']['bundle']} : $obj_type;
 | 
					 | 
				
			||||||
  $cacheable = $info['cacheable'];
 | 
					 | 
				
			||||||
  return array($id, $vid, $bundle, $cacheable);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Helper function to extract id, vid, and bundle name from an object.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param $obj_type
 | 
					 | 
				
			||||||
 *   The type of $object; e.g. 'node' or 'user'.
 | 
					 | 
				
			||||||
 * @param $bundle
 | 
					 | 
				
			||||||
 *   The bundle object (or string if bundles for this object type do not exist
 | 
					 | 
				
			||||||
 *   as standalone objects).
 | 
					 | 
				
			||||||
 * @return
 | 
					 | 
				
			||||||
 *   The bundle name.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
function field_attach_extract_bundle($obj_type, $bundle) {
 | 
					 | 
				
			||||||
  if (is_string($bundle)) {
 | 
					 | 
				
			||||||
    return $bundle;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  $info = field_info_fieldable_types($obj_type);
 | 
					 | 
				
			||||||
  if (is_object($bundle) && isset($info['bundle keys']['bundle']) && isset($bundle->{$info['bundle keys']['bundle']})) {
 | 
					 | 
				
			||||||
    return $bundle->{$info['bundle keys']['bundle']};
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Helper function to assemble an object structure with initial ids.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This function can be seen as reciprocal to field_attach_extract_ids().
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param $obj_type
 | 
					 | 
				
			||||||
 *   The type of $object; e.g. 'node' or 'user'.
 | 
					 | 
				
			||||||
 * @param $ids
 | 
					 | 
				
			||||||
 *   A numerically indexed array, as returned by field_attach_extract_ids(),
 | 
					 | 
				
			||||||
 *   containing these elements:
 | 
					 | 
				
			||||||
 *   0: primary id of the object
 | 
					 | 
				
			||||||
 *   1: revision id of the object, or NULL if $obj_type is not versioned
 | 
					 | 
				
			||||||
 *   2: bundle name of the object
 | 
					 | 
				
			||||||
 * @return
 | 
					 | 
				
			||||||
 *   An $object structure, initialized with the ids provided.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
function field_attach_create_stub_object($obj_type, $ids) {
 | 
					 | 
				
			||||||
  $object = new stdClass();
 | 
					 | 
				
			||||||
  $info = field_info_fieldable_types($obj_type);
 | 
					 | 
				
			||||||
  $object->{$info['object keys']['id']} = $ids[0];
 | 
					 | 
				
			||||||
  if (isset($info['object keys']['revision']) && !is_null($ids[1])) {
 | 
					 | 
				
			||||||
    $object->{$info['object keys']['revision']} = $ids[1];
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  if ($info['object keys']['bundle']) {
 | 
					 | 
				
			||||||
    $object->{$info['object keys']['bundle']} = $ids[2];
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  return $object;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @} End of "defgroup field_attach"
 | 
					 * @} End of "defgroup field_attach"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -59,7 +59,7 @@ function field_default_insert($obj_type, $object, $field, $instance, $langcode,
 | 
				
			||||||
 * @see field_attach_view()
 | 
					 * @see field_attach_view()
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_default_view($obj_type, $object, $field, $instance, $langcode, $items, $build_mode) {
 | 
					function field_default_view($obj_type, $object, $field, $instance, $langcode, $items, $build_mode) {
 | 
				
			||||||
  list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					  list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $addition = array();
 | 
					  $addition = array();
 | 
				
			||||||
  $display = $instance['display'][$build_mode];
 | 
					  $display = $instance['display'][$build_mode];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,7 +13,7 @@ function field_default_form($obj_type, $object, $field, $instance, $langcode, $i
 | 
				
			||||||
  // This could be called with no object, as when a UI module creates a
 | 
					  // This could be called with no object, as when a UI module creates a
 | 
				
			||||||
  // dummy form to set default values.
 | 
					  // dummy form to set default values.
 | 
				
			||||||
  if ($object) {
 | 
					  if ($object) {
 | 
				
			||||||
    list($id, , ) = field_attach_extract_ids($obj_type, $object);
 | 
					    list($id, , ) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  $addition = array();
 | 
					  $addition = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -500,7 +500,7 @@ function field_format($obj_type, $object, $field, $item, $formatter_type = NULL,
 | 
				
			||||||
    $field_type = field_info_field_types($field['type']);
 | 
					    $field_type = field_info_field_types($field['type']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // We need $field, $instance, $obj_type, $object to be able to display a value...
 | 
					    // We need $field, $instance, $obj_type, $object to be able to display a value...
 | 
				
			||||||
    list(, , $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					    list(, , $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
    $instance = field_info_instance($field['field_name'], $bundle);
 | 
					    $instance = field_info_instance($field['field_name'], $bundle);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $display = array(
 | 
					    $display = array(
 | 
				
			||||||
| 
						 | 
					@ -630,6 +630,86 @@ function field_access($op, $field, $account = NULL) {
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Helper function to extract id, vid, and bundle name from an object.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param $obj_type
 | 
				
			||||||
 | 
					 *   The type of $object; e.g. 'node' or 'user'.
 | 
				
			||||||
 | 
					 * @param $object
 | 
				
			||||||
 | 
					 *   The object from which to extract values.
 | 
				
			||||||
 | 
					 * @return
 | 
				
			||||||
 | 
					 *   A numerically indexed array (not a hash table) containing these
 | 
				
			||||||
 | 
					 *   elements:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *   0: primary id of the object
 | 
				
			||||||
 | 
					 *   1: revision id of the object, or NULL if $obj_type is not versioned
 | 
				
			||||||
 | 
					 *   2: bundle name of the object
 | 
				
			||||||
 | 
					 *   3: whether $obj_type's fields should be cached (TRUE/FALSE)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function field_extract_ids($obj_type, $object) {
 | 
				
			||||||
 | 
					  // TODO D7 : prevent against broken 3rd party $node without 'type'.
 | 
				
			||||||
 | 
					  $info = field_info_fieldable_types($obj_type);
 | 
				
			||||||
 | 
					  // Objects being created might not have id/vid yet.
 | 
				
			||||||
 | 
					  $id = isset($object->{$info['object keys']['id']}) ? $object->{$info['object keys']['id']} : NULL;
 | 
				
			||||||
 | 
					  $vid = ($info['object keys']['revision'] && isset($object->{$info['object keys']['revision']})) ? $object->{$info['object keys']['revision']} : NULL;
 | 
				
			||||||
 | 
					  // If no bundle key provided, then we assume a single bundle, named after the
 | 
				
			||||||
 | 
					  // type of the object.
 | 
				
			||||||
 | 
					  $bundle = $info['object keys']['bundle'] ? $object->{$info['object keys']['bundle']} : $obj_type;
 | 
				
			||||||
 | 
					  $cacheable = $info['cacheable'];
 | 
				
			||||||
 | 
					  return array($id, $vid, $bundle, $cacheable);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Helper function to extract id, vid, and bundle name from an object.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param $obj_type
 | 
				
			||||||
 | 
					 *   The type of $object; e.g. 'node' or 'user'.
 | 
				
			||||||
 | 
					 * @param $bundle
 | 
				
			||||||
 | 
					 *   The bundle object (or string if bundles for this object type do not exist
 | 
				
			||||||
 | 
					 *   as standalone objects).
 | 
				
			||||||
 | 
					 * @return
 | 
				
			||||||
 | 
					 *   The bundle name.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function field_extract_bundle($obj_type, $bundle) {
 | 
				
			||||||
 | 
					  if (is_string($bundle)) {
 | 
				
			||||||
 | 
					    return $bundle;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $info = field_info_fieldable_types($obj_type);
 | 
				
			||||||
 | 
					  if (is_object($bundle) && isset($info['bundle keys']['bundle']) && isset($bundle->{$info['bundle keys']['bundle']})) {
 | 
				
			||||||
 | 
					    return $bundle->{$info['bundle keys']['bundle']};
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Helper function to assemble an object structure with initial ids.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This function can be seen as reciprocal to field_extract_ids().
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param $obj_type
 | 
				
			||||||
 | 
					 *   The type of $object; e.g. 'node' or 'user'.
 | 
				
			||||||
 | 
					 * @param $ids
 | 
				
			||||||
 | 
					 *   A numerically indexed array, as returned by field_extract_ids(),
 | 
				
			||||||
 | 
					 *   containing these elements:
 | 
				
			||||||
 | 
					 *   0: primary id of the object
 | 
				
			||||||
 | 
					 *   1: revision id of the object, or NULL if $obj_type is not versioned
 | 
				
			||||||
 | 
					 *   2: bundle name of the object
 | 
				
			||||||
 | 
					 * @return
 | 
				
			||||||
 | 
					 *   An $object structure, initialized with the ids provided.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function field_create_stub_entity($obj_type, $ids) {
 | 
				
			||||||
 | 
					  $object = new stdClass();
 | 
				
			||||||
 | 
					  $info = field_info_fieldable_types($obj_type);
 | 
				
			||||||
 | 
					  $object->{$info['object keys']['id']} = $ids[0];
 | 
				
			||||||
 | 
					  if (isset($info['object keys']['revision']) && !is_null($ids[1])) {
 | 
				
			||||||
 | 
					    $object->{$info['object keys']['revision']} = $ids[1];
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if ($info['object keys']['bundle']) {
 | 
				
			||||||
 | 
					    $object->{$info['object keys']['bundle']} = $ids[2];
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return $object;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Theme preprocess function for field.tpl.php.
 | 
					 * Theme preprocess function for field.tpl.php.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -637,7 +717,7 @@ function field_access($op, $field, $account = NULL) {
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function template_preprocess_field(&$variables) {
 | 
					function template_preprocess_field(&$variables) {
 | 
				
			||||||
  $element = $variables['element'];
 | 
					  $element = $variables['element'];
 | 
				
			||||||
  list(, , $bundle) = field_attach_extract_ids($element['#object_type'], $element['#object']);
 | 
					  list(, , $bundle) = field_extract_ids($element['#object_type'], $element['#object']);
 | 
				
			||||||
  $instance = field_info_instance($element['#field_name'], $bundle);
 | 
					  $instance = field_info_instance($element['#field_name'], $bundle);
 | 
				
			||||||
  $field = field_info_field($element['#field_name']);
 | 
					  $field = field_info_field($element['#field_name']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2135,7 +2135,7 @@ class FieldBulkDeleteTestCase extends FieldTestCase {
 | 
				
			||||||
  function _generateStubObjects($obj_type, $objects, $field_name = NULL) {
 | 
					  function _generateStubObjects($obj_type, $objects, $field_name = NULL) {
 | 
				
			||||||
    $stubs = array();
 | 
					    $stubs = array();
 | 
				
			||||||
    foreach ($objects as $obj) {
 | 
					    foreach ($objects as $obj) {
 | 
				
			||||||
      $stub = field_attach_create_stub_object($obj_type, field_attach_extract_ids($obj_type, $obj));
 | 
					      $stub = field_create_stub_entity($obj_type, field_extract_ids($obj_type, $obj));
 | 
				
			||||||
      if (isset($field_name)) {
 | 
					      if (isset($field_name)) {
 | 
				
			||||||
        $stub->{$field_name} = $obj->{$field_name};
 | 
					        $stub->{$field_name} = $obj->{$field_name};
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -238,7 +238,7 @@ function field_sql_storage_field_storage_load($obj_type, $objects, $age, $skip_f
 | 
				
			||||||
  $field_ids = array();
 | 
					  $field_ids = array();
 | 
				
			||||||
  $delta_count = array();
 | 
					  $delta_count = array();
 | 
				
			||||||
  foreach ($objects as $obj) {
 | 
					  foreach ($objects as $obj) {
 | 
				
			||||||
    list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $obj);
 | 
					    list($id, $vid, $bundle) = field_extract_ids($obj_type, $obj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ($options['deleted']) {
 | 
					    if ($options['deleted']) {
 | 
				
			||||||
      $instances = field_read_instances(array('bundle' => $bundle), array('include_deleted' => $options['deleted']));
 | 
					      $instances = field_read_instances(array('bundle' => $bundle), array('include_deleted' => $options['deleted']));
 | 
				
			||||||
| 
						 | 
					@ -301,7 +301,7 @@ function field_sql_storage_field_storage_load($obj_type, $objects, $age, $skip_f
 | 
				
			||||||
 * Implement hook_field_storage_write().
 | 
					 * Implement hook_field_storage_write().
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_sql_storage_field_storage_write($obj_type, $object, $op, $skip_fields) {
 | 
					function field_sql_storage_field_storage_write($obj_type, $object, $op, $skip_fields) {
 | 
				
			||||||
  list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					  list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
  $etid = _field_sql_storage_etid($obj_type);
 | 
					  $etid = _field_sql_storage_etid($obj_type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $instances = field_info_instances($bundle);
 | 
					  $instances = field_info_instances($bundle);
 | 
				
			||||||
| 
						 | 
					@ -399,7 +399,7 @@ function field_sql_storage_field_storage_write($obj_type, $object, $op, $skip_fi
 | 
				
			||||||
 * This function deletes data for all fields for an object from the database.
 | 
					 * This function deletes data for all fields for an object from the database.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_sql_storage_field_storage_delete($obj_type, $object) {
 | 
					function field_sql_storage_field_storage_delete($obj_type, $object) {
 | 
				
			||||||
  list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					  list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
  $etid = _field_sql_storage_etid($obj_type);
 | 
					  $etid = _field_sql_storage_etid($obj_type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $instances = field_info_instances($bundle);
 | 
					  $instances = field_info_instances($bundle);
 | 
				
			||||||
| 
						 | 
					@ -416,7 +416,7 @@ function field_sql_storage_field_storage_delete($obj_type, $object) {
 | 
				
			||||||
 * an object.
 | 
					 * an object.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_sql_storage_field_storage_purge($obj_type, $object, $field, $instance) {
 | 
					function field_sql_storage_field_storage_purge($obj_type, $object, $field, $instance) {
 | 
				
			||||||
  list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					  list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
  $etid = _field_sql_storage_etid($obj_type);
 | 
					  $etid = _field_sql_storage_etid($obj_type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $field = field_info_field_by_id($field['id']);
 | 
					  $field = field_info_field_by_id($field['id']);
 | 
				
			||||||
| 
						 | 
					@ -532,7 +532,7 @@ function field_sql_storage_field_storage_query($field_id, $conditions, $count, &
 | 
				
			||||||
      $id = ($load_current || empty($entity_type['object keys']['revision'])) ? $row->entity_id : $row->revision_id;
 | 
					      $id = ($load_current || empty($entity_type['object keys']['revision'])) ? $row->entity_id : $row->revision_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (!isset($return[$row->type][$id])) {
 | 
					      if (!isset($return[$row->type][$id])) {
 | 
				
			||||||
        $return[$row->type][$id] = field_attach_create_stub_object($row->type, array($row->entity_id, $row->revision_id, $row->bundle));
 | 
					        $return[$row->type][$id] = field_create_stub_entity($row->type, array($row->entity_id, $row->revision_id, $row->bundle));
 | 
				
			||||||
        $obj_count++;
 | 
					        $obj_count++;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -553,7 +553,7 @@ function field_sql_storage_field_storage_query($field_id, $conditions, $count, &
 | 
				
			||||||
 * This function actually deletes the data from the database.
 | 
					 * This function actually deletes the data from the database.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_sql_storage_field_storage_delete_revision($obj_type, $object) {
 | 
					function field_sql_storage_field_storage_delete_revision($obj_type, $object) {
 | 
				
			||||||
  list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					  list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
  $etid = _field_sql_storage_etid($obj_type);
 | 
					  $etid = _field_sql_storage_etid($obj_type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (isset($vid)) {
 | 
					  if (isset($vid)) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,7 +66,7 @@ function field_ui_inactive_message($bundle) {
 | 
				
			||||||
 * Allows fields and pseudo-fields to be re-ordered.
 | 
					 * Allows fields and pseudo-fields to be re-ordered.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_ui_field_overview_form(&$form_state, $obj_type, $bundle) {
 | 
					function field_ui_field_overview_form(&$form_state, $obj_type, $bundle) {
 | 
				
			||||||
  $bundle = field_attach_extract_bundle($obj_type, $bundle);
 | 
					  $bundle = field_extract_bundle($obj_type, $bundle);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  field_ui_inactive_message($bundle);
 | 
					  field_ui_inactive_message($bundle);
 | 
				
			||||||
  $admin_path = _field_ui_bundle_admin_path($bundle);
 | 
					  $admin_path = _field_ui_bundle_admin_path($bundle);
 | 
				
			||||||
| 
						 | 
					@ -551,7 +551,7 @@ function field_ui_field_overview_form_submit($form, &$form_state) {
 | 
				
			||||||
 * full build modes, and how the field labels should be rendered.
 | 
					 * full build modes, and how the field labels should be rendered.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_ui_display_overview_form(&$form_state, $obj_type, $bundle, $build_modes_selector = 'basic') {
 | 
					function field_ui_display_overview_form(&$form_state, $obj_type, $bundle, $build_modes_selector = 'basic') {
 | 
				
			||||||
  $bundle = field_attach_extract_bundle($obj_type, $bundle);
 | 
					  $bundle = field_extract_bundle($obj_type, $bundle);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  field_ui_inactive_message($bundle);
 | 
					  field_ui_inactive_message($bundle);
 | 
				
			||||||
  $admin_path = _field_ui_bundle_admin_path($bundle);
 | 
					  $admin_path = _field_ui_bundle_admin_path($bundle);
 | 
				
			||||||
| 
						 | 
					@ -791,7 +791,7 @@ function field_ui_field_has_data($field) {
 | 
				
			||||||
 * Menu callback; presents the field settings edit page.
 | 
					 * Menu callback; presents the field settings edit page.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_ui_field_settings_form(&$form_state, $obj_type, $bundle, $instance) {
 | 
					function field_ui_field_settings_form(&$form_state, $obj_type, $bundle, $instance) {
 | 
				
			||||||
  $bundle = field_attach_extract_bundle($obj_type, $bundle);
 | 
					  $bundle = field_extract_bundle($obj_type, $bundle);
 | 
				
			||||||
  $field = field_info_field($instance['field_name']);
 | 
					  $field = field_info_field($instance['field_name']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // When a field is first created, we have to get data from the db.
 | 
					  // When a field is first created, we have to get data from the db.
 | 
				
			||||||
| 
						 | 
					@ -888,7 +888,7 @@ function field_ui_field_settings_form_submit($form, &$form_state) {
 | 
				
			||||||
 * Menu callback; select a widget for the field.
 | 
					 * Menu callback; select a widget for the field.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_ui_widget_type_form(&$form_state, $obj_type, $bundle, $instance) {
 | 
					function field_ui_widget_type_form(&$form_state, $obj_type, $bundle, $instance) {
 | 
				
			||||||
  $bundle = field_attach_extract_bundle($obj_type, $bundle);
 | 
					  $bundle = field_extract_bundle($obj_type, $bundle);
 | 
				
			||||||
  $field = field_read_field($instance['field_name']);
 | 
					  $field = field_read_field($instance['field_name']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $field_type = field_info_field_types($field['type']);
 | 
					  $field_type = field_info_field_types($field['type']);
 | 
				
			||||||
| 
						 | 
					@ -947,7 +947,7 @@ function field_ui_widget_type_form_submit($form, &$form_state) {
 | 
				
			||||||
 * Menu callback; present a form for removing a field from a content type.
 | 
					 * Menu callback; present a form for removing a field from a content type.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_ui_field_delete_form(&$form_state, $obj_type, $bundle, $instance) {
 | 
					function field_ui_field_delete_form(&$form_state, $obj_type, $bundle, $instance) {
 | 
				
			||||||
  $bundle = field_attach_extract_bundle($obj_type, $bundle);
 | 
					  $bundle = field_extract_bundle($obj_type, $bundle);
 | 
				
			||||||
  $field = field_info_field($instance['field_name']);
 | 
					  $field = field_info_field($instance['field_name']);
 | 
				
			||||||
  $admin_path = _field_ui_bundle_admin_path($bundle);
 | 
					  $admin_path = _field_ui_bundle_admin_path($bundle);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1001,7 +1001,7 @@ function field_ui_field_delete_form_submit($form, &$form_state) {
 | 
				
			||||||
 * Menu callback; presents the field instance edit page.
 | 
					 * Menu callback; presents the field instance edit page.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_ui_field_edit_form(&$form_state, $obj_type, $bundle, $instance) {
 | 
					function field_ui_field_edit_form(&$form_state, $obj_type, $bundle, $instance) {
 | 
				
			||||||
  $bundle = field_attach_extract_bundle($obj_type, $bundle);
 | 
					  $bundle = field_extract_bundle($obj_type, $bundle);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $field = field_info_field($instance['field_name']);
 | 
					  $field = field_info_field($instance['field_name']);
 | 
				
			||||||
  $form['#field'] = $field;
 | 
					  $form['#field'] = $field;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -292,7 +292,7 @@ function file_field_update($obj_type, $object, $field, $instance, $langcode, &$i
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Delete items from original object.
 | 
					  // Delete items from original object.
 | 
				
			||||||
  list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					  list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
  $load_function = $obj_type . '_load';
 | 
					  $load_function = $obj_type . '_load';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $original = $load_function($id);
 | 
					  $original = $load_function($id);
 | 
				
			||||||
| 
						 | 
					@ -312,7 +312,7 @@ function file_field_update($obj_type, $object, $field, $instance, $langcode, &$i
 | 
				
			||||||
 * Implement hook_field_delete().
 | 
					 * Implement hook_field_delete().
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function file_field_delete($obj_type, $object, $field, $instance, $langcode, &$items) {
 | 
					function file_field_delete($obj_type, $object, $field, $instance, $langcode, &$items) {
 | 
				
			||||||
  list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
 | 
					  list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
 | 
				
			||||||
  foreach ($items as $delta => $item) {
 | 
					  foreach ($items as $delta => $item) {
 | 
				
			||||||
    // For hook_file_references(), remember that this is being deleted.
 | 
					    // For hook_file_references(), remember that this is being deleted.
 | 
				
			||||||
    $item['file_field_name'] = $field['field_name'];
 | 
					    $item['file_field_name'] = $field['field_name'];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue