root / htmltest / sites / all / modules / fivestar / fivestar.api.php @ a5572547
1 | 85ad3d82 | Assos Assos | <?php
|
---|---|---|---|
2 | |||
3 | /**
|
||
4 | * @file
|
||
5 | * Provides API documentation for the fivestar module.
|
||
6 | */
|
||
7 | |||
8 | |||
9 | /**
|
||
10 | * Implementation of hook_fivestar_widgets().
|
||
11 | *
|
||
12 | * This hook allows other modules to create additional custom widgets for
|
||
13 | * the fivestar module.
|
||
14 | *
|
||
15 | * @return array
|
||
16 | * An array of key => value pairs suitable for inclusion as the #options in a
|
||
17 | * select or radios form element. Each key must be the location of a css
|
||
18 | * file for a fivestar widget. Each value should be the name of the widget.
|
||
19 | *
|
||
20 | * @see fivestar_fivestar_widgets()
|
||
21 | */
|
||
22 | function hook_fivestar_widgets() { |
||
23 | // Letting fivestar know about my Cool and Awesome Stars.
|
||
24 | $widgets = array( |
||
25 | 'path/to/my/awesome/fivestar/css.css' => 'Awesome Stars', |
||
26 | 'path/to/my/cool/fivestar/css.css' => 'Cool Stars', |
||
27 | ); |
||
28 | |||
29 | return $widgets; |
||
30 | } |
||
31 | |||
32 | /**
|
||
33 | * Implementation of hook_fivestar_access().
|
||
34 | *
|
||
35 | * This hook is called before every vote is cast through Fivestar. It allows
|
||
36 | * modules to allow or deny voting on any type of entity, such as nodes, users, or
|
||
37 | * comments.
|
||
38 | *
|
||
39 | * @param $entity_type
|
||
40 | * Type entity.
|
||
41 | * @param $id
|
||
42 | * Identifier within the type.
|
||
43 | * @param $tag
|
||
44 | * The VotingAPI tag string.
|
||
45 | * @param $uid
|
||
46 | * The user ID trying to cast the vote.
|
||
47 | *
|
||
48 | * @return boolean or NULL
|
||
49 | * Returns TRUE if voting is supported on this object.
|
||
50 | * Returns NULL if voting is not supported on this object by this module.
|
||
51 | * If needing to absolutely deny all voting on this object, regardless
|
||
52 | * of permissions defined in other modules, return FALSE. Note if all
|
||
53 | * modules return NULL, stating no preference, then access will be denied.
|
||
54 | *
|
||
55 | * @see fivestar_validate_target()
|
||
56 | * @see fivestar_fivestar_access()
|
||
57 | */
|
||
58 | function hook_fivestar_access($entity_type, $id, $tag, $uid) { |
||
59 | if ($uid == 1) { |
||
60 | // We are never going to allow the admin user case a fivestar vote.
|
||
61 | return FALSE; |
||
62 | } |
||
63 | } |
||
64 | |||
65 | /**
|
||
66 | * Implementation of hook_fivestar_access().
|
||
67 | *
|
||
68 | * @param $field
|
||
69 | * The field structure for the operation.
|
||
70 | * @param $instance
|
||
71 | * The instance structures for the $field.
|
||
72 | *
|
||
73 | * @return array
|
||
74 | * An array of key => value pairs. Each key must be unique the identifier for this
|
||
75 | * target selection. The Value is an array of key => value pairs for a title and a
|
||
76 | * callback function. The title value is used for displaying in the #options array
|
||
77 | * of the target selection option. The callback function is used when trying to decided
|
||
78 | * which target the current vote should be 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 key
|
||
116 | * and a entity_type key. The value os the entity_id and entity_type is what the
|
||
117 | * fivestar vote is going to be cast against when a user has selected this option
|
||
118 | * 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 | } |