1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Plugin definition.
|
5 |
|
|
*/
|
6 |
|
|
$plugin = array(
|
7 |
|
|
'title' => t('Flag link'),
|
8 |
|
|
'description' => t('Add a flag link of a certain flag type for entities.'),
|
9 |
|
|
'defaults' => array('flag_name' => ''),
|
10 |
|
|
'content type' => 'flag_flag_link_content_type_info',
|
11 |
|
|
);
|
12 |
|
|
|
13 |
|
|
/**
|
14 |
|
|
* Get the entity content type info.
|
15 |
|
|
*/
|
16 |
|
|
function flag_flag_link_content_type_info($entity_type) {
|
17 |
|
|
$types = flag_flag_link_content_type_content_types();
|
18 |
|
|
if (isset($types[$entity_type])) {
|
19 |
|
|
return $types[$entity_type];
|
20 |
|
|
}
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
/**
|
24 |
|
|
* Implements hook_PLUGIN_content_type_content_types().
|
25 |
|
|
*/
|
26 |
|
|
function flag_flag_link_content_type_content_types() {
|
27 |
b08d2851
|
Assos Assos
|
$types = &drupal_static(__FUNCTION__);
|
28 |
|
|
if (isset($types)) {
|
29 |
|
|
return $types;
|
30 |
|
|
}
|
31 |
|
|
|
32 |
85ad3d82
|
Assos Assos
|
$types = array();
|
33 |
|
|
$entities = entity_get_info();
|
34 |
|
|
|
35 |
|
|
foreach ($entities as $entity_type => $info) {
|
36 |
b08d2851
|
Assos Assos
|
$types[$entity_type] = array(
|
37 |
|
|
'title' => t('Flag for @entity_type', array('@entity_type' => $info['label'])),
|
38 |
|
|
'category' => t('Entity'),
|
39 |
|
|
'required context' => new ctools_context_required(t('Entity'), $entity_type),
|
40 |
|
|
);
|
41 |
85ad3d82
|
Assos Assos
|
}
|
42 |
|
|
|
43 |
|
|
return $types;
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
/**
|
47 |
|
|
* Render callback.
|
48 |
|
|
*/
|
49 |
|
|
function flag_flag_link_content_type_render($subtype, $conf, $args, $context) {
|
50 |
|
|
$flag = flag_get_flag($conf['flag_name']);
|
51 |
|
|
if (!$flag) {
|
52 |
|
|
return;
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
if (empty($context->data)) {
|
56 |
|
|
return;
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
// Get the ID of the entity.
|
60 |
|
|
list($id,,) = entity_extract_ids($flag->entity_type, $context->data);
|
61 |
|
|
$link = flag_create_link($flag->name, $id);
|
62 |
|
|
|
63 |
|
|
if (!$link) {
|
64 |
|
|
return;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
$block = new stdClass();
|
68 |
|
|
$block->module = 'flag';
|
69 |
|
|
$block->title = t('Flag link');
|
70 |
|
|
$block->delta = $flag->name;
|
71 |
|
|
|
72 |
|
|
$block->content = $link;
|
73 |
|
|
return $block;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
/**
|
77 |
|
|
* Form callback.
|
78 |
|
|
*/
|
79 |
|
|
function flag_flag_link_content_type_edit_form($form, &$form_state) {
|
80 |
|
|
$conf = $form_state['conf'];
|
81 |
|
|
$entity_type = $form_state['subtype_name'];
|
82 |
|
|
$options = array();
|
83 |
|
|
|
84 |
|
|
foreach (flag_get_flags($entity_type) as $flag) {
|
85 |
|
|
$options[$flag->name] = $flag->title;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
$form['flag_name'] = array(
|
89 |
|
|
'#type' => 'select',
|
90 |
|
|
'#title' => t('Flag name'),
|
91 |
|
|
'#default_value' => $conf['flag_name'],
|
92 |
|
|
'#options' => $options,
|
93 |
|
|
'#description' => t('Select a flag.'),
|
94 |
|
|
'#required' => TRUE,
|
95 |
|
|
'#disabled' => !$options,
|
96 |
|
|
);
|
97 |
|
|
|
98 |
|
|
return $form;
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
/**
|
102 |
|
|
* Form submit.
|
103 |
|
|
*/
|
104 |
|
|
function flag_flag_link_content_type_edit_form_submit($form, &$form_state) {
|
105 |
|
|
// Copy everything from our defaults.
|
106 |
|
|
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
107 |
|
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
/**
|
112 |
|
|
* Returns the administrative title for a flag link.
|
113 |
|
|
*/
|
114 |
|
|
function flag_flag_link_content_type_admin_title($subtype, $conf) {
|
115 |
|
|
if ($flag = flag_get_flag($conf['flag_name'])) {
|
116 |
|
|
return t('Flag link of @flag', array('@flag' => $flag->title));
|
117 |
|
|
}
|
118 |
|
|
} |