title.admin.inc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * @file
  4. * Admin page callbacks for the Title module.
  5. */
  6. /**
  7. * Provide settings to enable title field.
  8. */
  9. function title_form_field_ui_overview(&$form, &$form_state) {
  10. $entity_info = entity_get_info($form['#entity_type']);
  11. if (!empty($entity_info['field replacement'])) {
  12. $field_replacement_info = $entity_info['field replacement'];
  13. $admin_path = _field_ui_bundle_admin_path($form['#entity_type'], $form['#bundle']);
  14. $form['fields']['#header'][6]['colspan'] += 1;
  15. foreach (element_children($form['fields']) as $field_name) {
  16. if (isset($field_replacement_info[$field_name])) {
  17. $form['fields'][$field_name]['field_replacement'] = array(
  18. '#type' => 'link',
  19. '#title' => t('replace'),
  20. '#href' => $admin_path . '/fields/replace/' . $field_name,
  21. '#options' => array('attributes' => array('title' => t('Replace %field with a customizable field instance that can be translated.', array('%field' => $field_name)))),
  22. );
  23. }
  24. else {
  25. $form['fields'][$field_name]['field_replacement'] = array();
  26. }
  27. }
  28. }
  29. }
  30. /**
  31. * Generate a field replacement form.
  32. */
  33. function title_field_replacement_form($form, $form_state, $entity_type, $bundle, $field_name) {
  34. $bundle_name = field_extract_bundle($entity_type, $bundle);
  35. $entity_info = entity_get_info($entity_type);
  36. $info = $entity_info['field replacement'][$field_name];
  37. $instance = field_info_instance($entity_type, $info['field']['field_name'], $bundle_name);
  38. $enabled = !empty($instance);
  39. $form['#entity_type'] = $entity_type;
  40. $form['#bundle'] = $bundle_name;
  41. $form['#field_name'] = $field_name;
  42. $form['enabled'] = array(
  43. '#type' => 'checkbox',
  44. '#title' => t('Replace %field with a field instance', array('%field' => $field_name)),
  45. '#description' => t('If this is enabled the %field will be replaced with a customizable field that can be translated.', array('%field' => $field_name)),
  46. '#default_value' => $enabled,
  47. '#disabled' => $enabled,
  48. );
  49. $form['actions'] = array('#type' => 'actions');
  50. $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save settings'));
  51. return $form;
  52. }
  53. /**
  54. * Process field replacement form subissions.
  55. */
  56. function title_field_replacement_form_submit($form, &$form_state) {
  57. if ($form_state['values']['enabled'] != $form['enabled']['#default_value']) {
  58. if (title_field_replacement_toggle($form['#entity_type'], $form['#bundle'], $form['#field_name'])) {
  59. drupal_set_message(t('%field replaced with a field instance.', array('%field' => $form['#field_name'])));
  60. title_field_replacement_batch_set($form['#entity_type'], $form['#bundle'], $form['#field_name']);
  61. }
  62. else {
  63. drupal_set_message(t('Field replacement removed.'));
  64. }
  65. }
  66. $form_state['redirect'] = _field_ui_bundle_admin_path($form['#entity_type'], $form['#bundle']) . '/fields';
  67. }
  68. /**
  69. * Form settings for automated title_field attachement.
  70. */
  71. function title_admin_settings_form() {
  72. $form['tabs'] = array(
  73. '#type' => 'vertical_tabs',
  74. );
  75. foreach (entity_get_info() as $entity_type => $info) {
  76. if (empty($info['field replacement'])) {
  77. continue;
  78. }
  79. $form['settings']['title_' . $entity_type] = array(
  80. '#type' => 'fieldset',
  81. '#collapsible' => TRUE,
  82. '#collapsed' => TRUE,
  83. '#tree' => TRUE,
  84. '#group' => 'tabs',
  85. '#title' => $info['label'],
  86. );
  87. $options = array();
  88. foreach (array_keys($info['field replacement']) as $replacement) {
  89. $options[$replacement] = drupal_ucfirst($replacement);
  90. }
  91. $default = variable_get('title_' . $entity_type, array());
  92. $form['settings']['title_' . $entity_type]['auto_attach'] = array(
  93. '#type' => 'checkboxes',
  94. '#title' => t('Automatic field replacement'),
  95. '#options' => $options,
  96. '#default_value' => !empty($default['auto_attach']) ? $default['auto_attach'] : array(),
  97. '#description' => t('Automatically replace the selected field(s) when creating a new bundle.'),
  98. );
  99. $form['settings']['title_' . $entity_type]['hide_label'] = _title_hide_label_widget($default, $info['label']);
  100. }
  101. return system_settings_form($form);
  102. }