Projet

Général

Profil

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

root / drupal7 / sites / all / modules / fivestar / fivestar.migrate.inc @ 6ae446a4

1 4853591f Assos Assos
<?php
2
/**
3
 * @file
4
 * Base integration with the Migrate API class.
5
 */
6
7
/**
8
 * Implements hook_migrate_api().
9
 */
10
function fivestar_migrate_api() {
11
  $api = array(
12
    'api' => 2,
13
    'field handlers' => array('MigrateFivestarFieldHandler'),
14
  );
15
  return $api;
16
}
17
18
/**
19
 * Custom extended MigrateFieldHandler class for FiveStar module.
20
 */
21
class MigrateFivestarFieldHandler extends MigrateFieldHandler {
22
23
  public function __construct() {
24
    $this->registerTypes(array('fivestar'));
25
  }
26
27
  public function fields($type, $parent_field, $migration = NULL) {
28
    $fields = array(
29
      'target' => t('Ratings: The target of the rating.'),
30
    );
31
    return $fields;
32
  }
33
34
  public function prepare($entity, array $field_info, array $instance, array $values) {
35
    $arguments = array();
36
    if (isset($values['arguments'])) {
37
      $arguments = array_filter($values['arguments']);
38
      unset($values['arguments']);
39
    }
40
    $language = $this->getFieldLanguage($entity, $field_info, $arguments);
41
42
    // Setup the standard Field API array for saving.
43
    foreach (array_values($values) as $delta => $value) {
44
      $return[$language][$delta] = array('rating' => $value) + array_intersect_key($arguments, $field_info['columns']);
45
    }
46
47
    return isset($return) ? $return : NULL;
48
  }
49
}