You are here

function content_multigroup_allowed_out in Content Construction Kit (CCK) 6.3

Helper function for deciding if a field is allowed out of a Multigroup.

2 calls to content_multigroup_allowed_out()
content_multigroup_field_basic_form in modules/content_multigroup/content_multigroup.admin.inc
Alter the basic field settings form.
content_multigroup_field_overview_form_validate in modules/content_multigroup/content_multigroup.admin.inc
Validation for creating/moving fields and groups on the Manage Fields screen.

File

modules/content_multigroup/content_multigroup.admin.inc, line 195
Implementation of node type administration functions for content multigroup.

Code

function content_multigroup_allowed_out($field, $group) {
  if ($group['group_type'] != 'multigroup') {
    return array(
      'allowed' => TRUE,
      'message' => '',
    );
  }

  // Optionwidgets do not behave the same in a Multigroup field as out of it.
  // In a Multigroup the same option can be selected multiple times,
  // but that is not possible in a normal group.
  // Adding a hook here where widgets that handle their own multiple values
  // can indicate their fields should not be removed from Multigroups.
  $max_existing = content_max_delta($field['field_name']);
  $no_remove_widgets = array(
    'optionwidgets_select',
    'optionwidgets_buttons',
    'optionwidgets_onoff',
    'nodereference_buttons',
    'nodereference_select',
    'userreference_buttons',
    'userreference_select',
  );
  $no_remove_widgets = array_merge($no_remove_widgets, module_invoke_all('content_multigroup_no_remove_widgets'));
  if (in_array($field['widget']['type'], $no_remove_widgets) && $max_existing > 0) {
    return array(
      'allowed' => FALSE,
      'message' => t('This change is not allowed. The field %field already has data created and uses a widget that stores data differently in a Standard group than in a Multigroup. Making this change could result in the loss of data.', array(
        '%field' => $field['widget']['label'],
      )),
    );
  }

  // Allow other modules to intervene.
  // Any failure will prevent this action.
  foreach (module_implements('content_multigroup_allowed_out') as $module) {
    $function = $module . '_content_multigroup_allowed_out';
    $result = $function($field, $group);
    if ($result['allowed'] === FALSE) {
      return array(
        'allowed' => FALSE,
        'message' => $result['message'],
      );
    }
  }
  $message = t('You are moving the field %field out of a Multigroup.', array(
    '%field' => $field['widget']['label'],
  ));
  return array(
    'allowed' => TRUE,
    'message' => $message,
  );
}