public function RLayoutFormController::form in Layout 8
Overrides Drupal\Core\Entity\EntityFormController::form().
File
- lib/
Drupal/ rlayout/ RLayoutFormController.php, line 46 - Definition of Drupal\rlayout\RLayoutFormController.
Class
- RLayoutFormController
- Form controller for the layout edit/add forms.
Namespace
Drupal\rlayoutCode
public function form(array $form, array &$form_state, EntityInterface $layout) {
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#maxlength' => 255,
'#default_value' => $layout
->label(),
'#description' => t("Example: 'Front page', 'Section page'."),
'#required' => TRUE,
);
$form['id'] = array(
'#type' => 'machine_name',
'#default_value' => $layout
->id(),
'#machine_name' => array(
'exists' => 'rlayout_load',
'source' => array(
'label',
),
),
'#disabled' => !$layout
->isNew(),
);
$layoutdata = array();
$default_regions = region_load_all();
foreach ($layout->regions as $id) {
$layoutdata['regions'][] = array(
'id' => $id,
'label' => $default_regions[$id]
->label(),
);
}
$layoutdata['overrides'] = (array) $layout->overrides;
$form['layout_regions'] = array(
'#type' => 'textarea',
'#title' => t('Region and bunnypoint configuration'),
'#default_value' => drupal_json_encode($layoutdata),
'#suffix' => '<div id="responsive-layout-designer"></div>',
);
$form['#attached'] = array(
'library' => array(
array(
'system',
'jquery.ui.dialog',
),
array(
'system',
'jquery.ui.sortable',
),
array(
'rlayout',
'rlayout-designer',
),
array(
'rlayout',
'rlayout-admin',
),
),
'js' => array(
array(
'data' => array(
'responsiveLayout' => array(
'layout' => $layout,
'defaultRegions' => region_load_all(),
'defaultBreakpoints' => rlayout_breakpoints_load_all(),
'defaultGrids' => entity_load_multiple('grid'),
),
),
'type' => 'setting',
),
),
'css' => array(
array(
// Embed the grid css inline for now. Yeah, I know this is evil.
// It is just a prototype for now, ok? I know it is evil. Yes.
'data' => rlayout_breakpoint_get_css(FALSE),
'type' => 'inline',
),
),
);
// JSON2 is required for stringifying JavaScript data structures in older browsers.
/*$name = 'json2';
if (!libraries_detect($name)) {
watchdog('responsive', 'The JSON-js library is recommended for this module to function properly. Some older browsers do not provide the JSON function natively. Please visit !url to obtain this library.',
array(
'!url' => l('JSON-js (Github)', 'https://github.com/douglascrockford/JSON-js',
array(
'absolute' => TRUE,
'external' => TRUE
)
)
),
WATCHDOG_NOTICE
);
}
else {
libraries_load($name);
}*/
return parent::form($form, $form_state, $layout);
}