function og_field_attach_form in Organic groups 7
Same name and namespace in other branches
- 7.2 og.module \og_field_attach_form()
Implements hook_field_attach_form().
Handle translated nodes that act as groups.
File
- ./
og.field.inc, line 433 - Field module functionality for the Organic groups module.
Code
function og_field_attach_form($entity_type, $entity, &$form, $form_state, $langcode) {
if (!empty($form['#node_edit_form']) && (og_is_group_type('node', $form['type']['#value']) || og_is_group_content_type('node', $form['type']['#value'])) && (!empty($entity->tnid) && $entity->tnid != $entity->nid) || !empty($_GET['translation']) && !empty($_GET['target'])) {
// Iterate over OG fields that shouldn't be changed in node translation.
foreach (og_fields_info() as $field_name => $info) {
if (!empty($form[$field_name]) && $info['disable on node translate']) {
// Prevent changing the group state on nodes that are translated.
$description = t('You can not change "@label" field from a translated content.', array(
'@label' => $info['instance']['label'],
));
$tnid = !empty($entity->tnid) ? $entity->tnid : $_GET['translation'];
if (($node = node_load($tnid)) && node_access('update', $node)) {
$description .= ' ' . t('Changing this field can only be done via <a href="@node">@title</a>.', array(
'@node' => url('node/' . $node->nid . '/edit'),
'@title' => $node->title,
));
}
$form[$field_name][LANGUAGE_NONE]['#options'] = array();
$form[$field_name][LANGUAGE_NONE]['#description'] = $description;
$form[$field_name][LANGUAGE_NONE]['#disabled'] = TRUE;
$form[$field_name][LANGUAGE_NONE]['#required'] = FALSE;
}
}
}
}