public function GridFormController::form in Grid builder 8
Overrides Drupal\Core\Entity\EntityFormController::form().
File
- lib/
Drupal/ gridbuilder/ GridFormController.php, line 37 - Definition of Drupal\gridbuilder\GridFormController.
Class
- GridFormController
- Form controller for the grid edit/add forms.
Namespace
Drupal\gridbuilderCode
public function form(array $form, array &$form_state, EntityInterface $grid) {
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#maxlength' => 255,
'#default_value' => $grid
->label(),
'#required' => TRUE,
);
$form['id'] = array(
'#type' => 'machine_name',
'#default_value' => $grid
->id(),
'#machine_name' => array(
'exists' => 'gridbuilder_load',
'source' => array(
'label',
),
),
'#disabled' => !$grid
->isNew(),
);
// Master grid configuration.
$form['type'] = array(
'#type' => 'radios',
'#title' => t('Type of grid'),
'#options' => array(
GRIDBUILDER_FLUID => t('Fluid'),
GRIDBUILDER_FIXED => t('Fixed to specific width'),
),
'#default_value' => $grid->type,
);
$form['width'] = array(
'#type' => 'textfield',
'#title' => t('Grid width'),
'#description' => t('Only meaningful if using a fixed grid. Enter a pixel size (eg. 960).'),
'#default_value' => $grid->width,
'#states' => array(
'visible' => array(
'input[name="type"]' => array(
'value' => GRIDBUILDER_FIXED,
),
),
),
'#field_suffix' => $grid->type == GRIDBUILDER_FIXED ? 'px' : '%',
);
// Grid detail configuration.
$form['columns'] = array(
'#type' => 'textfield',
'#title' => t('Number of grid columns'),
'#default_value' => $grid->columns,
);
$form['padding_width'] = array(
'#type' => 'textfield',
'#title' => t('Column padding'),
'#description' => t('Column padding in pixels (for fixed grids, eg. 10) or percentages (for fluid grids, eg. 1.5). Enter 0 for no padding.'),
'#default_value' => $grid->padding_width,
'#field_suffix' => $grid->type == GRIDBUILDER_FIXED ? 'px' : '%',
);
$form['gutter_width'] = array(
'#type' => 'textfield',
'#title' => t('Gutter width'),
'#description' => t('Gutter width in pixels (for fixed grids, eg. 20) or percentages (for fluid grids, eg. 2). Enter 0 for no gutter.'),
'#default_value' => $grid->gutter_width,
'#field_suffix' => $grid->type == GRIDBUILDER_FIXED ? 'px' : '%',
);
$grid_breakpoints = entity_load('breakpoint_group', 'module.gridbuilder.gridbuilder');
$breakpoint_options = array();
foreach ($grid_breakpoints->breakpoints as $key => $breakpoint) {
$breakpoint_options[$key] = $breakpoint
->label();
}
$form['breakpoints'] = array(
'#title' => t('Breakpoints where this grid will apply'),
'#type' => 'checkboxes',
'#options' => $breakpoint_options,
'#default_value' => (array) $grid->breakpoints,
);
$form['#attached']['css'][] = drupal_get_path('module', 'gridbuilder') . '/gridbuilder-admin.css';
$form['#attached']['js'][] = drupal_get_path('module', 'gridbuilder') . '/gridbuilder-admin.js';
return parent::form($form, $form_state, $grid);
}