function _ds_field_ui_table_layouts in Display Suite 7.2
Same name and namespace in other branches
- 8.4 includes/field_ui.inc \_ds_field_ui_table_layouts()
- 8.2 includes/field_ui.inc \_ds_field_ui_table_layouts()
- 8.3 includes/field_ui.inc \_ds_field_ui_table_layouts()
- 7 ds.field_ui.inc \_ds_field_ui_table_layouts()
Add the layouts fieldset on the Field UI screen.
Parameters
$entity_type: The name of the entity type.
$bundle: The name of the bundle
$view_mode: The name of the view_mode
$form: A collection of form properties.
1 call to _ds_field_ui_table_layouts()
- ds_field_ui_fields_layouts in includes/
ds.field_ui.inc - Adds the Display Suite fields and layouts to the form.
File
- includes/
ds.field_ui.inc, line 1544 - Field UI functions for Display Suite.
Code
function _ds_field_ui_table_layouts($entity_type, $bundle, $view_mode, &$form, $form_state) {
$layout_options = array();
$ds_layouts = ds_get_layout_info();
$layout_options = array(
'' => t('- None -'),
);
foreach ($ds_layouts as $key => $layout) {
$optgroup = 'Display Suite';
// Panels can not be used on Views fields and forms.
if (!empty($layout['module']) && $layout['module'] == 'panels' && isset($form_state['no_panels'])) {
continue;
}
// Create new layout option group.
if (!empty($layout['module'])) {
$optgroup = drupal_ucfirst($layout['module']);
}
if (!isset($layout_options[$optgroup])) {
$layout_options[$optgroup] = array();
}
// Stack the layout.
$layout_options[$optgroup][$key] = $layout['label'];
}
// If there is only one $optgroup, move it to the root.
if (count($layout_options) == 2) {
$options = $layout_options[$optgroup];
$layout_options = array_merge(array(
'' => t('- None -'),
), $options);
}
// Add layouts form.
$form['additional_settings']['ds_layouts'] = array(
'#type' => 'fieldset',
'#title' => t('Layout for !bundle in !view_mode', array(
'!bundle' => str_replace('_', ' ', $bundle),
'!view_mode' => str_replace('_', ' ', $view_mode),
)),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#parents' => array(
'additional_settings',
),
'#weight' => -100,
);
ctools_include('export');
$layout = new stdClass();
$ds_layout_settings = ctools_export_crud_load_all('ds_layout_settings');
if (isset($ds_layout_settings[$form['#export_id']])) {
$layout = $ds_layout_settings[$form['#export_id']];
}
if (!empty($layout) && isset($layout->layout) && isset($ds_layouts[$layout->layout]) && empty($layout->disabled)) {
$layout->settings = $layout->settings;
$layout->regions = $ds_layouts[$layout->layout]['regions'];
$form['#ds_layout'] = $layout;
}
// The layout is defined in code.
if (isset($layout->export_type)) {
// Enabled/disable the layout.
if (empty($layout->disabled)) {
$link = t('This layout is defined in code') . ': ' . l(t('disable layout.'), 'admin/structure/ds/disable/' . $form['#export_id'], array(
'query' => drupal_get_destination(),
));
}
else {
$link = t('A layout is defined in code but has been disabled') . ': ' . l(t('enable layout.'), 'admin/structure/ds/enable/' . $form['#export_id'], array(
'query' => drupal_get_destination(),
));
}
$form['additional_settings']['ds_layouts']['enable_disable'] = array(
'#markup' => $link,
'#weight' => 2,
);
// Overridden in database.
if ($layout->export_type == 3) {
$form['additional_settings']['ds_layouts']['revert'] = array(
'#markup' => l(t('This layout is overridden. Click to revert to default settings.'), 'admin/structure/ds/revert-layout/' . $form['#export_id'], array(
'query' => drupal_get_destination(),
)),
'#weight' => 1,
);
}
}
// Load the layout preview form
$layout->layout_options = $layout_options;
_ds_field_ui_table_layouts_preview($form, $form_state, $ds_layouts, $layout, $entity_type, $bundle, $view_mode);
if (!empty($layout) && isset($layout->regions)) {
// Add wrappers
$wrapper_options = array(
'div' => 'Div',
'span' => 'Span',
'section' => 'Section',
'article' => 'Article',
'header' => 'Header',
'footer' => 'Footer',
'aside' => 'Aside',
'figure' => 'Figure',
);
$form['additional_settings']['region_wrapper'] = array(
'#type' => 'fieldset',
'#title' => t('Custom wrappers'),
'#description' => t('Choose a wrapper. All Display Suite layouts support this option.'),
);
// Hide the fieldset in case of the reset layout.
if ($layout->layout === 'ds_reset') {
$form['additional_settings']['region_wrapper']['#access'] = FALSE;
}
foreach (array_keys($layout->regions) as $region) {
$form['additional_settings']['region_wrapper'][$region] = array(
'#type' => 'select',
'#options' => $wrapper_options,
'#title' => t('Wrapper for @region', array(
'@region' => $layout->regions[$region],
)),
'#default_value' => isset($layout->settings['wrappers'], $layout->settings['wrappers'][$region]) ? $layout->settings['wrappers'][$region] : 'div',
);
}
$form['additional_settings']['region_wrapper']['layout_wrapper'] = array(
'#type' => 'select',
'#options' => $wrapper_options,
'#title' => t('Layout wrapper'),
'#default_value' => isset($layout->settings['layout_wrapper']) ? $layout->settings['layout_wrapper'] : 'div',
'#weight' => 10,
);
$form['additional_settings']['region_wrapper']['layout_attributes'] = array(
'#type' => 'textfield',
'#title' => t('Layout attributes'),
'#description' => 'E.g. role="navigation"',
'#default_value' => isset($layout->settings['layout_attributes']) ? $layout->settings['layout_attributes'] : '',
'#weight' => 11,
);
$form['additional_settings']['region_wrapper']['layout_attributes_merge'] = array(
'#type' => 'checkbox',
'#title' => t('Merge other layout attributes'),
'#description' => 'Certain modules might provide additional attributes for the template wrapper, e.g. RDFa. Disable this option if you prefer to specify these attributes above.',
'#default_value' => isset($layout->settings['layout_attributes_merge']) ? $layout->settings['layout_attributes_merge'] : variable_get('ds_layout_attributes_merge', TRUE),
'#weight' => 12,
);
$form['additional_settings']['region_wrapper']['layout_link_attribute'] = array(
'#type' => 'select',
'#options' => array(
'' => t('No link'),
'content' => t('Link to content'),
'custom' => t('Custom'),
'tokens' => t('Tokens'),
),
'#title' => t('Add link'),
'#description' => t('This will add an onclick attribute on the layout wrapper.'),
'#default_value' => isset($layout->settings['layout_link_attribute']) ? $layout->settings['layout_link_attribute'] : FALSE,
'#weight' => 12,
);
$form['additional_settings']['region_wrapper']['layout_link_custom'] = array(
'#type' => 'textfield',
'#title' => t('Custom link'),
'#description' => t('You may use tokens for this link if you selected tokens.'),
'#default_value' => isset($layout->settings['layout_link_custom']) ? $layout->settings['layout_link_custom'] : FALSE,
'#weight' => 13,
'#states' => array(
'visible' => array(
array(
':input[name="additional_settings[region_wrapper][layout_link_attribute]"]' => array(
array(
"value" => "tokens",
),
array(
"value" => "custom",
),
),
),
),
),
);
if (module_exists('token')) {
$form['additional_settings']['region_wrapper']['tokens'] = array(
'#title' => t('Tokens'),
'#type' => 'container',
'#weight' => 14,
'#states' => array(
'visible' => array(
':input[name="additional_settings[region_wrapper][layout_link_attribute]"]' => array(
"value" => "tokens",
),
),
),
);
$form['additional_settings']['region_wrapper']['tokens']['help'] = array(
'#theme' => 'token_tree',
'#token_types' => 'all',
'#global_types' => FALSE,
'#dialog' => TRUE,
);
}
// Add extra classes for the regions to have more control while theming.
$form['additional_settings']['ds_classes'] = array(
'#type' => 'fieldset',
'#title' => t('Custom classes'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#parents' => array(
'additional_settings',
),
'#access' => empty($chosen_layout['flexible']),
);
$classes_access = user_access('admin_classes') && module_exists('ds_ui');
$classes = _ds_classes();
if (!empty($classes)) {
$form['additional_settings']['ds_classes']['layout_class'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#options' => $classes,
'#title' => t('Class for layout'),
'#default_value' => isset($layout->settings['classes']['layout_class']) ? $layout->settings['classes']['layout_class'] : '',
);
foreach (array_keys($layout->regions) as $region) {
$form['additional_settings']['ds_classes'][$region] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#options' => $classes,
'#title' => t('Class for @region', array(
'@region' => $region,
)),
'#default_value' => isset($layout->settings['classes'][$region]) ? $layout->settings['classes'][$region] : '',
);
}
if ($classes_access) {
$form['additional_settings']['ds_classes']['info'] = array(
'#markup' => l(t('Manage region and field CSS classes'), 'admin/structure/ds/classes', array(
'query' => drupal_get_destination(),
)),
);
}
elseif (user_access('admin_classes')) {
$form['additional_settings']['ds_classes']['info'] = array(
'#markup' => l(t('To manage region and field CSS classes, the Display Suite UI module should be enabled.'), 'admin/modules', array(
'query' => drupal_get_destination(),
'fragment' => 'edit-modules-display-suite',
)),
);
}
}
else {
if ($classes_access) {
$form['additional_settings']['ds_classes']['info'] = array(
'#markup' => '<p>' . t('You have not defined any CSS classes which can be used on regions.') . '</p><p>' . l(t('Manage region and field CSS classes'), 'admin/structure/ds/classes', array(
'query' => drupal_get_destination(),
)) . '</p>',
);
}
else {
$form['additional_settings']['ds_classes']['#access'] = FALSE;
}
}
}
else {
if ($view_mode != 'form') {
// See if we can clone from another view mode.
$options = array();
$ds_layout_settings = ctools_export_crud_load_all('ds_layout_settings');
foreach ($ds_layout_settings as $row) {
// Do not clone from form layouts.
if ($row->view_mode == 'form') {
continue;
}
if ($row->entity_type == $entity_type && $row->bundle == $bundle) {
$name = drupal_ucfirst(str_replace('_', ' ', $row->entity_type)) . ' > ' . drupal_ucfirst(str_replace('_', ' ', $row->bundle)) . ' > ' . drupal_ucfirst(str_replace('_', ' ', $row->view_mode));
if (!empty($row->disabled)) {
$name .= ' ' . t('(disabled)');
}
$options[$row->id] = $name;
}
}
if (!empty($options)) {
// Clone from another layout.
$form['additional_settings']['ds_clone'] = array(
'#type' => 'fieldset',
'#title' => t('Clone layout'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#parents' => array(
'additional_settings',
),
);
$form['additional_settings']['ds_clone']['clone'] = array(
'#title' => t('Select an existing layout to clone.'),
'#type' => 'select',
'#options' => $options,
'#weight' => 20,
);
$form['additional_settings']['ds_clone']['clone_submit'] = array(
'#type' => 'submit',
'#value' => t('Clone layout'),
'#submit' => array(
'ds_field_ui_layout_clone',
),
'#weight' => 21,
);
}
}
}
$form['additional_settings']['ds_layouts']['id'] = array(
'#type' => 'value',
'#value' => isset($layout->id) ? $layout->id : $form['#export_id'],
);
$form['additional_settings']['ds_layouts']['old_layout'] = array(
'#type' => 'value',
'#value' => isset($layout->layout) ? $layout->layout : 0,
);
// Add validate and submit handlers. Layout needs be first so
// we can reset the type key for Field API fields.
$form['#validate'][] = 'ds_field_ui_layouts_validate';
$submit = $form['#submit'];
$form['#submit'] = array(
'ds_field_ui_layouts_save',
);
$form['#submit'] = array_merge($form['#submit'], $submit);
}