/** * Implements hook_field_group_format_settings(). * * Defines configuration widget for the settings on a field group * formatter. Eache formatter can have different elements and storage. * * @params Object $group The group object. * @return Array $form The form element for the format settings. */ function hook_field_group_format_settings($group) { // Add a wrapper for extra settings to use by others. $form = array('instance_settings' => array('#tree' => TRUE, '#weight' => 2)); $field_group_types = field_group_formatter_info(); $mode = $group->mode == 'form' ? 'form' : 'display'; $formatter = $field_group_types[$mode][$group->format_type]; // Add the required formatter type selector. if (isset($formatter['format_types'])) { $form['formatter'] = array('#title' => t('Fieldgroup settings'), '#type' => 'select', '#options' => drupal_map_assoc($formatter['format_types']), '#default_value' => isset($group->format_settings['formatter']) ? $group->format_settings['formatter'] : $formatter['default_formatter'], '#weight' => 1); } if ($mode == 'form') { $form['instance_settings']['required_fields'] = array('#type' => 'checkbox', '#title' => t('Mark group for required fields.'), '#default_value' => isset($group->format_settings['instance_settings']['required_fields']) ? $group->format_settings['instance_settings']['required_fields'] : (isset($formatter['instance_settings']['required_fields']) ? $formatter['instance_settings']['required_fields'] : ''), '#weight' => 2); } $form['instance_settings']['classes'] = array('#title' => t('Extra CSS classes'), '#type' => 'textfield', '#default_value' => isset($group->format_settings['instance_settings']['classes']) ? $group->format_settings['instance_settings']['classes'] : (isset($formatter['instance_settings']['classes']) ? $formatter['instance_settings']['classes'] : ''), '#weight' => 3, '#element_validate' => array('field_group_validate_css_class')); $form['instance_settings']['description'] = array('#title' => t('Description'), '#type' => 'textarea', '#default_value' => isset($group->format_settings['instance_settings']['description']) ? $group->format_settings['instance_settings']['description'] : (isset($formatter['instance_settings']['description']) ? $formatter['instance_settings']['description'] : ''), '#weight' => 0); // Add optional instance_settings. switch ($group->format_type) { case 'div': $form['instance_settings']['effect'] = array('#title' => t('Effect'), '#type' => 'select', '#options' => array('none' => t('None'), 'blind' => t('Blind')), '#default_value' => isset($group->format_settings['instance_settings']['effect']) ? $group->format_settings['instance_settings']['effect'] : $formatter['instance_settings']['effect'], '#weight' => 2); $form['instance_settings']['speed'] = array('#title' => t('Speed'), '#type' => 'select', '#options' => array('none' => t('None'), 'slow' => t('Slow'), 'fast' => t('Fast')), '#default_value' => isset($group->format_settings['instance_settings']['speed']) ? $group->format_settings['instance_settings']['speed'] : $formatter['instance_settings']['speed'], '#weight' => 3); break; case 'fieldset': $form['instance_settings']['classes'] = array('#title' => t('Extra CSS classes'), '#type' => 'textfield', '#default_value' => isset($group->format_settings['instance_settings']['classes']) ? $group->format_settings['instance_settings']['classes'] : $formatter['instance_settings']['classes'], '#weight' => 3, '#element_validate' => array('field_group_validate_css_class')); break; case 'tabs': case 'htabs': case 'accordion': unset($form['instance_settings']['description']); if (isset($form['instance_settings']['required_fields'])) { unset($form['instance_settings']['required_fields']); } break; case 'tab': case 'htab': case 'accordion-item': default: } return $form; }
/** * Get the type format of a Group by the name. * * @param string $name * Name of the group. * * @return string * Machine name of the group. */ private function getGroupTypeFormatByName($name) { $formats = field_group_formatter_info(); foreach ($formats['form'] as $key => $value) { if (strtolower($value['label']) == strtolower($name)) { $group_type_id = $key; } } if (!isset($group_type_id)) { throw new \InvalidArgumentException("The Group Type Format '{$name}' doesn't exist."); } return $group_type_id; }