Revision 0e38f1bf
Added by Andreas Kohlbecker almost 2 years ago
modules/cdm_dataportal/ext_links/ext_links.module | ||
---|---|---|
81 | 81 |
/** |
82 | 82 |
* Retrieves a list of External Link templates, ordered by weight. |
83 | 83 |
* |
84 |
* @return |
|
84 |
* Empty 'ext_links' tables will be initialized with the default templates. |
|
85 |
* |
|
86 |
* @see ext_links_template_defaults() |
|
87 |
* |
|
88 |
* @return array |
|
85 | 89 |
* An array of external link template objects, keyed by the format ID and ordered by |
86 | 90 |
* weight. |
87 | 91 |
* |
... | ... | |
93 | 97 |
// cache_clear_all("ext_links_templates:{$language->language}"); |
94 | 98 |
// All available link_templates are cached for performance. |
95 | 99 |
if (!is_array($link_templates) || !count($link_templates)) { |
96 |
if ($cache = cache_get("ext_links_templates:{$language->language}")) {
|
|
100 |
if ($cache = cache_get("ext_links:{$language->language}")) { |
|
97 | 101 |
$link_templates = $cache->data; |
98 | 102 |
} |
99 | 103 |
else { |
100 |
$test = true;
|
|
104 |
$test = false;
|
|
101 | 105 |
if($test){ |
102 | 106 |
$link_templates = []; |
103 | 107 |
$link_templates_arrays = ext_links_template_defaults(); |
... | ... | |
108 | 112 |
$link_templates = db_select('ext_links', 'elt') |
109 | 113 |
->addTag('translatable') |
110 | 114 |
->fields('elt') |
111 |
->condition('status', 1)
|
|
115 |
->orderBy('category')
|
|
112 | 116 |
->orderBy('weight') |
113 |
->execute(); |
|
117 |
->execute() |
|
118 |
->fetchAllAssoc('id'); |
|
114 | 119 |
} |
115 |
// cache_set("ext_links_templates:{$language->language}", $link_templates); |
|
120 |
if(!count($link_templates)) { |
|
121 |
$link_templates_arrays = ext_links_template_defaults(); |
|
122 |
$query = db_insert('ext_links') |
|
123 |
->fields(array_keys(array_values($link_templates_arrays)[0])); |
|
124 |
foreach($link_templates_arrays as $a){ |
|
125 |
$query->values($a); |
|
126 |
} |
|
127 |
try { |
|
128 |
$query->execute(); |
|
129 |
} catch (Exception $e) { |
|
130 |
drupal_set_message("Error while initializing ext_links database: " . $e->getMessage(), "error"); |
|
131 |
} |
|
132 |
$link_templates = []; |
|
133 |
foreach($link_templates_arrays as $a){ |
|
134 |
$link_templates[] = (object)$a; |
|
135 |
} |
|
136 |
} |
|
137 |
// cache_set("ext_links:{$language->language}", $link_templates); |
|
116 | 138 |
} |
117 | 139 |
} |
118 | 140 |
return $link_templates; |
... | ... | |
124 | 146 |
* @see filter_formats() |
125 | 147 |
*/ |
126 | 148 |
function ext_links_templates_reset() { |
127 |
cache_clear_all('ext_links_templates', 'cache', TRUE);
|
|
128 |
drupal_static_reset('ext_links_templates');
|
|
149 |
cache_clear_all('ext_links', 'cache', TRUE); |
|
150 |
drupal_static_reset('ext_links'); |
|
129 | 151 |
} |
130 | 152 |
|
131 | 153 |
/** |
... | ... | |
142 | 164 |
* @see ext_links_exists() |
143 | 165 |
*/ |
144 | 166 |
function ext_links_load($extlink_id) { |
145 |
$test = TRUE;
|
|
167 |
$test = false;
|
|
146 | 168 |
if($test) { |
147 | 169 |
$defaults = ext_links_template_defaults(); |
148 | 170 |
return isset($defaults[$extlink_id]) ? (object)$defaults[$extlink_id] : FALSE; |
149 | 171 |
} |
150 | 172 |
else { |
151 |
$formats = ext_links_templates();
|
|
152 |
return isset($formats[$extlink_id]) ? $formats[$extlink_id] : FALSE;
|
|
173 |
$link_templates = ext_links_templates();
|
|
174 |
return isset($link_templates[$extlink_id]) ? $link_templates[$extlink_id] : FALSE;
|
|
153 | 175 |
} |
154 | 176 |
} |
155 | 177 |
|
... | ... | |
174 | 196 |
* SAVED_NEW or SAVED_UPDATED. |
175 | 197 |
*/ |
176 | 198 |
function ext_links_save($link_template) { |
199 |
|
|
177 | 200 |
$link_template->title = trim($link_template->title); |
178 | 201 |
$link_template->cache = true; |
179 | 202 |
if (!isset($link_template->status)) { |
... | ... | |
185 | 208 |
|
186 | 209 |
// Insert or update the text format. |
187 | 210 |
$return = db_merge('ext_links') |
188 |
->key(array('format' => $link_template->title))
|
|
211 |
->key(array('id' => $link_template->id))
|
|
189 | 212 |
->fields(array( |
190 | 213 |
'id' => $link_template->id, |
191 | 214 |
'title' => $link_template->title, |
... | ... | |
196 | 219 |
)) |
197 | 220 |
->execute(); |
198 | 221 |
|
199 |
if ($return != SAVED_NEW) { |
|
200 |
// Clear the filter cache whenever an external link is updated. |
|
201 |
cache_clear_all($link_template->format . ':', 'cache_filter', TRUE); |
|
202 |
} |
|
203 | 222 |
ext_links_templates_reset(); |
204 | 223 |
return $return; |
205 | 224 |
} |
Also available in: Unified diff
ref #9659 ext_links editing possible