function structured_data_social_form in Structured Data (JSON+LD Rich Snippets) 7
Fieldset builder for the Social links settings form.
1 call to structured_data_social_form()
- structured_data_settings_form in ./
structured_data.admin.inc - Form callback for admin settings page.
File
- ./
structured_data.admin.inc, line 216 - Administrative pages for the structured_data module.
Code
function structured_data_social_form(&$form_state) {
$fieldset = array(
'#type' => 'fieldset',
'#title' => t('Social links'),
// Set up the wrapper so that AJAX will be able to replace the fieldset.
'#prefix' => '<div id="links-fieldset-wrapper">',
'#suffix' => '</div>',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);
$social_links = variable_get('structured_data_social_links', array());
if (isset($social_links[0])) {
if ($social_links[0] != '') {
$fieldset['#collapsed'] = FALSE;
}
}
// Build the fieldset with the proper number of links. We'll use
// $form_state['num_links'] to determine the number of textfields to build.
if (empty($form_state['num_links'])) {
if (empty($social_links)) {
$form_state['num_links'] = 1;
}
else {
$form_state['num_links'] = count($social_links) + 1;
}
}
for ($i = 0; $i < $form_state['num_links']; $i++) {
$fieldset['links'][$i] = array(
'#type' => 'textfield',
'#title' => t('Social Network link'),
);
if (isset($social_links[$i])) {
$fieldset['links'][$i]['#default_value'] = $social_links[$i];
}
}
$fieldset['add_link'] = array(
'#type' => 'submit',
'#value' => t('Add one more'),
'#submit' => array(
'structured_data_ajax_add_more_add_one',
),
// See the examples in ajax_example.module for more details on the
// properties of #ajax.
'#ajax' => array(
'callback' => 'structured_data_ajax_add_more_callback',
'wrapper' => 'links-fieldset-wrapper',
),
);
if ($form_state['num_links'] > 1) {
$fieldset['remove_link'] = array(
'#type' => 'submit',
'#value' => t('Remove last'),
'#submit' => array(
'structured_data_ajax_add_more_remove_one',
),
'#ajax' => array(
'callback' => 'structured_data_ajax_add_more_callback',
'wrapper' => 'links-fieldset-wrapper',
),
);
}
return $fieldset;
}