1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Features integration for Flag module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements hook_features_export().
|
10 |
|
|
*/
|
11 |
|
|
function flag_features_export($data, &$export, $module_name = '') {
|
12 |
|
|
$pipe = array();
|
13 |
|
|
|
14 |
|
|
// Add flag module as a dependency.
|
15 |
|
|
$export['dependencies']['flag'] = 'flag';
|
16 |
|
|
|
17 |
|
|
// Ensure the modules that provide the flag are included as dependencies.
|
18 |
|
|
$modules = flag_features_providing_module();
|
19 |
|
|
foreach ($data as $key => $flag) {
|
20 |
|
|
$module = '';
|
21 |
|
|
if ($flag = flag_load($flag, TRUE)) {
|
22 |
|
|
// Try to get the module that provides the entity this flag is on.
|
23 |
|
|
// First pass: check whether there's a module that implements
|
24 |
|
|
// hook_flag_type_info() for this entity.
|
25 |
|
|
if (array_key_exists($flag->entity_type, $modules)) {
|
26 |
|
|
$module = $modules[$flag->entity_type];
|
27 |
|
|
}
|
28 |
|
|
else {
|
29 |
|
|
// Second pass: check whether this entity is defined using Entity API
|
30 |
|
|
// and therefore has an extra 'module' property in its information.
|
31 |
|
|
if ($entity_info = entity_get_info($flag->entity_type)) {
|
32 |
|
|
if (isset($entity_info['module'])) {
|
33 |
|
|
$module = $entity_info['module'];
|
34 |
|
|
}
|
35 |
|
|
}
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
if (!empty($module)) {
|
39 |
|
|
$export['dependencies'][$module] = $module;
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
$export['features']['flag'][$flag->name] = $flag->name;
|
43 |
|
|
}
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
return $pipe;
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
/**
|
50 |
|
|
* Implements hook_features_export_options().
|
51 |
|
|
*/
|
52 |
|
|
function flag_features_export_options() {
|
53 |
|
|
$options = array();
|
54 |
|
|
// Get all flags, including disabled defaults.
|
55 |
|
|
$flags = flag_get_flags() + flag_get_default_flags(TRUE);
|
56 |
|
|
foreach ($flags as $name => $flag) {
|
57 |
|
|
$options[$name] = drupal_ucfirst(check_plain($flag->entity_type)) . ': ' . check_plain($flag->title);
|
58 |
|
|
}
|
59 |
|
|
return $options;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
/**
|
63 |
|
|
* Implements hook_features_export_render().
|
64 |
|
|
*/
|
65 |
|
|
function flag_features_export_render($module, $data) {
|
66 |
|
|
module_load_include('inc', 'flag', '/includes/flag.export');
|
67 |
|
|
$code = flag_export_flags($data, $module, ' ');
|
68 |
|
|
return array('flag_default_flags' => $code);
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
/**
|
72 |
|
|
* Implements hook_features_revert().
|
73 |
|
|
*
|
74 |
|
|
* @param $module
|
75 |
|
|
* The name of module for which to revert content.
|
76 |
|
|
*/
|
77 |
|
|
function flag_features_revert($module = NULL) {
|
78 |
|
|
// Get default flags from features.
|
79 |
|
|
if (module_hook($module, 'flag_default_flags')) {
|
80 |
|
|
module_load_include('inc', 'flag', '/includes/flag.admin');
|
81 |
|
|
$default_flags = module_invoke($module, 'flag_default_flags');
|
82 |
|
|
|
83 |
|
|
// Build up values for the cache clear.
|
84 |
|
|
$entity_types = array();
|
85 |
|
|
|
86 |
|
|
// Revert flags that are defined in code.
|
87 |
|
|
foreach ($default_flags as $flag_name => $flag_info) {
|
88 |
|
|
if (is_numeric($flag_name)) {
|
89 |
|
|
// Backward compatibility.
|
90 |
|
|
$flag_name = $flag_info['name'];
|
91 |
|
|
}
|
92 |
|
|
$flag = flag_load($flag_name, TRUE);
|
93 |
|
|
if ($flag && $flag->revert() === FALSE) {
|
94 |
|
|
drupal_set_message(t('Could not revert flag %flag-name to the state described in your code: Your flag was created by a different version of the Flag module than is now being used.', array('%flag-name' => $flag->name)), 'error');
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
$entity_types[] = $flag->entity_type;
|
98 |
|
|
}
|
99 |
|
|
_flag_clear_cache($entity_types);
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
/**
|
104 |
|
|
* Helper function; Retrieve the providing modules defining the flags.
|
105 |
|
|
*/
|
106 |
|
|
function flag_features_providing_module() {
|
107 |
|
|
$modules = array();
|
108 |
|
|
$hook = 'flag_type_info';
|
109 |
|
|
foreach (module_implements($hook) as $module) {
|
110 |
|
|
foreach (module_invoke($module, $hook) as $key => $value) {
|
111 |
|
|
$modules[$key] = isset($value['module']) ? $value['module'] : $module;
|
112 |
|
|
}
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
// Any entity type without a flag providing module will be provided by the
|
116 |
|
|
// flag module.
|
117 |
|
|
foreach (entity_get_info() as $entity_type => $entity) {
|
118 |
|
|
if (!isset($modules[$entity_type]) && empty($entity['configuration']) && $entity_type !== 'taxonomy_vocabulary') {
|
119 |
|
|
$modules[$entity_type] = 'flag';
|
120 |
|
|
}
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
return $modules;
|
124 |
|
|
} |