| 1 |
<?php
|
| 2 |
// $Id: $
|
| 3 |
|
| 4 |
/**
|
| 5 |
*@file
|
| 6 |
* Adds prefix/suffix values for cck widgets
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_help().
|
| 11 |
*/
|
| 12 |
function form_markup_help($section) {
|
| 13 |
switch ($section) {
|
| 14 |
case 'admin/modules#description':
|
| 15 |
return t('Adds prefix/suffix attributes for CCK fields. Requires the <em>Content.module</em>.');
|
| 16 |
}
|
| 17 |
}
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Implementation of hook_form_alter().
|
| 21 |
*/
|
| 22 |
function form_markup_form_alter($form_id, &$form) {
|
| 23 |
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
|
| 24 |
|
| 25 |
$markup_fields = array();
|
| 26 |
$info = _content_type_info();
|
| 27 |
foreach ($info['content types'] as $content_typ) {
|
| 28 |
foreach ($content_typ['fields'] as $field_name => $field_values) {
|
| 29 |
if ($field_values['type_name'] == $form['type']['#value']) {
|
| 30 |
if ($field_values['widget']['prefix']) $markup_fields[$field_name]['prefix'] = $field_values['widget']['prefix'];
|
| 31 |
if ($field_values['widget']['suffix']) $markup_fields[$field_name]['suffix'] = $field_values['widget']['suffix'];
|
| 32 |
}
|
| 33 |
}
|
| 34 |
}
|
| 35 |
|
| 36 |
if (module_exists('fieldgroup')) {
|
| 37 |
foreach (fieldgroup_groups($form['type']['#value']) as $group_name => $group) {
|
| 38 |
foreach ($group['fields'] as $field_name => $field) {
|
| 39 |
if (is_array($markup_fields[$field_name])) {
|
| 40 |
if ($markup_fields[$field_name]['prefix']) $form[$group_name][$field_name]['#prefix'] = $markup_fields[$field_name]['prefix'];
|
| 41 |
if ($markup_fields[$field_name]['suffix']) $form[$group_name][$field_name]['#suffix'] = $markup_fields[$field_name]['suffix'];
|
| 42 |
unset($markup_fields[$field_name]);
|
| 43 |
}
|
| 44 |
}
|
| 45 |
}
|
| 46 |
}
|
| 47 |
|
| 48 |
foreach ($markup_fields as $field_name => $settings) {
|
| 49 |
if (is_array($form[$field_name])) {
|
| 50 |
if ($markup_fields[$field_name]['prefix']) $form[$field_name]['#prefix'] = $markup_fields[$field_name]['prefix'];
|
| 51 |
if ($markup_fields[$field_name]['suffix']) $form[$field_name]['#suffix'] = $markup_fields[$field_name]['suffix'];
|
| 52 |
unset($markup_fields[$field_name]);
|
| 53 |
}
|
| 54 |
}
|
| 55 |
}
|
| 56 |
elseif ($form_id == '_content_admin_field') {
|
| 57 |
$form['widget']['markup'] = array(
|
| 58 |
'#type' => 'fieldset',
|
| 59 |
'#title' => t('Markup'),
|
| 60 |
'#collapsible' => TRUE,
|
| 61 |
);
|
| 62 |
$form['widget']['markup']['prefix'] = array(
|
| 63 |
'#type' => 'textfield',
|
| 64 |
'#title' => t('Prefix'),
|
| 65 |
'#size' => 60,
|
| 66 |
'#default_value' => _form_markup_get_default_value($form['type_name']['#value'], $form['field_name']['#value'], 'prefix'),
|
| 67 |
);
|
| 68 |
$form['widget']['markup']['suffix'] = array(
|
| 69 |
'#type' => 'textfield',
|
| 70 |
'#title' => t('Suffix'),
|
| 71 |
'#size' => 60,
|
| 72 |
'#default_value' => _form_markup_get_default_value($form['type_name']['#value'], $form['field_name']['#value'], 'suffix'),
|
| 73 |
);
|
| 74 |
$form['#submit']['form_markup_submit'] = array();
|
| 75 |
}
|
| 76 |
}
|
| 77 |
|
| 78 |
function form_markup_submit($form_name, $form_values) {
|
| 79 |
if (!empty($form_values['prefix']) || !empty($form_values['suffix'])) {
|
| 80 |
$info = _content_type_info();
|
| 81 |
$widget_settings = $info['content types'][$form_values['type_name']]['fields'][$form_values['field_name']]['widget'];
|
| 82 |
if (!empty($form_values['prefix'])) $widget_settings['prefix'] = $form_values['prefix'];
|
| 83 |
if (!empty($form_values['suffix'])) $widget_settings['suffix'] = $form_values['suffix'];
|
| 84 |
|
| 85 |
db_query("UPDATE {node_field_instance} SET widget_settings = '%s'
|
| 86 |
WHERE type_name = '%s' AND field_name = '%s'", serialize($widget_settings), $form_values['type_name'], $form_values['field_name']);
|
| 87 |
content_clear_type_cache();
|
| 88 |
}
|
| 89 |
}
|
| 90 |
|
| 91 |
|
| 92 |
function _form_markup_get_default_value($type_name, $field_name, $value) {
|
| 93 |
$info = _content_type_info();
|
| 94 |
return $info['content types'][$type_name]['fields'][$field_name]['widget'][$value];
|
| 95 |
}
|
| 96 |
|
| 97 |
|
| 98 |
?>
|