You are here

function fivestar_fivestar_target_info in Fivestar 7.2

Implements hook_fivestar_target_info().

File

./fivestar.module, line 912

Code

function fivestar_fivestar_target_info($field, $instance) {
  $entity_type = $instance['entity_type'];
  $bundle = $instance['bundle'];
  $options = array(
    'none' => array(
      'title' => t('None'),
    ),
  );

  // Add node_referrence support.
  if (module_exists('node_reference')) {
    $field_names = array_keys(field_read_fields(array(
      'module' => 'node_reference',
    )));
    if (!empty($field_names)) {
      $field_instances = field_read_instances(array(
        'entity_type' => $entity_type,
        'bundle' => $bundle,
        'field_name' => $field_names,
      ));
      if (!empty($field_instances)) {
        foreach ($field_instances as $field_instance) {
          $options[$field_instance['field_name']] = array(
            'title' => t('Node reference: @field', array(
              '@field' => $field_instance['field_name'],
            )),
            'callback' => '_fivestar_target_node_reference',
          );
        }
      }
    }
  }

  // Add entityreference support.
  if (module_exists('entityreference')) {
    $field_names = array_keys(field_read_fields(array(
      'module' => 'entityreference',
    )));
    if (!empty($field_names)) {
      $field_instances = field_read_instances(array(
        'entity_type' => $entity_type,
        'bundle' => $bundle,
        'field_name' => $field_names,
      ));
      if (!empty($field_instances)) {
        foreach ($field_instances as $field_instance) {
          $options[$field_instance['field_name']] = array(
            'title' => t('Entity reference: @field', array(
              '@field' => $field_instance['field_name'],
            )),
            'callback' => '_fivestar_target_entityreference',
          );
        }
      }
    }
  }

  // Add user reference support.
  if (module_exists('user_reference')) {
    $field_names = array_keys(field_read_fields(array(
      'module' => 'user_reference',
    )));
    if (!empty($field_names)) {
      $field_instances = field_read_instances(array(
        'entity_type' => $entity_type,
        'bundle' => $bundle,
        'field_name' => $field_names,
      ));
      if (!empty($field_instances)) {
        foreach ($field_instances as $field_instance) {
          $options[$field_instance['field_name']] = array(
            'title' => t('User reference: @field', array(
              '@field' => $field_instance['field_name'],
            )),
            'callback' => '_fivestar_target_user_reference',
          );
        }
      }
    }
  }

  // Add comment module support.
  if ($instance['entity_type'] == 'comment') {
    $options['parent_node'] = array(
      'title' => t('Parent Node'),
      'callback' => '_fivestar_target_comment_parent_node',
    );
  }
  return $options;
}