1 field_group.groups.inc _field_group_field_group_format_settings_alter(&$form, &$group)

Field group format settings

See also

field_group_field_group_format_settings_alter()

File

core/modules/field_group/field_group.groups.inc, line 372
Defines some field group types.

Code

function _field_group_field_group_format_settings_alter(&$form, &$group) {
  $field_group_types = field_group_formatter_info();
  $mode = $group->mode == 'form' ? 'form' : 'display';
  $formatter = $field_group_types[$mode][$group->format_type];

  if ($mode == 'display') {
    $select_name = 'fields[' . $group->group_name . '][format_settings][settings][instance_settings]';
  }
  else {
    $select_name = 'instance_settings';
  }

  // Add optional instance_settings.
  switch ($group->format_type) {
    case 'html-element':
      $form['instance_settings']['wrapper'] = array(
        '#title' => t('Wrapper tag'),
        '#type' => 'select',
        '#options' => array(
          'section' => t('Section'), 'article' => t('Article'),
          'header' => t('Header'), 'footer' => t('Footer'),
          'aside' => t('Aside'), 'div' => t('Div'), 'other' => t('Other'),
        ),
        '#default_value' => isset($group->format_settings['instance_settings']['wrapper']) ? $group->format_settings['instance_settings']['wrapper'] : 'section',
        '#description' => t('The HTML element to use as a wrapper for the fields.'),
      );

      $form['instance_settings']['wrapper_other'] = array(
        '#title' => t('Other wrapper'),
        '#type' => 'textfield',
        '#default_value' => isset($group->format_settings['instance_settings']['wrapper_other']) ? $group->format_settings['instance_settings']['wrapper_other'] : $formatter['instance_settings']['wrapper_other'],
        '#description' => t('For example: <code>p</code>, <code>span</code>.'),
        '#weight' => 1,
        '#indentation' => 1,
        '#states' => array(
          'visible' => array(
            'select[name="' . $select_name . '[wrapper]"]' => array('value' => 'other'),
          ),
        ),
        '#element_validate' => array('field_group_format_settings_other_tag_validate'),
      );

      $form['instance_settings']['show_label'] = array(
        '#title' => t('Show label'),
        '#type' => 'select',
        '#options' => array(0 => t('No'), 1 => t('Yes')),
        '#default_value' => isset($group->format_settings['instance_settings']['show_label']) ? $group->format_settings['instance_settings']['show_label'] : $formatter['instance_settings']['show_label'],
        '#weight' => 2,
      );

      $form['instance_settings']['label_element'] = array(
        '#title' => t('Label tag'),
        '#type' => 'select',
        '#options' => array(
          'h2' => t('Header 2'),
          'h3' => t('Header 3'),
          'div' => t('Div'),
          'p' => t('P'),
          'span' => t('Span'),
          'other' => t('Other'),
        ),
        '#default_value' => isset($group->format_settings['instance_settings']['label_element']) ? $group->format_settings['instance_settings']['label_element'] : $formatter['instance_settings']['label_element'],
        '#description' => t('An HTML element to use for the label.'),
        '#weight' => 3,
        '#indentation' => 1,
        '#states' => array(
          'visible' => array(
            'select[name="' . $select_name . '[show_label]"]' => array('value' => 1),
          ),
        ),
      );

      $form['instance_settings']['label_element_other'] = array(
        '#title' => t('Other label tag'),
        '#type' => 'textfield',
        '#default_value' => isset($group->format_settings['instance_settings']['label_element_other']) ? $group->format_settings['instance_settings']['label_element_other'] : '',
        '#description' => t('An alternative HTML element to use for the label, without the angle brackets. For example, <code>h4</code>, <code>strong</code>.'),
        '#weight' => 4,
        '#indentation' => 1,
        '#states' => array(
          'visible' => array(
            'select[name="' . $select_name . '[show_label]"]' => array('value' => 1),
            'select[name="' . $select_name . '[label_element]"]' => array('value' => 'other'),
          ),
        ),
        '#element_validate' => array('field_group_format_settings_other_tag_validate'),
      );

      $form['instance_settings']['attributes'] = array(
        '#title' => t('Attributes'),
        '#type' => 'textfield',
        '#default_value' => isset($group->format_settings['instance_settings']['attributes']) ? $group->format_settings['instance_settings']['attributes'] : $formatter['instance_settings']['attributes'],
        '#description' => t('For example, <code>name="MY-ANCHOR"</code> to create an anchor that can be used in a link from elsewhere.'),
        '#weight' => 5,
      );
      break;
    case 'fieldset':
      $form['label']['#description'] = t('Please enter a label for collapsible elements');
      break;
    case 'details':
      $form['label']['#description'] = t('Please enter a label for the summary');
      $form['instance_settings']['label_element'] = array(
        '#title' => t('Label element'),
        '#type' => 'select',
        '#options' => array(
          'span' => t('Span'), 'strong' => t('Strong'), 'em' => t('Emphasis'),
          'h2' => t('Header 2'), 'h3' => t('Header 3')),
        '#default_value' => isset($group->format_settings['instance_settings']['label_element']) ? $group->format_settings['instance_settings']['label_element'] : $formatter['instance_settings']['label_element'],
        '#weight' => 2,
      );
      $form['instance_settings']['name'] = array(
        '#title' => t('Name attribute'),
        '#type' => 'textfield',
        '#default_value' => isset($group->format_settings['instance_settings']['name']) ? $group->format_settings['instance_settings']['name'] : $formatter['instance_settings']['name'],
        '#description' => t('The name attribute specifies a group name, as per the <a href="@url">HTML specification</a>. Give multiple <code>details</code> elements the same name value to group them. Only one of the grouped <code>details</code> elements can be open at a time — opening one will cause another to close — so do not use if that behaviour is not desired. If multiple grouped <code>details</code> elements are given the open attribute, only the first one in the source order will be rendered open.', array('@url' => 'https://html.spec.whatwg.org/multipage/interactive-elements.html#the-details-element')),
        '#weight' => 5,
      );
      break;
    case 'tabs':
      break;
    case 'tab':
    default:
  }
}