1 layout.flexible.inc | layout_flexible_template_edit_row_form($form, &$form_state, LayoutFlexibleTemplate $flexible_template, $original_row, $region_style = NULL) |
Form to add or edit a row on a flexible template.
Parameters
LayoutFlexibleTemplate $flexible_template: The loaded flexible template object.
string $original_row: The row above or below which a new row is being inserted.
string $region_style: The selected region style.
Related topics
File
- core/
modules/ layout/ layout.flexible.inc, line 436 - Provides configurable (flexible) layout templates.
Code
function layout_flexible_template_edit_row_form($form, &$form_state, LayoutFlexibleTemplate $flexible_template, $original_row, $region_style = NULL) {
form_load_include($form_state, 'inc', 'layout', 'layout.flexible');
form_load_include($form_state, 'inc', 'layout', 'layout.admin');
$form_state['flexible_template'] = &$flexible_template;
$flexible_template_name = $flexible_template->name;
$form_state['flexible_template_name'] = $flexible_template_name;
$form_state['original_row'] = $original_row;
$row_data = array();
if ($original_row != 'add') {
if (isset($flexible_template->rows[$original_row]['in_progress'])) {
$row_data = $flexible_template->rows[$original_row]['in_progress'];
}
else {
$row_data = $flexible_template->rows[$original_row];
}
}
$region_style = $region_style ? $region_style : $row_data['contains'];
$form_state['region_style'] = $region_style;
$row_styles = layout_flexible_row_styles();
$selected_style = $row_styles[$region_style]['name'];
$region_count = $row_styles[$region_style]['region_count'];
if ($original_row == 'add') {
backdrop_set_title(t('Add new row'));
}
else {
backdrop_set_title(t('Configure row !original_row', array('!original_row' => $original_row)));
}
$form['region_style'] = array(
'#type' => 'item',
'#title' => t('Selected region widths'),
'#markup' => $selected_style,
);
if ($original_row != 'add') {
$form['change_region_style'] = array(
'#type' => 'submit',
'#value' => t('Change region widths'),
'#attributes' => array('class' => array('layout-link-button')),
'#submit' => array(
'layout_flexible_template_change_region_style',
),
'#ajax' => array(
'callback' => 'layout_ajax_form_open_dialog',
),
);
}
$form['region_names'] = array(
'#type' => 'fieldset',
'#title' => t('Regions'),
'#collapsed' => $original_row != 'add',
'#collapsible' => TRUE,
'#tree' => TRUE,
);
$form_state['last_region_number'] = layout_flexible_template_get_last_region_number($flexible_template);
for ($i = 0; $i < $region_count; $i++) {
$form['region_names']['region_' . $i] = array(
'#type' => 'container',
);
if (isset($row_data['region_names']['region_' . $i]['label'])) {
$region_name = $row_data['region_names']['region_' . $i]['label'];
}
$form['region_names']['region_' . $i]['label'] = array(
'#type' => 'textfield',
'#title' => t('Region name') . ' ' . ($i + 1),
'#default_value' => !empty($region_name) ? $region_name : t('Region') . ' ' . ($form_state['last_region_number'] + $i + 1),
);
$form['region_names']['region_' . $i]['name'] = array(
'#type' => 'machine_name',
'#description' => t('A machine name to be used as the default CSS class. It must only contain uppercase letters, lowercase letters, numbers, hyphens and underscores.'),
'#default_value' => !empty($row_data['region_names']['region_' . $i]['name']) ? $row_data['region_names']['region_' . $i]['name'] : '',
'#maxlength' => 255,
'#field_prefix' => '<span dir="ltr">l-region--',
'#field_suffix' => '</span>‎',
'#size' => 15,
'#disabled' => FALSE,
'#machine_name' => array(
'exists' => '_layout_flexible_template_region_name_exists',
'source' => array('region_names', 'region_' . $i, 'label'),
'standalone' => TRUE,
'label' => t('Name'),
'replace_pattern' => '[^a-z0-9-]+',
'replace' => '-',
),
);
if (isset($row_data['region_names']['region_' . $i]['region_class_enable'])) {
$region_class_enable = $row_data['region_names']['region_' . $i]['region_class_enable'];
}
$form['region_names']['region_' . $i]['region_class_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Add CSS classes'),
'#default_value' => !empty($region_class_enable) ? $region_class_enable : 0,
);
if (isset($row_data['region_names']['region_' . $i]['classes'])) {
$classes = $row_data['region_names']['region_' . $i]['classes'];
}
$form['region_names']['region_' . $i]['classes'] = array(
'#type' => 'textfield',
'#title' => t('Additional region CSS classes'),
'#description' => t('Separate multiple classes with spaces.'),
'#default_value' => !empty($classes) ? $classes : '',
'#states' => array(
'visible' => array(
':input[name="region_names[region_' . $i . '][region_class_enable]"]' => array('checked' => TRUE),
),
),
);
}
$form['region_styles'] = array(
'#type' => 'fieldset',
'#title' => t('Row Style'),
'#collapsed' => $original_row != 'add',
'#collapsible' => TRUE,
);
$options = array(
'div' => 'DIV',
'nav' => 'NAV',
'aside' => 'ASIDE',
'section' => 'SECTION',
'header' => 'HEADER',
'footer' => 'FOOTER',
'main' => 'MAIN',
);
$form['region_styles']['element'] = array(
'#title' => t('Row wrapper tag'),
'#type' => 'select',
'#options' => $options,
'#default_value' => isset($row_data['element']) ? $row_data['element'] : '',
);
$form['region_styles']['container'] = array(
'#title' => t('Row width behavior'),
'#type' => 'radios',
'#options' => array(
'container' => t('Fixed maximum width'),
'container_fluid' => t('Fluid width'),
'no_container' => t('Full width'),
),
'#default_value' => isset($row_data['container']) ? $row_data['container'] : 'container_fluid',
);
$form['region_styles']['container']['container']['#description'] = t('Adds the <code>container</code> class to the row.');
$form['region_styles']['container']['container_fluid']['#description'] = t('Adds the <code>container-fluid</code> class to the row (no <code>max-width</code>, but <code>padding</code>).');
$form['region_styles']['container']['no_container']['#description'] = t('No container-related classes added to the row (e.g. for Hero blocks).');
$form['region_styles']['row_classes'] = array(
'#title' => t('Additional row CSS classes'),
'#type' => 'textfield',
'#default_value' => isset($row_data['classes']) ? $row_data['classes'] : '',
'#description' => t('Separate multiple classes with spaces.'),
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#name' => 'submit',
'#value' => t('Save configuration'),
'#attributes' => array('class' => array('layout-title-button')),
'#validate' => array(
'layout_flexible_template_edit_row_validate',
),
'#submit' => array(
'layout_flexible_template_edit_row_form_submit',
),
'#ajax' => array(
'callback' => 'layout_flexible_template_edit_row_ajax',
),
);
$form['actions']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#validate' => array(),
'#submit' => array(
'layout_flexible_template_cancel',
),
'#ajax' => array(
'callback' => 'layout_flexible_template_cancel_ajax',
),
);
return $form;
}