You are here

function field_deploy_entity_alter in Deploy - Content Staging 7.2

Same name and namespace in other branches
  1. 7.3 deploy.core.inc \field_deploy_entity_alter()

Implements hook_deploy_entity_alter().

This hook will go through all fields for an entity and invoke a new hook for all field modules. This saves a lot of work for each field implementaor.

Related topics

File

./deploy.core.inc, line 51
Deploy module functions for core entities.

Code

function field_deploy_entity_alter(&$entity, $entity_type) {
  if (empty($entity) || empty($entity_type)) {
    return;
  }
  $dependencies = array();
  list(, , $bundle_name) = entity_extract_ids($entity_type, $entity);
  $instances = field_info_instances($entity_type, $bundle_name);
  foreach ($instances as $field_name => $instance) {
    $field = field_info_field($field_name);
    foreach ($entity->{$field_name} as $langcode => &$items) {
      foreach ($items as &$item) {

        // This can potentially save *a lot* of bandwidth, since these values
        // aren't really needed when deploying.
        foreach (array(
          'safe_value',
          'safe_summary',
        ) as $key) {
          if (isset($item[$key])) {
            unset($item[$key]);
          }
        }
      }

      // TODO: Can we do this with drupal_alter()? Reason for this quick and
      // mashup is because I want to keep the argument order consistent between
      // field hooks, and still possibility to alter arguments.
      $function = $field['module'] . '_deploy_field_alter';
      if (function_exists($function)) {
        $function($entity_type, $entity, $field, $instance, $langcode, $items);
      }
    }
  }
  return $dependencies;
}