This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
forked from drupalprojects/metatag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetatag.api.php
372 lines (348 loc) · 12.8 KB
/
metatag.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<?php
/**
* @file
* API documentation for the Metatag module.
*/
/**
* To enable Metatag support in custom entities, add 'metatags' => TRUE to the
* entity definition in hook_entity_info(), e.g.:
*
* /**
* * Implements hook_entity_info().
* *
* * Taken from the Examples module.
* * /
* function entity_example_entity_info() {
* $info['entity_example_basic'] = array(
* 'label' => t('Example Basic Entity'),
* 'controller class' => 'EntityExampleBasicController',
* 'base table' => 'entity_example_basic',
* 'uri callback' => 'entity_example_basic_uri',
* 'fieldable' => TRUE,
* 'metatags' => TRUE,
* 'entity keys' => array(
* 'id' => 'basic_id' , // The 'id' (basic_id here) is the unique id.
* 'bundle' => 'bundle_type' // Bundle will be determined by the 'bundle_type' field
* ),
* 'bundle keys' => array(
* 'bundle' => 'bundle_type',
* ),
* 'static cache' => TRUE,
* 'bundles' => array(
* 'first_example_bundle' => array(
* 'label' => 'First example bundle',
* 'admin' => array(
* 'path' => 'admin/structure/entity_example_basic/manage',
* 'access arguments' => array('administer entity_example_basic entities'),
* ),
* ),
* ),
* 'view modes' => array(
* 'tweaky' => array(
* 'label' => t('Tweaky'),
* 'custom settings' => FALSE,
* ),
* )
* );
*
* return $info;
* }
*
* The definition of each bundle may be handled separately, thus support may be
* disabled for the entity as a whole but enabled for individual bundles. This
* is handled via the 'metatags' value on the bundle definition, e.g.:
*
* 'bundles' => array(
* 'first_example_bundle' => array(
* 'label' => 'First example bundle',
* 'metatags' => TRUE,
* 'admin' => array(
* 'path' => 'admin/structure/entity_example_basic/manage',
* 'access arguments' => array('administer entity_example_basic entities'),
* ),
* ),
* ),
*/
/**
* Provides a default configuration for Metatag intances.
*
* This hook allows modules to provide their own Metatag instances which can
* either be used as-is or as a "starter" for users to build from.
*
* This hook should be placed in MODULENAME.metatag.inc and it will be auto-
* loaded. MODULENAME.metatag.inc *must* be in the same directory as the
* .module file which *must* also contain an implementation of
* hook_ctools_plugin_api, preferably with the same code as found in
* metatag_ctools_plugin_api().
*
* The $config->disabled boolean attribute indicates whether the Metatag
* instance should be enabled (FALSE) or disabled (TRUE) by default.
*
* @return
* An associative array containing the structures of Metatag instances, as
* generated from the Export tab, keyed by the Metatag config name.
*
* @see metatag_metatag_config_default()
* @see metatag_ctools_plugin_api()
*/
function hook_metatag_config_default() {
$configs = array();
$config = new stdClass();
$config->instance = 'config1';
$config->api_version = 1;
$config->disabled = FALSE;
$config->config = array(
'title' => array('value' => '[current-page:title] | [site:name]'),
'generator' => array('value' => 'Drupal 7 (http://drupal.org)'),
'canonical' => array('value' => '[current-page:url:absolute]'),
'shortlink' => array('value' => '[current-page:url:unaliased]'),
);
$configs[$config->instance] = $config;
$config = new stdClass();
$config->instance = 'config2';
$config->api_version = 1;
$config->disabled = FALSE;
$config->config = array(
'title' => array('value' => '[user:name] | [site:name]'),
);
$configs[$config->instance] = $config;
return $configs;
}
/**
* Internal hook for adding further configuration values in bundled submodules.
*
* The defaults provided by the main Metatag module need to be extended by the
* bundled submodules before they are presented to other modules for altering
* via hook_metatag_config_default_alter(), in case differences in module
* weights and loading priorities cause the submodules' settings to run after
* those of any custom modules.
*
* @see hook_metatag_config_default()
* @see hook_metatag_config_default_alter()
*/
function hook_metatag_bundled_config_alter(&$config) {
}
/**
*
*/
function hook_metatag_config_default_alter(&$config) {
}
/**
*
*/
function hook_metatag_config_delete($entity_type, $entity_ids, $revision_ids, $langcode) {
}
/**
*
*/
function hook_metatag_config_insert($config) {
}
/**
*
*/
function hook_metatag_config_instance_info() {
return array();
}
/**
*
*/
function hook_metatag_config_instance_info_alter(&$info) {
}
/**
*
*/
function hook_metatag_config_load() {
}
/**
*
*/
function hook_metatag_config_load_presave() {
}
/**
*
*/
function hook_metatag_config_presave($config) {
}
/**
*
*/
function hook_metatag_config_update($config) {
}
/**
* Definition of the meta tags and groups.
*
* @return array
* A nested array of 'tags' and 'groups', each keyed off the machine name for
* their respective structure type, with the following values:
* Tags:
* 'label' - The name for this meta tag.
* 'description' - An explanation of what this meta tag is used for and what
* values are permissible.
* 'class' - The class name that controls this meta tag.
* 'weight' - Used to sort the meta tags during output.
* 'group' - The machine name of a group this meta tag will be contained
* within.
* 'context' - Optionally control the type of configuration the meta tag
* will be available from. Possible values are:
* [empty] - All meta tags apply to all possible objects, by default.
* 'global' - This will make it only show in the global meta tag
* configuration form.
* [entity type] - Makes the meta tag only show for specific entity types.
* 'header' - Optionally output the meta tag as an HTTP header value.
* 'element' - Optional attributes for rendering the meta tag. Should
* contain the following:
* '#theme' - The theming function used to render the meta tag.
* 'replaces' - An optional array of meta tags that this meta tag replaces.
* Used to indicate that these deprecated meta tags will be replaced by
* this newer one, their values will be used, upon the next object save
* the deprecated tag will be entirely replaced by the new meta tag. While
* one meta tag can replace several others, only one of the possible
* values will be used, the others will be silently purged upon the next
* configuration/object save.
* 'form' - Optional items to be passed directly to the form; uses standard
* Form API values.
* 'devel_generate' - Optional values to be passed to the Devel Generate
* submodule. Should be an array containing one of the following values:
* 'type' - One of the following:
* 'canonical' - The token for the absolute URL for the current page.
* 'email' - An email address randomly generated at the site's hostname.
* 'float' - A random floating point number between 0.0 and 999.999.
* 'image' - A randomly generated image.
* 'integer' - A random integer between 0 and 999.
* 'phone' - A phone number in the format 999-999-9999.
* 'select' - A value randomly selected from the available form options.
* 'text' - Random text string.
* 'twitter' - A Twitter username.
* 'url' - A randomly generated URL on this site.
* 'maxlength' - The maximum length / number of iterations of this value,
* defaults to 10.
* 'dependencies' - Optional nested array of values to indicate other meta
* tags that must be present in order for this meta tag to be visible. See
* The Open Graph and Twitter Cards submodules for example usage. Each
* dependency must contain the following elements:
* 'dependency' - The name of the meta tag that is required.
* 'attribute' - The name of the other meta tag that is to be checked,
* most meta tags use "value" as the attribute name.
* 'condition' - The state condition to be checked against, e.g. "filled"
* to check text values, "checked" for a checkbox, "value" to compare
* the raw selection; see https://api.drupal.org/drupal_process_states
* for more details.
* 'value' - The field value to check the 'condition' against. see
* https://api.drupal.org/drupal_process_states for further details.
* Groups:
* 'label' - The name for this group.
* 'description' - A detailed explanation of these meta tags.
* 'form' - Additional items to be passed directly to the form.
* Note: 'label', 'description', and any text strings passed in 'form', should
* be translated.
*
* @see metatag_metatag_info().
*/
function hook_metatag_info() {
return array();
}
/**
*
*/
function hook_metatag_info_alter(&$info) {
}
/**
*
*/
function hook_metatag_load_entity_from_path_alter(&$path, $result) {
}
/**
* Alter metatags before being cached.
*
* This hook is invoked prior to the meta tags for a given page are cached.
*
* @param array $output
* All of the meta tags to be output for this page in their raw format. This
* is a heavily nested array.
* @param string $instance
* An identifier for the current page's page type, typically a combination
* of the entity name and bundle name, e.g. "node:story".
* @param array $options
* All of the options used to generate the meta tags.
*/
function hook_metatag_metatags_view_alter(&$output, $instance, $options) {
if (isset($output['description']['#attached']['drupal_add_html_head'][0][0]['#value'])) {
$output['description']['#attached']['drupal_add_html_head'][0][0]['#value'] = 'O rly?';
}
}
/**
*
*/
function hook_metatag_page_cache_cid_parts_alter(&$cid_parts) {
}
/**
*
*/
function hook_metatag_presave(&$metatags, $entity_type, $entity_id, $revision_id, $langcode) {
}
/**
* Allows modules to alter the defined list of tokens available
* for metatag patterns replacements.
*
* By default only context (for example: global, node, etc...)
* related tokens are made available to metatag patterns replacements.
* This hook allows other modules to extend the default declared tokens.
*
* @param array $options
* (optional) An array of options including the following keys and values:
* - token types: An array of token types to be passed to theme_token_tree().
* - context: An identifier for the configuration instance type, typically
* an entity name or object name, e.g. node, views, taxonomy_term.
*
* @see metatag_config_edit_form()
* @see metatag_field_attach_form()
*/
function hook_metatag_token_types_alter(&$options) {
// Watchout: $options['token types'] might be empty
if (!isset($options['token types'])) {
$options['token types'] = array();
}
if ($options['context'] == 'config1'){
$options['token types'] += array('token_type1','token_type2');
}
elseif ($options['context'] == 'config2'){
$options['token types'] += array('token_type3','token_type4');
}
}
/**
* Allows modules to alter defined token patterns and values before replacement.
*
* The metatag module defines default token patterns replacements depending on
* the different configuration instances (contexts, such as global, node, ...).
* This hook provides an opportunity for other modules to alter the patterns or
* the values for replacements, before tokens are replaced (token_replace).
*
* See facetapi and facetapi_bonus modules for an example of implementation.
*
* @param $pattern
* A string potentially containing replaceable tokens. The pattern could also
* be altered by reference, allowing modules to implement further logic, such
* as tokens lists or masks/filters.
* @param $types
* Corresponds to the 'token data' property of the $options object.
* (optional) An array of keyed objects. For simple replacement scenarios
* 'node', 'user', and others are common keys, with an accompanying node or
* user object being the value. Some token types, like 'site', do not require
* any explicit information from $data and can be replaced even if it is
* empty.
* @param string $tag_name
* The name of the meta tag being altered.
*
* @see DrupalTextMetaTag::getValue()
*/
function hook_metatag_pattern_alter(&$pattern, &$types, $tag_name) {
if (strpos($pattern, 'token_type1') !== FALSE) {
$types['token_type1'] = "data to be used in hook_tokens for replacement";
}
if (strpos($pattern, 'token_type2') !== FALSE) {
// Load something or do some operations.
$types['token_type2'] = array("Then fill in the array with the right data");
// $pattern could also be altered, for example, strip off [token_type3].
$pattern = str_replace('[token_type3]', '', $pattern);
}
}