1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
76e2e7c3
|
Assos Assos
|
* Contains the flag_node class.
|
6 |
85ad3d82
|
Assos Assos
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements a node flag.
|
10 |
|
|
*/
|
11 |
|
|
class flag_node extends flag_entity {
|
12 |
|
|
function options() {
|
13 |
|
|
$options = parent::options();
|
14 |
|
|
// Use own display settings in the meanwhile.
|
15 |
|
|
$options += array(
|
16 |
|
|
'i18n' => 0,
|
17 |
|
|
);
|
18 |
|
|
return $options;
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
/**
|
22 |
|
|
* Options form extras for node flags.
|
23 |
|
|
*/
|
24 |
|
|
function options_form(&$form) {
|
25 |
|
|
parent::options_form($form);
|
26 |
|
|
|
27 |
|
|
$form['access']['access_author'] = array(
|
28 |
|
|
'#type' => 'radios',
|
29 |
|
|
'#title' => t('Flag access by content authorship'),
|
30 |
|
|
'#options' => array(
|
31 |
|
|
'' => t('No additional restrictions'),
|
32 |
|
|
'own' => t('Users may only flag content they own'),
|
33 |
|
|
'others' => t('Users may only flag content of others'),
|
34 |
|
|
),
|
35 |
|
|
'#default_value' => $this->access_author,
|
36 |
|
|
'#description' => t("Restrict access to this flag based on the user's ownership of the content. Users must also have access to the flag through the role settings."),
|
37 |
|
|
);
|
38 |
|
|
|
39 |
|
|
// Support for i18n flagging requires Translation helpers module.
|
40 |
|
|
$form['i18n'] = array(
|
41 |
|
|
'#type' => 'radios',
|
42 |
|
|
'#title' => t('Internationalization'),
|
43 |
|
|
'#options' => array(
|
44 |
|
|
'1' => t('Flag translations of content as a group'),
|
45 |
|
|
'0' => t('Flag each translation of content separately'),
|
46 |
|
|
),
|
47 |
|
|
'#default_value' => $this->i18n,
|
48 |
|
|
'#description' => t('Flagging translations as a group effectively allows users to flag the original piece of content regardless of the translation they are viewing. Changing this setting will <strong>not</strong> update content that has been flagged already.'),
|
49 |
|
|
'#access' => module_exists('translation_helpers'),
|
50 |
|
|
'#weight' => 5,
|
51 |
|
|
);
|
52 |
|
|
|
53 |
|
|
// Override the UI texts for nodes.
|
54 |
|
|
$form['display']['show_on_form'] = array(
|
55 |
|
|
'#title' => t('Display checkbox on node edit form'),
|
56 |
|
|
'#description' => t('If you elect to have a checkbox on the node edit form, you may specify its initial state in the settings form <a href="@content-types-url">for each content type</a>.', array('@content-types-url' => url('admin/structure/types'))),
|
57 |
|
|
) + $form['display']['show_on_form'];
|
58 |
b08d2851
|
Assos Assos
|
|
59 |
|
|
// Add the 'teaser' view mode as a default value for the entity link display
|
60 |
|
|
// option if this is a new flag.
|
61 |
|
|
if (empty($this->fid)) {
|
62 |
|
|
$form['display']['show_in_links']['#default_value']['teaser'] = 'teaser';
|
63 |
|
|
}
|
64 |
85ad3d82
|
Assos Assos
|
}
|
65 |
|
|
|
66 |
|
|
function type_access_multiple($entity_ids, $account) {
|
67 |
|
|
$access = array();
|
68 |
|
|
|
69 |
|
|
// If all subtypes are allowed, we have nothing to say here.
|
70 |
|
|
if (empty($this->types)) {
|
71 |
|
|
return $access;
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
// Ensure that only flaggable node types are granted access. This avoids a
|
75 |
|
|
// node_load() on every type, usually done by applies_to_entity_id().
|
76 |
|
|
$result = db_select('node', 'n')->fields('n', array('nid'))
|
77 |
|
|
->condition('nid', array_keys($entity_ids), 'IN')
|
78 |
|
|
->condition('type', $this->types, 'NOT IN')
|
79 |
|
|
->execute();
|
80 |
|
|
foreach ($result as $row) {
|
81 |
|
|
$access[$row->nid] = FALSE;
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
return $access;
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
/**
|
88 |
|
|
* Adjust the Content ID to find the translation parent if i18n-enabled.
|
89 |
|
|
*
|
90 |
|
|
* @param $entity_id
|
91 |
|
|
* The nid for the content.
|
92 |
76e2e7c3
|
Assos Assos
|
*
|
93 |
85ad3d82
|
Assos Assos
|
* @return
|
94 |
|
|
* The tnid if available, the nid otherwise.
|
95 |
|
|
*/
|
96 |
|
|
function get_translation_id($entity_id) {
|
97 |
|
|
if ($this->i18n) {
|
98 |
|
|
$node = $this->fetch_entity($entity_id);
|
99 |
|
|
if (!empty($node->tnid)) {
|
100 |
|
|
$entity_id = $node->tnid;
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
|
|
return $entity_id;
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
function flag($action, $entity_id, $account = NULL, $skip_permission_check = FALSE, $flagging = NULL) {
|
107 |
|
|
$entity_id = $this->get_translation_id($entity_id);
|
108 |
|
|
return parent::flag($action, $entity_id, $account, $skip_permission_check, $flagging);
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
// Instead of overriding is_flagged() we override get_flagging_record(),
|
112 |
|
|
// which is the underlying method.
|
113 |
|
|
function get_flagging_record($entity_id, $uid = NULL, $sid = NULL) {
|
114 |
|
|
$entity_id = $this->get_translation_id($entity_id);
|
115 |
|
|
return parent::get_flagging_record($entity_id, $uid, $sid);
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
/**
|
119 |
|
|
* This is overridden for no other purpose than to document that $entity_id
|
120 |
|
|
* can be one of the following fake IDs in certain contexts:
|
121 |
|
|
* - 'new': On a new node form.
|
122 |
|
|
* - 'fake': On the node type admin form.
|
123 |
|
|
*/
|
124 |
|
|
function replace_tokens($label, $contexts, $options, $entity_id) {
|
125 |
|
|
return parent::replace_tokens($label, $contexts, $options, $entity_id);
|
126 |
|
|
}
|
127 |
|
|
} |