metatag.admin.inc 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. <?php
  2. /**
  3. * @file
  4. * Administration page callbacks for the metatag module.
  5. */
  6. function _metatag_config_overview_indent($text, $instance) {
  7. $parents = metatag_config_get_parent_instances($instance);
  8. array_shift($parents);
  9. // Add indentation to the leading cell.
  10. if (!empty($parents)) {
  11. $prefix = array_fill(0, count($parents), '<div class="indent">');
  12. $suffix = array_fill(0, count($parents), '</div>');
  13. $text = implode('', $prefix) . $text . implode('', $suffix);
  14. }
  15. return $text;
  16. }
  17. function metatag_config_overview() {
  18. ctools_include('export');
  19. $metatags = metatag_get_info('tags');
  20. $configs = ctools_export_crud_load_all('metatag_config');
  21. uksort($configs, '_metatag_config_instance_sort');
  22. $rows = array();
  23. foreach ($configs as $config) {
  24. $row = array();
  25. // Style disabled configurations differently.
  26. if (!empty($config->disabled)) {
  27. $row['class'][] = 'disabled';
  28. }
  29. $details = '<div class="metatag-config-label collapsed"><a href="#" class="toggle-details">' . check_plain(metatag_config_instance_label($config->instance)) . '</a></div>';
  30. $details .= '<div class="metatag-config-details js-hide">';
  31. $inherits = array();
  32. $parents = metatag_config_get_parent_instances($config->instance);
  33. array_shift($parents);
  34. foreach (array_reverse($parents) as $parent) {
  35. if (!isset($configs[$parent])) {
  36. $rows[$parent] = array(
  37. _metatag_config_overview_indent('<div class="metatag-config-label">' . check_plain(metatag_config_instance_label($parent)) . '</div>', $parent),
  38. '',
  39. );
  40. }
  41. else {
  42. $inherits[$parent] = metatag_config_instance_label($parent);
  43. if (!empty($configs[$parent]->disabled)) {
  44. $inherits[$parent] .= ' ' . t('(disabled)');
  45. }
  46. }
  47. }
  48. // Show how this config inherits from its parents.
  49. if (!empty($inherits)) {
  50. $details .= '<div class="inheritance"><p>' . t('Inherits meta tags from: @parents', array('@parents' => implode(', ', $inherits))) . '</p></div>';
  51. }
  52. // Add a summary of the configuration's defaults.
  53. $summary = array();
  54. foreach ($config->config as $metatag => $data) {
  55. // Skip meta tags that were disabled.
  56. if (empty($metatags[$metatag])) {
  57. continue;
  58. }
  59. $summary[] = array(
  60. check_plain($metatags[$metatag]['label']) . ':',
  61. check_plain(metatag_get_value($metatag, $data, array('raw' => TRUE))),
  62. );
  63. }
  64. if (!empty($summary)) {
  65. $details .= theme('table', array(
  66. 'rows' => $summary,
  67. 'attributes' => array('class' => array('metatag-value-summary')),
  68. ));
  69. }
  70. else {
  71. $details .= '<p class="warning">No overridden default meta tags</p>';
  72. $row['class'][] = 'warning';
  73. }
  74. // Close the details div
  75. $details .= '</div>';
  76. // Add indentation to the leading cell based on how many parents the config has.
  77. $details = _metatag_config_overview_indent($details, $config->instance);
  78. $row['data']['details'] = $details;
  79. $operations = array();
  80. if (metatag_config_access('disable', $config)) {
  81. $operations['edit'] = array(
  82. 'title' => ($config->export_type & EXPORT_IN_DATABASE) ? t('Edit') : t('Override'),
  83. 'href' => 'admin/config/search/metatags/config/' . $config->instance,
  84. );
  85. }
  86. if (metatag_config_access('enable', $config)) {
  87. $operations['enable'] = array(
  88. 'title' => t('Enable'),
  89. 'href' => 'admin/config/search/metatags/config/' . $config->instance . '/enable',
  90. 'query' => array(
  91. 'token' => drupal_get_token('enable-' . $config->instance),
  92. ) + drupal_get_destination(),
  93. );
  94. }
  95. if (metatag_config_access('disable', $config)) {
  96. $operations['disable'] = array(
  97. 'title' => t('Disable'),
  98. 'href' => 'admin/config/search/metatags/config/' . $config->instance . '/disable',
  99. 'query' => array(
  100. 'token' => drupal_get_token('disable-' . $config->instance),
  101. ) + drupal_get_destination(),
  102. );
  103. }
  104. if (metatag_config_access('revert', $config)) {
  105. $operations['revert'] = array(
  106. 'title' => t('Revert'),
  107. 'href' => 'admin/config/search/metatags/config/' . $config->instance . '/revert',
  108. );
  109. }
  110. if (metatag_config_access('delete', $config)) {
  111. $operations['delete'] = array(
  112. 'title' => t('Delete'),
  113. 'href' => 'admin/config/search/metatags/config/' . $config->instance . '/delete',
  114. );
  115. }
  116. $operations['export'] = array(
  117. 'title' => t('Export'),
  118. 'href' => 'admin/config/search/metatags/config/' . $config->instance . '/export',
  119. );
  120. if (module_exists('i18n_string') && !variable_get('metatag_i18n_disabled', FALSE)) {
  121. $operations['translate'] = array(
  122. 'title' => t('Translate'),
  123. 'href' => 'admin/config/search/metatags/config/' . $config->instance . '/translate',
  124. );
  125. }
  126. $row['data']['operations'] = array(
  127. 'data' => array(
  128. '#theme' => 'links',
  129. '#links' => $operations,
  130. '#attributes' => array('class' => array('links', 'inline')),
  131. ),
  132. );
  133. $rows[$config->instance] = $row;
  134. }
  135. $build['config_table'] = array(
  136. '#theme' => 'table',
  137. '#header' => array(
  138. 'type' => t('Type'),
  139. 'operations' => t('Operations'),
  140. ),
  141. '#rows' => $rows,
  142. '#empty' => t('No meta tag defaults available yet.'),
  143. '#attributes' => array(
  144. 'class' => array('metatag-config-overview'),
  145. ),
  146. '#attached' => array(
  147. 'js' => array(
  148. drupal_get_path('module', 'metatag') . '/metatag.admin.js',
  149. ),
  150. 'css' => array(
  151. drupal_get_path('module', 'metatag') . '/metatag.admin.css',
  152. ),
  153. ),
  154. '#suffix' => '<p>' . t('Any items marked "Unknown" are configurations in the system for entity types or bundles which have been disabled via the API or the <a href="@url">Settings page</a>; they will not be used.', array('@url' => url('admin/config/search/metatags/settings'))) . '</p>',
  155. );
  156. return $build;
  157. }
  158. /**
  159. * Build an FAPI #options array for the instance select field.
  160. */
  161. function _metatag_config_instance_get_available_options() {
  162. $options = array();
  163. $instances = metatag_config_instance_info();
  164. foreach ($instances as $instance => $instance_info) {
  165. if (metatag_config_load($instance)) {
  166. continue;
  167. }
  168. $parents = metatag_config_get_parent_instances($instance, FALSE);
  169. array_shift($parents);
  170. if (!empty($parents)) {
  171. $parent = reset($parents);
  172. $parent_label = isset($instances[$parent]['label']) ? $instances[$parent]['label'] : t('Unknown');
  173. if (!isset($options[$parent_label])) {
  174. $options[$parent_label] = array();
  175. if (!metatag_config_load($parent)) {
  176. $options[$parent_label][$parent] = t('All');
  177. }
  178. }
  179. $options[$parent_label][$instance] = $instance_info['label'];
  180. unset($options[$parent]);
  181. }
  182. else {
  183. $options[$instance] = $instance_info['label'];
  184. }
  185. }
  186. return $options;
  187. }
  188. function metatag_config_add_form($form, &$form_state) {
  189. $form['instance'] = array(
  190. '#type' => 'select',
  191. '#title' => t('Type'),
  192. '#description' => t('Select the type of default meta tags you would like to add.'),
  193. '#options' => _metatag_config_instance_get_available_options(),
  194. '#required' => TRUE,
  195. );
  196. $form['config'] = array(
  197. '#type' => 'value',
  198. '#value' => array(),
  199. );
  200. $form['actions']['#type'] = 'actions';
  201. $form['actions']['save'] = array(
  202. '#type' => 'submit',
  203. '#value' => t('Add and configure'),
  204. );
  205. $form['actions']['cancel'] = array(
  206. '#type' => 'link',
  207. '#title' => t('Cancel'),
  208. '#href' => isset($_GET['destination']) ? $_GET['destination'] : 'admin/config/search/metatags',
  209. );
  210. return $form;
  211. }
  212. function metatag_config_add_form_submit($form, &$form_state) {
  213. form_state_values_clean($form_state);
  214. $config = (object) $form_state['values'];
  215. metatag_config_save($config);
  216. $form_state['redirect'] = 'admin/config/search/metatags/config/' . $config->instance;
  217. }
  218. function metatag_config_edit_form($form, &$form_state, $config) {
  219. $form['cid'] = array(
  220. '#type' => 'value',
  221. '#value' => !empty($config->cid) ? $config->cid : NULL,
  222. );
  223. $form['instance'] = array(
  224. '#type' => 'value',
  225. '#value' => $config->instance,
  226. );
  227. $contexts = explode(':', $config->instance);
  228. $options['context'] = $contexts[0];
  229. if ($contexts[0] != 'global') {
  230. // The context part of the instance may not map to an entity type, so allow
  231. // the token_get_entity_mapping() function to fallback to the provided type.
  232. if ($token_type = token_get_entity_mapping('entity', $contexts[0], TRUE)) {
  233. $options['token types'] = array($token_type);
  234. }
  235. else {
  236. $options['token types'] = array($contexts[0]);
  237. }
  238. // Trigger hook_metatag_token_types_alter().
  239. // Allow the defined tokens to be modified.
  240. drupal_alter('metatag_token_types', $options);
  241. }
  242. // Ensure that this configuration is properly compared to its parent 'default'
  243. // configuration values.
  244. if (count($contexts) > 1) {
  245. // If the config is something like 'node:article' or 'taxonomy_term:tags'
  246. // then the parent default config is 'node' or 'taxonomy_term'.
  247. $default_instance = $contexts;
  248. array_pop($default_instance);
  249. $default_instance = implode(':', $default_instance);
  250. $options['defaults'] = metatag_config_load_with_defaults($default_instance);
  251. }
  252. elseif ($contexts[0] != 'global') {
  253. // If the config is something like 'node' or 'taxonomy_term' then the
  254. // parent default config is 'global'.
  255. $options['defaults'] = metatag_config_load_with_defaults('global');
  256. }
  257. else {
  258. // If the config is 'global' than there are no parent defaults.
  259. $options['defaults'] = array();
  260. }
  261. metatag_metatags_form($form, $config->instance, $config->config, $options);
  262. $form['metatags']['#type'] = 'container';
  263. $form['actions']['#type'] = 'actions';
  264. $form['actions']['save'] = array(
  265. '#type' => 'submit',
  266. '#value' => t('Save'),
  267. );
  268. $form['actions']['cancel'] = array(
  269. '#type' => 'link',
  270. '#title' => t('Cancel'),
  271. '#href' => isset($_GET['destination']) ? $_GET['destination'] : 'admin/config/search/metatags',
  272. );
  273. $form['#submit'][] = 'metatag_config_edit_form_submit';
  274. return $form;
  275. }
  276. function metatag_config_edit_form_submit($form, &$form_state) {
  277. // Build the configuration object and save it.
  278. form_state_values_clean($form_state);
  279. $config = (object) $form_state['values'];
  280. // @todo Consider renaming the config field from 'config' to 'metatags'
  281. $config->config = $config->metatags[LANGUAGE_NONE];
  282. unset($config->metatags);
  283. metatag_config_save($config);
  284. $label = metatag_config_instance_label($config->instance);
  285. drupal_set_message(t('The meta tag defaults for @label have been saved.', array('@label' => $label)));
  286. $form_state['redirect'] = 'admin/config/search/metatags';
  287. }
  288. function metatag_config_enable($config) {
  289. if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], 'enable-' . $config->instance)) {
  290. return MENU_ACCESS_DENIED;
  291. }
  292. ctools_export_crud_enable('metatag_config', $config);
  293. $label = metatag_config_instance_label($config->instance);
  294. drupal_set_message(t('The meta tag defaults for @label have been enabled.', array('@label' => $label)));
  295. drupal_goto();
  296. }
  297. function metatag_config_disable($config) {
  298. if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], 'disable-' . $config->instance)) {
  299. return MENU_ACCESS_DENIED;
  300. }
  301. ctools_export_crud_disable('metatag_config', $config);
  302. $label = metatag_config_instance_label($config->instance);
  303. drupal_set_message(t('The meta tag defaults for @label have been disabed.', array('@label' => $label)));
  304. drupal_goto();
  305. }
  306. function metatag_config_delete_form($form, &$form_state, $config) {
  307. $form['cid'] = array('#type' => 'value', '#value' => $config->cid);
  308. $form['instance'] = array('#type' => 'value', '#value' => $config->instance);
  309. $label = metatag_config_instance_label($config->instance);
  310. $delete = metatag_config_access('delete', $config);
  311. $title = $delete ? t('Are you sure you want to delete the meta tag defaults for @label?', array('@label' => $label)) : t('Are you sure you want to revert the meta tag defaults for @label?', array('@label' => $label));
  312. return confirm_form(
  313. $form,
  314. $title,
  315. 'admin/config/search/metatags',
  316. t('This action cannot be undone.')
  317. );
  318. }
  319. function metatag_config_delete_form_submit($form, &$form_state) {
  320. $config = metatag_config_load($form_state['values']['instance']);
  321. metatag_config_delete($config);
  322. $label = metatag_config_instance_label($config->instance);
  323. $delete = metatag_config_access('delete', $config);
  324. $title = $delete ? t('The meta tag defaults for @label have been deleted.', array('@label' => $label)) : t('The meta tag defaults for @label have been reverted.', array('@label' => $label));
  325. drupal_set_message($title);
  326. $form_state['redirect'] = 'admin/config/search/metatags';
  327. }
  328. function metatag_config_export_form($config) {
  329. ctools_include('export');
  330. return drupal_get_form('ctools_export_form', ctools_export_crud_export('metatag_config', $config), t('Export'));
  331. }
  332. /**
  333. * Form constructor to revert nodes to their default metatags.
  334. *
  335. * @see metatag_bulk_revert_form_submit()
  336. * @ingroup forms
  337. */
  338. function metatag_bulk_revert_form() {
  339. // Get the list of entity:bundle options
  340. $options = array();
  341. foreach (entity_get_info() as $entity_type => $entity_info) {
  342. foreach (array_keys($entity_info['bundles']) as $bundle) {
  343. if (metatag_entity_supports_metatags($entity_type, $bundle)) {
  344. $options[$entity_type . ':' . $bundle] =
  345. $entity_info['label'] . ': ' . $entity_info['bundles'][$bundle]['label'];
  346. }
  347. }
  348. }
  349. $form['update'] = array(
  350. '#type' => 'checkboxes',
  351. '#required' => TRUE,
  352. '#title' => t('Select the entities to revert'),
  353. '#options' => $options,
  354. '#default_value' => array(),
  355. '#description' => t('All meta tags will be removed for all content of the selected entities.'),
  356. );
  357. $form['submit'] = array(
  358. '#type' => 'submit',
  359. '#value' => t('Revert'),
  360. );
  361. return $form;
  362. }
  363. /**
  364. * Form submit handler for metatag reset bulk revert form.
  365. *
  366. * @see metatag_batch_revert_form()
  367. * @see metatag_bulk_revert_batch_finished()
  368. */
  369. function metatag_bulk_revert_form_submit($form, &$form_state) {
  370. $batch = array(
  371. 'title' => t('Bulk updating metatags'),
  372. 'operations' => array(),
  373. 'finished' => 'metatag_bulk_revert_batch_finished',
  374. 'file' => drupal_get_path('module', 'metatag') . '/metatag.admin.inc',
  375. );
  376. // Set a batch operation per entity:bundle.
  377. foreach (array_filter($form_state['values']['update']) as $option) {
  378. list($entity_type, $bundle) = explode(':', $option);
  379. $batch['operations'][] = array('metatag_bulk_revert_batch_operation', array($entity_type, $bundle));
  380. }
  381. batch_set($batch);
  382. }
  383. /**
  384. * Batch callback: delete custom metatags for selected bundles.
  385. */
  386. function metatag_bulk_revert_batch_operation($entity_type, $bundle, &$context) {
  387. if (!isset($context['sandbox']['current'])) {
  388. $context['sandbox']['count'] = 0;
  389. $context['sandbox']['current'] = 0;
  390. }
  391. // Query the selected entity table.
  392. $entity_info = entity_get_info($entity_type);
  393. $query = new EntityFieldQuery();
  394. $query->entityCondition('entity_type', $entity_type)
  395. ->propertyCondition($entity_info['entity keys']['id'], $context['sandbox']['current'], '>')
  396. ->propertyOrderBy($entity_info['entity keys']['id']);
  397. if ($entity_type != 'user') {
  398. /**
  399. * Entities which do not define a bundle such as User fail returning no results.
  400. * @see https://www.drupal.org/node/1054168#comment-5266208
  401. */
  402. $query->entityCondition('bundle', $bundle);
  403. }
  404. // Get the total amount of entities to process.
  405. if (!isset($context['sandbox']['total'])) {
  406. $context['sandbox']['total'] = $query->count()->execute();
  407. $query->count = FALSE;
  408. // If there are no bundles to revert, stop immediately.
  409. if (!$context['sandbox']['total']) {
  410. $context['finished'] = 1;
  411. return;
  412. }
  413. }
  414. // Process 25 entities per iteration.
  415. $query->range(0, 25);
  416. $result = $query->execute();
  417. $entity_ids = !empty($result[$entity_type]) ? array_keys($result[$entity_type]) : array();
  418. foreach ($entity_ids as $entity_id) {
  419. $metatags = metatag_metatags_load($entity_type, $entity_id);
  420. if (!empty($metatags)) {
  421. db_delete('metatag')->condition('entity_type', $entity_type)
  422. ->condition('entity_id', $entity_id)
  423. ->execute();
  424. metatag_metatags_cache_clear($entity_type, $entity_id);
  425. $context['results'][] = t('Reverted metatags for @bundle with id @id.', array(
  426. '@bundle' => $entity_type . ': ' . $bundle,
  427. '@id' => $entity_id,
  428. ));
  429. }
  430. }
  431. $context['sandbox']['count'] += count($entity_ids);
  432. $context['sandbox']['current'] = max($entity_ids);
  433. if ($context['sandbox']['count'] != $context['sandbox']['total']) {
  434. $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
  435. }
  436. }
  437. /**
  438. * Batch finished callback.
  439. */
  440. function metatag_bulk_revert_batch_finished($success, $results, $operations) {
  441. if ($success) {
  442. if (!count($results)) {
  443. drupal_set_message(t('No metatags were reverted.'));
  444. }
  445. else {
  446. $message = theme('item_list', array('items' => $results));
  447. drupal_set_message($message);
  448. }
  449. }
  450. else {
  451. $error_operation = reset($operations);
  452. drupal_set_message(t('An error occurred while processing @operation with arguments : @args',
  453. array('@operation' => $error_operation[0], '@args' => print_r($error_operation[0], TRUE))));
  454. }
  455. }
  456. /**
  457. * Misc settings page.
  458. */
  459. function metatag_admin_settings_form() {
  460. $form = array();
  461. $form['#attached'] = array(
  462. 'js' => array(
  463. drupal_get_path('module', 'metatag') . '/metatag.admin.js',
  464. ),
  465. 'css' => array(
  466. drupal_get_path('module', 'metatag') . '/metatag.admin.css',
  467. ),
  468. );
  469. $form['entities'] = array(
  470. '#type' => 'fieldset',
  471. '#title' => t('Master controls for all entities'),
  472. '#description' => t('By enabling and disabling items here, it is possible to control which entities (e.g. nodes, taxonomy terms) and bundles (e.g. content types, vocabularies) will have the meta tag form available on their respective edit pages. If an entity type is disabled it also disables it for <em>all</em> of that entity type\'s bundles.<br />Technical note: Entity types must not be configuration entities and must have view modes in order to be compatible.'),
  473. '#collapsible' => TRUE,
  474. '#collapsed' => FALSE,
  475. );
  476. foreach (entity_get_info() as $entity_type => $entity_info) {
  477. // Only show entities that are capable of using meta tags.
  478. if (metatag_entity_type_is_suitable($entity_type, $entity_info)) {
  479. $entity_enabled = metatag_entity_supports_metatags($entity_type);
  480. $form['entities']['metatag_enable_' . $entity_type] = array(
  481. '#type' => 'checkbox',
  482. '#title' => t($entity_info['label']),
  483. '#default_value' => $entity_enabled,
  484. // '#description' => t('Enable meta tags for all pages of this entity type.'),
  485. );
  486. // Some entities, e.g. User, (core) File, have a single bundle with the
  487. // same name as the entity, so only show the bundles list if there is
  488. // more than one of them and the bundle's name isn't the same as the
  489. // entity type's.
  490. if (!empty($entity_info['bundles'])) {
  491. foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
  492. if (count($entity_info['bundles']) > 1 || $entity_type != $bundle_name) {
  493. // If the entity type was disabled, automatically enable the bundle.
  494. // This will have the effect that if the entity type is enabled in
  495. // the form then all of the bundles will then also be enabled. This
  496. // is safe to do because in the rest of the module the bundle will
  497. // be ignored if the entity is disabled.
  498. $form['entities']['metatag_enable_' . $entity_type . '__' . $bundle_name] = array(
  499. '#type' => 'checkbox',
  500. '#title' => t($bundle_info['label']),
  501. '#default_value' => !$entity_enabled || metatag_entity_supports_metatags($entity_type, $bundle_name),
  502. '#attributes' => array(
  503. // Add some theming that'll indent this bundle.
  504. 'class' => array('metatag-bundle-checkbox'),
  505. ),
  506. '#states' => array(
  507. 'visible' => array(
  508. ':input[name="metatag_enable_' . $entity_type . '"]' => array('checked' => TRUE),
  509. ),
  510. ),
  511. );
  512. }
  513. }
  514. }
  515. }
  516. }
  517. $form['additional'] = array(
  518. '#type' => 'fieldset',
  519. '#title' => t('Additional settings'),
  520. '#collapsible' => TRUE,
  521. '#collapsed' => FALSE,
  522. );
  523. $form['additional']['metatag_pager_string'] = array(
  524. '#title' => t('Custom pager string'),
  525. '#type' => 'textfield',
  526. '#description' => t('When the current page includes a pager, e.g. the URL contains "?page=42", the [current-page:pager] token may be added to a meta tag to differentiate between two pages that would otherwise have the same meta tags. The value "PAGER" (must be in uppercase) will be replaced by the actual page count. Note: the pager will only output if the page number is 2 or above and the string "page=NUMBER" is in the URL.<br />For best use, it may be worthwhile to add the [current-page:pager] to the page title to the left of the site name, to the start of description tags, etc.'),
  527. '#default_value' => variable_get('metatag_pager_string', 'Page PAGER | '),
  528. );
  529. $form['i18n'] = array(
  530. '#type' => 'fieldset',
  531. '#title' => t('Internationalization options'),
  532. '#description' => t('Additional options are available when using the <a href="@url">Internationalization module</a>.', array('@url' => 'https://www.drupal.org/project/i18n')),
  533. '#collapsible' => TRUE,
  534. '#collapsed' => FALSE,
  535. );
  536. $form['i18n']['metatag_i18n_disabled'] = array(
  537. '#title' => t('Disable i18n integration'),
  538. '#type' => 'checkbox',
  539. '#description' => t('If the i18n_string module is enabled but the site does not need to translate Metatag strings, the integration may be disabled to avoid a large volume of records being added to the translation system.'),
  540. '#default_value' => variable_get('metatag_i18n_disabled', FALSE),
  541. '#disabled' => !module_exists('i18n_string'),
  542. );
  543. $form['i18n']['metatag_i18n_translate_output'] = array(
  544. '#title' => t('Translate output'),
  545. '#type' => 'checkbox',
  546. '#description' => t('Optionally translate the final page output.'),
  547. '#default_value' => variable_get('metatag_i18n_translate_output', FALSE),
  548. '#disabled' => !module_exists('i18n_string'),
  549. );
  550. $form['i18n']['metatag_i18n_enable_watchdog'] = array(
  551. '#title' => t('Enable logging of translations to Watchdog'),
  552. '#type' => 'checkbox',
  553. '#description' => t('Optionally log to Watchdog any changes that happen.'),
  554. '#default_value' => variable_get('metatag_i18n_enable_watchdog', FALSE),
  555. '#disabled' => !module_exists('i18n_string'),
  556. );
  557. $form['advanced'] = array(
  558. '#type' => 'fieldset',
  559. '#title' => t('Advanced settings'),
  560. '#collapsible' => TRUE,
  561. '#collapsed' => TRUE,
  562. );
  563. $form['advanced']['metatag_load_all_pages'] = array(
  564. '#type' => 'checkbox',
  565. '#title' => t('Output meta tags even if only global settings apply'),
  566. '#description' => t('By default Metatag will load the global default values for all pages that do not have meta tags assigned via the normal entity display or via Metatag Context. This may be disabled so that meta tags will only be output on pages that specifically have meta tags configured for them.'),
  567. '#default_value' => variable_get('metatag_load_all_pages', TRUE),
  568. );
  569. $form['advanced']['metatag_tag_admin_pages'] = array(
  570. '#type' => 'checkbox',
  571. '#title' => t('Output meta tags on admin pages'),
  572. '#description' => t('By default meta tags will not be output on admin pages, but it may be beneficial for some sites to do so.'),
  573. '#default_value' => variable_get('metatag_tag_admin_pages', FALSE),
  574. );
  575. $form['advanced']['metatag_extended_permissions'] = array(
  576. '#type' => 'checkbox',
  577. '#title' => t('Advanced permissions'),
  578. '#description' => t('Optionally add a permission for each individual meta tag. This provides tremendous flexibility for the editorial process, at the expense of making the permissions configuration more tedious.'),
  579. '#default_value' => variable_get('metatag_extended_permissions', FALSE),
  580. );
  581. $form['advanced']['metatag_entity_no_lang_default'] = array(
  582. '#type' => 'checkbox',
  583. '#title' => t("Don't load entity's default language values if no languages match"),
  584. '#description' => t("On a site with multiple languages it is possible for an entity to not have meta tag values assigned for the language of the current page. By default the meta tags for an entity's default language value will be used in this scenario, with the canonical URL pointing to the URL. This option may be disabled, i.e. to only load meta tags for languages that specifically have them assigned, otherwise using defaults."),
  585. '#default_value' => variable_get('metatag_entity_no_lang_default', FALSE),
  586. );
  587. $form['advanced']['metatag_load_defaults'] = array(
  588. '#type' => 'checkbox',
  589. '#title' => t("Load the module's default configurations"),
  590. '#description' => t("Control whether the module's default configuration is used. This will not affect configurations exported via Features."),
  591. '#default_value' => variable_get('metatag_load_defaults', TRUE),
  592. );
  593. $form['advanced']['metatag_cache_output'] = array(
  594. '#type' => 'checkbox',
  595. '#title' => t('Cache meta tag output'),
  596. '#description' => t('Disabling this will cause all meta tag output to be generated uniquely for each page load. Currently only affects entities. Note: the entity configuration and output for other types of pages will still be cached, but this can stop the {cache_metatag} table from growing out of control in some scenarios.'),
  597. '#default_value' => variable_get('metatag_cache_output', TRUE),
  598. );
  599. $form['advanced']['metatag_leave_core_tags'] = array(
  600. '#type' => 'checkbox',
  601. '#title' => t("Leave core's meta tags as-is"),
  602. '#description' => t("Drupal core outputs a number of meta tags itself: canonical, shortlink, and generator. Metatag can be used to replace these with custom values. Should Metatag not have values for these meta tags, core's tags will normally be removed. Enabling this option will leave those meta tags on the page, even if Metatag is not replacing them."),
  603. '#default_value' => variable_get('metatag_leave_core_tags', FALSE),
  604. );
  605. $form['advanced']['metatag_page_region'] = array(
  606. '#type' => 'select',
  607. '#title' => t("Page region to use"),
  608. '#description' => t("By default Metatag uses the 'Content' region to trigger output of the meta tags. Some themes do not have this region, so it can be necessary to pick another."),
  609. '#options' => system_region_list(variable_get('theme_default', 'bartik')),
  610. '#default_value' => variable_get('metatag_page_region', 'content'),
  611. );
  612. $form['advanced']['metatag_token_sanitize'] = array(
  613. '#type' => 'checkbox',
  614. '#title' => t('Sanitize content during token replacement'),
  615. '#description' => t('If checked, will ensure that metatag value output is encoded and text filters are processed.'),
  616. '#default_value' => variable_get('metatag_token_sanitize', FALSE),
  617. );
  618. // Extra submission logic.
  619. $form['#submit'][] = 'metatag_admin_settings_form_submit';
  620. return system_settings_form($form);
  621. }
  622. /**
  623. * Form API submission callback for metatag_admin_settings_form().
  624. */
  625. function metatag_admin_settings_form_submit() {
  626. cache_clear_all('entity_info:', 'cache', TRUE);
  627. cache_clear_all('*', 'cache_metatag', TRUE);
  628. drupal_set_message(t('The Metatag cache has been cleared, so all meta tags can be reloaded.'));
  629. }