Révision 018e218c
Ajouté par Assos Assos il y a plus de 10 ans
htmltest/sites/all/modules/flag/flag.module | ||
---|---|---|
33 | 33 |
// The following tells EntityAPI how to save flaggings, thus allowing use |
34 | 34 |
// of Entity metadata wrappers (if present). |
35 | 35 |
'save callback' => 'flagging_save', |
36 |
'creation callback' => 'flagging_create', |
|
36 | 37 |
), |
37 | 38 |
); |
38 | 39 |
|
... | ... | |
72 | 73 |
return reset($result); |
73 | 74 |
} |
74 | 75 |
|
76 |
/** |
|
77 |
* Entity API creation callback. |
|
78 |
* |
|
79 |
* Creates an unsaved flagging object for use with $flag->flag(). |
|
80 |
* |
|
81 |
* @param $values |
|
82 |
* An array of values as described by the entity's property info. Only |
|
83 |
* 'flag_name' or 'fid' must be specified, since $flag->flag() does the rest. |
|
84 |
* |
|
85 |
* @return |
|
86 |
* An unsaved flagging object containing the property values. |
|
87 |
*/ |
|
88 |
function flagging_create($values = array()) { |
|
89 |
$flagging = (object) array(); |
|
90 |
|
|
91 |
if (!isset($values['flag_name'])) { |
|
92 |
if (isset($values['fid'])) { |
|
93 |
// Add flag_name, determined from fid. |
|
94 |
$flag = flag_get_flag(NULL, $values['fid']); |
|
95 |
$values['flag_name'] = $flag->name; |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
// Apply the given values. |
|
100 |
foreach ($values as $key => $value) { |
|
101 |
$flagging->$key = $value; |
|
102 |
} |
|
103 |
|
|
104 |
return $flagging; |
|
105 |
} |
|
106 |
|
|
75 | 107 |
/** |
76 | 108 |
* Saves a flagging entity. |
77 | 109 |
* |
... | ... | |
616 | 648 |
continue; |
617 | 649 |
} |
618 | 650 |
|
619 |
foreach ($flag->types as $bundle_name) { |
|
651 |
$applicable_bundles = $flag->types; |
|
652 |
// If the list of bundles is empty, it indicates all bundles apply. |
|
653 |
if (empty($applicable_bundles)) { |
|
654 |
$entity_info = entity_get_info($flag->entity_type); |
|
655 |
$applicable_bundles = array_keys($entity_info['bundles']); |
|
656 |
} |
|
657 |
|
|
658 |
foreach ($applicable_bundles as $bundle_name) { |
|
620 | 659 |
if ($flag->show_on_form) { |
621 | 660 |
$extra[$flag->entity_type][$bundle_name]['form']['flag'] = array( |
622 | 661 |
'label' => t('Flags'), |
... | ... | |
698 | 737 |
$id = NULL; |
699 | 738 |
} |
700 | 739 |
|
740 |
// Keep track of whether the entity is new or not, as we're about to fiddle |
|
741 |
// with the entity id for the flag's entity cache. |
|
742 |
$is_existing_entity = !empty($id); |
|
743 |
|
|
701 | 744 |
// Get all possible flags for this entity type. |
702 | 745 |
$flags = flag_get_flags($entity_type); |
703 | 746 |
|
... | ... | |
710 | 753 |
} |
711 | 754 |
|
712 | 755 |
// Get the flag status. |
713 |
if (isset($id)) {
|
|
756 |
if ($is_existing_entity) {
|
|
714 | 757 |
$flag_status = $flag->is_flagged($id); |
715 | 758 |
} |
716 | 759 |
else { |
... | ... | |
719 | 762 |
$flag_status = FALSE; |
720 | 763 |
// Apply the per-bundle defaults for nodes. |
721 | 764 |
if ($entity_type == 'node') { |
722 |
$flag_status = variable_get('flag_' . $flag->name . '_default_' . $form['type']['#value'], 0); |
|
765 |
$node_type = $entity->type; |
|
766 |
$flag_status = variable_get('flag_' . $flag->name . '_default_' . $node_type, 0); |
|
723 | 767 |
} |
724 | 768 |
|
725 | 769 |
// For a new, unsaved entity, make a dummy entity ID so that the flag |
... | ... | |
1646 | 1690 |
// Non-Views public API |
1647 | 1691 |
|
1648 | 1692 |
/** |
1649 |
* Get the count of flags for a certain entity.
|
|
1693 |
* Get the count of flags for a particular entity type.
|
|
1650 | 1694 |
* |
1651 | 1695 |
* @param $flag |
1652 | 1696 |
* The flag. |
1653 | 1697 |
* @param $entity_type |
1654 |
* The entity type (usually 'node').
|
|
1698 |
* The entity type. For example, 'node'.
|
|
1655 | 1699 |
* |
1656 | 1700 |
* @return |
1657 | 1701 |
* The flag count with the flag name and entity type as the array key. |
... | ... | |
2104 | 2148 |
* The "machine readable" name of the flag; e.g. 'bookmarks'. |
2105 | 2149 |
* @param $entity_id |
2106 | 2150 |
* The entity ID to check for flagging, for example a node ID. |
2151 |
* @param $variables |
|
2152 |
* An array of further variables to pass to theme('flag'). For the full list |
|
2153 |
* of parameters, see flag.tpl.php. Of particular interest: |
|
2154 |
* - after_flagging: Set to TRUE if this flag link is being displayed as the |
|
2155 |
* result of a flagging action. |
|
2156 |
* - errors: An array of error messages. |
|
2107 | 2157 |
* |
2108 | 2158 |
* @return |
2109 | 2159 |
* The HTML for the themed flag link. |
2110 | 2160 |
*/ |
2111 |
function flag_create_link($flag_name, $entity_id) { |
|
2161 |
function flag_create_link($flag_name, $entity_id, $variables = array()) {
|
|
2112 | 2162 |
$flag = flag_get_flag($flag_name); |
2113 | 2163 |
if (!$flag) { |
2114 | 2164 |
// Flag does not exist. |
... | ... | |
2118 | 2168 |
// User has no permission to use this flag. |
2119 | 2169 |
return; |
2120 | 2170 |
} |
2121 |
return $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id); |
|
2171 |
return $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, $variables);
|
|
2122 | 2172 |
} |
2123 | 2173 |
|
2124 | 2174 |
/** |
Formats disponibles : Unified diff
Weekly update of contrib modules