You are here

function fieldgroup_nodeapi in Content Construction Kit (CCK) 5

Same name and namespace in other branches
  1. 6.3 modules/fieldgroup/fieldgroup.module \fieldgroup_nodeapi()
  2. 6 modules/fieldgroup/fieldgroup.module \fieldgroup_nodeapi()
  3. 6.2 modules/fieldgroup/fieldgroup.module \fieldgroup_nodeapi()

File

./fieldgroup.module, line 362
Create field groups for CCK fields.

Code

function fieldgroup_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'view':
    case 'print':
      $context = $teaser ? 'teaser' : 'full';
      foreach (fieldgroup_groups($node->type) as $group_name => $group) {
        $label = $group['settings']['display']['label'] == 'above';
        $element = array(
          '#title' => $label ? check_plain(t($group['label'])) : '',
          '#description' => $label ? content_filter_xss(t($group['settings']['display']['description'])) : '',
          '#weight' => $group['weight'],
          '#attributes' => array(
            'class' => 'fieldgroup ' . strtr($group['group_name'], '_', '-'),
          ),
        );
        switch ($group['settings']['display'][$context]) {
          case 'simple':
            $element['#type'] = 'fieldgroup_simple';
            break;
          case 'hidden':
            $element['#access'] = FALSE;
            break;
          case 'fieldset_collapsed':
            $element['#collapsed'] = TRUE;
          case 'fieldset_collapsible':
            $element['#collapsible'] = TRUE;
          case 'fieldset':
            $element['#type'] = 'fieldset';
            break;
        }
        $node->content[$group_name] = $element;
        $visible = FALSE;
        foreach ($group['fields'] as $field_name => $field) {
          if (isset($node->content[$field_name])) {
            $node->content[$group_name][$field_name] = $node->content[$field_name];
            if ($node->content[$field_name]['#access'] && !empty($node->content[$field_name]['#value'])) {
              $visible = TRUE;
            }
            unset($node->content[$field_name]);
          }
        }
        if (!$visible) {

          // Hide the group, because the fields are empty or not accessible.
          unset($node->content[$group_name]);
        }
      }
      break;
  }
}