root / drupal7 / sites / all / modules / fivestar / fivestar.api.php @ d50a36e0
1 |
<?php
|
---|---|
2 |
|
3 |
/**
|
4 |
* @file
|
5 |
* Provides API documentation for the fivestar module.
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
* Implements hook_fivestar_widgets().
|
10 |
*
|
11 |
* This hook allows other modules to create additional custom widgets for
|
12 |
* the fivestar module.
|
13 |
*
|
14 |
* @return array
|
15 |
* An array of key => value pairs suitable for inclusion as the #options in a
|
16 |
* select or radios form element. Each key must be the location of a css
|
17 |
* file for a fivestar widget. Each value should be the name of the widget.
|
18 |
*
|
19 |
* @see fivestar_fivestar_widgets()
|
20 |
*/
|
21 |
function hook_fivestar_widgets() { |
22 |
// Letting fivestar know about my Cool and Awesome Stars.
|
23 |
$widgets = array( |
24 |
'path/to/my/awesome/fivestar/css.css' => 'Awesome Stars', |
25 |
'path/to/my/cool/fivestar/css.css' => 'Cool Stars', |
26 |
); |
27 |
|
28 |
return $widgets; |
29 |
} |
30 |
|
31 |
/**
|
32 |
* Implements hook_fivestar_access().
|
33 |
*
|
34 |
* This hook is called before every vote is cast through Fivestar. It allows
|
35 |
* modules to allow or deny voting on any type of entity, such as nodes, users,
|
36 |
* or comments.
|
37 |
*
|
38 |
* @param $entity_type
|
39 |
* Type entity.
|
40 |
* @param $id
|
41 |
* Identifier within the type.
|
42 |
* @param $tag
|
43 |
* The VotingAPI tag string.
|
44 |
* @param $uid
|
45 |
* The user ID trying to cast the vote.
|
46 |
*
|
47 |
* @return bool|null
|
48 |
* Returns TRUE if voting is supported on this object.
|
49 |
* Returns NULL if voting is not supported on this object by this module.
|
50 |
* If needing to absolutely deny all voting on this object, regardless
|
51 |
* of permissions defined in other modules, return FALSE. Note if all
|
52 |
* modules return NULL, stating no preference, then access will be denied.
|
53 |
*
|
54 |
* @see fivestar_validate_target()
|
55 |
* @see fivestar_fivestar_access()
|
56 |
*/
|
57 |
function hook_fivestar_access($entity_type, $id, $tag, $uid) { |
58 |
if ($uid == 1) { |
59 |
// We are never going to allow the admin user case a fivestar vote.
|
60 |
return FALSE; |
61 |
} |
62 |
} |
63 |
|
64 |
/**
|
65 |
* Implements hook_fivestar_target_info().
|
66 |
*
|
67 |
* @param $field
|
68 |
* The field structure for the operation.
|
69 |
* @param $instance
|
70 |
* The instance structures for the $field.
|
71 |
*
|
72 |
* @return array
|
73 |
* An array of key => value pairs. Each key must be unique the identifier for
|
74 |
* this target selection. The Value is an array of key => value pairs for a
|
75 |
* title and a callback function. The title value is used for displaying in
|
76 |
* the #options array of the target selection option. The callback function
|
77 |
* is used when trying to decided which target the current vote should be
|
78 |
* cast against.
|
79 |
*
|
80 |
* @see fivestar_get_targets()
|
81 |
* @see fivestar_fivestar_target_info()
|
82 |
*/
|
83 |
function hook_fivestar_target_info($field, $instance) { |
84 |
$entity_type = $instance['entity_type']; |
85 |
$bundle = $instance['bundle']; |
86 |
|
87 |
$options = array( |
88 |
// Declase a new Target Type.
|
89 |
// This will allow users to vote on a Node and have the vote cast against the
|
90 |
// node's author instead of the actual node.
|
91 |
'example_node_author' => array( |
92 |
'title' => t('Node Author'), |
93 |
'callback' => '_example_target_node_author', |
94 |
), |
95 |
); |
96 |
|
97 |
return $options; |
98 |
} |
99 |
|
100 |
/**
|
101 |
* Define a custom voting behavior for this target selection type.
|
102 |
*
|
103 |
* Invoked from fivestar_get_targets().
|
104 |
*
|
105 |
* @param $entity
|
106 |
* The entity for the operation.
|
107 |
* @param $field
|
108 |
* The field structure for the operation.
|
109 |
* @param $instance
|
110 |
* The instance structure for $field on $entity's bundle.
|
111 |
* @param $langcode
|
112 |
* The language associated with $items.
|
113 |
*
|
114 |
* @return array
|
115 |
* An array of key => value pairs. The return array must contain an entity_id
|
116 |
* key and a entity_type key. The value os the entity_id and entity_type is
|
117 |
* what the fivestar vote is going to be cast against when a user has selected
|
118 |
* this option as the target selection.
|
119 |
*
|
120 |
* @see _fivestar_target_comment_parent_node()
|
121 |
* @see _fivestar_target_node_reference()
|
122 |
* @see fivestar_get_targets()
|
123 |
* @see hook_fivestar_target_info()
|
124 |
*/
|
125 |
function _example_target_node_author($entity, $field, $instance, $langcode) { |
126 |
$target = array( |
127 |
'entity_id' => 2, |
128 |
'entity_type' => 'user', |
129 |
); |
130 |
|
131 |
return $target; |
132 |
} |