function _noderelationships_cck_admin_forms_alter in Node Relationships 6
Alter CCK administration forms.
See also
noderelationships_form_alter()
1 call to _noderelationships_cck_admin_forms_alter()
- noderelationships_form_alter in ./
noderelationships.module - Implementation of hook_form_alter().
File
- ./
noderelationships.admin.inc, line 791 - Implementation of the administration pages of the module.
Code
function _noderelationships_cck_admin_forms_alter(&$form, $form_state, $form_id) {
// Alter CCK fields overview form (Manage fields screen).
if ($form_id == 'content_field_overview_form') {
if (isset($form['_add_new_field']) && isset($form['_add_new_field']['type']) && isset($form['_add_new_field']['type']['#options'])) {
// Hide back reference fields from the "Add new field" selector to
// prevent users from creating Back reference fields manually.
// We will create these kind of fields from the back reference settings
// page provided by node relationships module itself.
if (isset($form['_add_new_field']['type']['#options']['noderelationships_backref'])) {
unset($form['_add_new_field']['type']['#options']['noderelationships_backref']);
}
}
if (isset($form['_add_existing_field']) && isset($form['_add_existing_field']['field_name']) && isset($form['_add_existing_field']['field_name']['#options'])) {
// Hide back reference fields from the "Add existing field" selector to
// prevent the field from being shared. We don't want per field tables.
foreach (content_fields() as $field) {
if ($field['type'] == 'noderelationships_backref' && isset($form['_add_existing_field']['field_name']['#options'][$field['field_name']])) {
unset($form['_add_existing_field']['field_name']['#options'][$field['field_name']]);
}
}
}
// The above changes to the form are mostly related to usability, where we
// simply hide options users are not allowed to use, but we need to check
// this properly. So we now add a validate callback so that we can prevent
// users from creating back reference fields manually.
$form['#validate'][] = '_noderelationships_content_field_overview_form_validate';
}
elseif ($form_id == 'content_field_edit_form' && isset($form['#field']) && isset($form['#field']['type'])) {
// Node reference field settings.
if ($form['#field']['type'] == 'nodereference') {
// Add a submit callback so that we can get rid of information about back
// references that are no longer enabled.
$form['#submit'][] = '_noderelationships_nodereference_settings_form_submit';
return;
}
elseif ($form['#field']['type'] == 'noderelationships_backref') {
unset($form['basic']);
$form['field']['required']['#access'] = FALSE;
$form['field']['multiple']['#access'] = FALSE;
$form['widget']['description']['#access'] = FALSE;
unset($form['widget']['default_value_fieldset']);
$field = $form['#field'];
$type = noderelationships_get_localized_content_type($form['type_name']['#value']);
$type_url_str = str_replace('_', '-', $form['type_name']['#value']);
$form['widget']['#title'] = t('Back reference field settings');
$form['widget']['#description'] = t('Back reference fields for the %type content type are created automatically from the settings specified in the <a href="@backref-settings">back reference settings panel</a> for the %type content type.', array(
'@backref-settings' => url('admin/content/node-type/' . $type_url_str . '/relationships/backref'),
'%type' => $type->name,
));
$form['widget']['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#default_value' => $field['widget']['label'],
'#required' => TRUE,
'#description' => t('A human-readable name to be used as the label for the back references view displayed for this field in the %type content type.', array(
'%type' => $type->name,
)),
);
$form['field']['#title'] = t('Referrer information');
$form['field']['#description'] = t('This section provides information about the node reference field that generates back references to the %type content type.', array(
'%type' => $type->name,
));
$form['field']['referrer_type'] = array(
'#type' => 'textfield',
'#title' => t('Referrer type'),
'#value' => $field['referrer_type'],
'#disabled' => TRUE,
);
$form['field']['referrer_field'] = array(
'#type' => 'textfield',
'#title' => t('Referrer field'),
'#value' => $field['referrer_field'],
'#disabled' => TRUE,
);
$form['#validate'][] = '_noderelationships_backreference_settings_form_validate';
}
}
}