Projet

Général

Profil

Paste
Télécharger (1,9 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / field_collection / field_collection.info.inc @ 5e632cae

1
<?php
2

    
3
/**
4
 * @file
5
 * Provides entity property info for field collection items.
6
 */
7

    
8
class FieldCollectionItemMetadataController extends EntityDefaultMetadataController {
9

    
10
  public function entityPropertyInfo() {
11
    $info = parent::entityPropertyInfo();
12
    $properties = &$info['field_collection_item']['properties'];
13

    
14
    $properties['field_name']['label'] = t('Field name');
15
    $properties['field_name']['description'] = t('The machine-readable name of the field collection field containing this item.');
16
    $properties['field_name']['required'] = TRUE;
17

    
18
    $properties['host_entity'] = array(
19
      'label' => t('Host entity'),
20
      'type' => 'entity',
21
      'description' => t('The entity containing the field collection field.'),
22
      'getter callback' => 'field_collection_item_get_host_entity',
23
      'setter callback' => 'field_collection_item_set_host_entity',
24
      'required' => TRUE,
25
    );
26

    
27
    // Also add type-specific host entity references for all entity types that
28
    // have at least one field collection field.
29
    $field_collection_fields = field_read_fields(array('type' => 'field_collection'));
30
    $entity_types = entity_get_info();
31
    foreach (field_info_instances() as $entity_type => $bundles) {
32
      foreach ($bundles as $bundle => $fields) {
33
        if (array_intersect_key($fields, $field_collection_fields)) {
34
          $args = array('@type' => $entity_types[$entity_type]['label']);
35
          $properties["host_entity_{$entity_type}"] = array(
36
            'label' => t('Host entity (@type)', $args),
37
            'type' => $entity_type,
38
            'description' => t('The @type containing the field collection field (empty if this field collection is attached to an item of a different type).', $args),
39
            'getter callback' => 'field_collection_item_get_specific_type_host_entity',
40
            'computed' => TRUE,
41
          );
42
          break;
43
        }
44
      }
45
    }
46

    
47
    return $info;
48
  }
49

    
50
}