function fb_instant_articles_display_add_regions in Facebook Instant Articles 7.2
Same name and namespace in other branches
- 7 modules/fb_instant_articles_display/includes/view_mode_layout.inc \fb_instant_articles_display_add_regions()
Includes regions Facebook Instant Articles Display View Mode.
1 string reference to 'fb_instant_articles_display_add_regions'
- fb_instant_articles_display_layout_form in modules/
fb_instant_articles_display/ includes/ view_mode_layout.inc - Includes Facebook Instant Articles Display View Mode elements.
File
- modules/
fb_instant_articles_display/ includes/ view_mode_layout.inc, line 40 - View mode layout functions for Facebook Instant Articles Display.
Code
function fb_instant_articles_display_add_regions(&$form, &$form_state) {
// Get the entity_type, bundle and view mode.
$entity_type = $form['#entity_type'];
$bundle = $form['#bundle'];
$view_mode = $form['#view_mode'];
// Check layout.
$layout = isset($form['#fbia_layout']) ? $form['#fbia_layout'] : FALSE;
$table =& $form['fields'];
$table['#header'] = array(
t('Field'),
t('Weight'),
t('Parent'),
t('Region'),
t('Label'),
array(
'data' => t('Format'),
'colspan' => 3,
),
);
$regions = array(
'header' => t('Header'),
'body' => t('Body'),
'footer' => t('Footer'),
);
$table['#regions'] = array();
foreach ($regions as $region_key => $region_title) {
$region_options[$region_key] = $region_title;
$table['#regions'][$region_key] = array(
'title' => $region_title,
'message' => t('No fields are displayed in this region'),
);
}
// Let other modules alter the regions.
$context = array(
'entity_type' => $entity_type,
'bundle' => $bundle,
'view_mode' => $view_mode,
);
$region_info = array(
'region_options' => &$region_options,
'table_regions' => &$table['#regions'],
);
drupal_alter('fb_instant_articles_display_layout_region', $context, $region_info);
$region_options['hidden'] = $view_mode != 'form' ? t('Disabled') : t('Hidden');
$table['#regions']['hidden'] = array(
'title' => $view_mode != 'form' ? t('Disabled') : t('Hidden'),
'message' => t('No fields are hidden.'),
);
$region = array(
'#type' => 'select',
'#options' => $region_options,
'#default_value' => 'hidden',
'#attributes' => array(
'class' => array(
'ds-field-region',
),
),
);
// Update existing rows by changing rowHandler and adding regions.
foreach (element_children($table) as $name) {
$row =& $table[$name];
$row['#js_settings'] = array(
'rowHandler' => 'facebookInstantArticlesDisplay',
);
$row['#region_callback'] = 'fb_instant_articles_display_field_ui_row_region';
// Remove hidden format.
if (isset($row['format']['type']['#options']['hidden'])) {
unset($row['format']['type']['#options']['hidden']);
}
// Add label class.
if (isset($row['label'])) {
if (isset($form_state['formatter_settings']) && isset($form_state['formatter_settings'][$name]['ft'])) {
if (!empty($form_state['formatter_settings'][$name]['ft']['lb'])) {
$row['human_name']['#markup'] = check_plain($form_state['formatter_settings'][$name]['ft']['lb']) . ' ' . t('(Original: !orig)', array(
'!orig' => $row['human_name']['#markup'],
));
}
}
}
// Add region.
$split = $view_mode != 'form' ? 7 : 6;
if ($row['#row_type'] == 'group' && $view_mode == 'form') {
$split = $view_mode != 'form' ? 8 : 7;
}
$second = array_splice($row, $split);
$row['region'] = $region;
$row['region']['#default_value'] = isset($layout->settings['fields'][$name]) && isset($region_options[$layout->settings['fields'][$name]]) ? $layout->settings['fields'][$name] : 'hidden';
$row = array_merge($row, $second);
}
return $form;
}