You are here

public function EntityDefaultFeaturesController::export in Entity API 7

Generates the result for hook_features_export().

File

./entity.features.inc, line 77
Provides Features integration for entity types using the CRUD API.

Class

EntityDefaultFeaturesController
Default controller handling features integration.

Code

public function export($data, &$export, $module_name = '') {
  $pipe = array();
  foreach (entity_load_multiple_by_name($this->type, $data) as $name => $entity) {

    // If this entity is provided by a different module, add it as dependency.
    if ($entity->{$this->statusKey} & ENTITY_IN_CODE && $entity->{$this->moduleKey} != $module_name) {
      $module = $entity->{$this->moduleKey};
      $export['dependencies'][$module] = $module;
    }
    else {
      $export['features'][$this->type][$name] = $name;

      // If this is a bundle of a fieldable entity add its fields to the pipe.
      if (!empty($this->info['bundle of'])) {
        $fields = field_info_instances($this->info['bundle of'], $entity->{$this->bundleKey});
        foreach ($fields as $name => $field) {
          $pipe['field'][] = "{$field['entity_type']}-{$field['bundle']}-{$field['field_name']}";
          $pipe['field_instance'][] = "{$field['entity_type']}-{$field['bundle']}-{$field['field_name']}";
        }
      }
    }
  }

  // Add the module providing the entity type as dependency.
  if ($data && !empty($this->info['module'])) {
    $export['dependencies'][$this->info['module']] = $this->info['module'];

    // In case entity is not already an indirect dependency, add it.
    // We can do so without causing redundant dependencies because,
    // if entity is an indirect dependency, Features will filter it out.
    $export['dependencies']['entity'] = 'entity';
  }
  return $pipe;
}