function RenderExampleDemoForm::buildForm
File
-
modules/render_example/src/Form/RenderExampleDemoForm.php, line 55
Class
- RenderExampleDemoForm
- Provides the form for toggling module features on and off.
Namespace
Drupal\render_example\Form
Code
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('render_example.settings');
$form['description'] = [
'#markup' => $this->t('This example shows what render arrays look like in the building of a page. It will not work unless the user running it has the "access devel information" privilege. It shows both the actual arrays used to build a page or block, and examples of altering the page late in its lifecycle.'),
];
$form['show_arrays'] = [
'#type' => 'fieldset',
'#title' => $this->t('Show render arrays'),
'render_example_show_block' => [
'#type' => 'checkbox',
'#title' => $this->t('Show block render arrays'),
'#default_value' => $config->get('show_block'),
'#access' => $this->moduleHandler
->moduleExists('devel'),
],
'render_example_show_page' => [
'#type' => 'checkbox',
'#title' => $this->t('Show page render arrays'),
'#default_value' => $config->get('show_page'),
'#access' => $this->moduleHandler
->moduleExists('devel'),
],
'render_example_devel' => [
'#markup' => $this->t('Install the Devel module (https://www.drupal.org/project/devel) to enable additional demonstration features.'),
'#access' => !$this->moduleHandler
->moduleExists('devel'),
],
];
$form['page_fiddling'] = [
'#type' => 'fieldset',
'#title' => $this->t('Make changes on all pages via hook_preprocess_page()'),
'#description' => $this->t('Theses changes are all made via the function render_example_preprocess_page()'),
'render_example_move_breadcrumbs' => [
'#title' => $this->t('Move the breadcrumbs to the top of the content area'),
'#description' => $this->t('Uses hook_preprocess_page() to move the breadcrumbs into another region.'),
'#type' => 'checkbox',
'#default_value' => $config->get('move_breadcrumbs'),
],
'render_example_reverse_sidebar' => [
'#title' => $this->t('Reverse ordering of sidebar_first elements (if it exists)'),
'#description' => $this->t('Uses hook_preprocess_page() to reverse the ordering of items in sidebar_first'),
'#type' => 'checkbox',
'#default_value' => $config->get('reverse_sidebar'),
],
'render_example_wrap_blocks' => [
'#title' => $this->t('Use #prefix and #suffix to wrap a div around every block'),
'#description' => $this->t('Uses hook_block_view_alter() to wrap all blocks with a div using #prefix and #suffix'),
'#type' => 'checkbox',
'#default_value' => $config->get('wrap_blocks'),
],
];
$form['tabledrag'] = [
'#type' => 'table',
'#id' => 'draggable-table',
'#caption' => $this->t('Our favorite colors.'),
'#header' => [
$this->t('Name'),
$this->t('Favorite color'),
$this->t('Weight'),
],
'#tabledrag' => [
[
'table_id' => 'draggable-table',
'action' => 'order',
'relationship' => 'sibling',
'group' => 'table-order-weight',
],
],
[
'#attributes' => [
'class' => [
'draggable',
],
],
'name' => [
'#plain_text' => $this->t('Teal'),
],
'color' => [
'#plain_text' => $this->t('teal'),
],
'weight' => [
'#type' => 'weight',
'#title_display' => 'invisible',
'#default_value' => 1,
'#attributes' => [
'class' => [
'table-order-weight',
],
],
],
],
[
'#attributes' => [
'class' => [
'draggable',
],
],
'name' => [
'#plain_text' => $this->t('Amber'),
],
'color' => [
'#plain_text' => $this->t('green'),
],
'weight' => [
'#type' => 'weight',
'#title_display' => 'invisible',
'#default_value' => 2,
'#attributes' => [
'class' => [
'table-order-weight',
],
],
],
],
[
'#attributes' => [
'class' => [
'draggable',
],
],
'name' => [
'#plain_text' => $this->t('Blake'),
],
'color' => [
'#plain_text' => $this->t('#063'),
],
'weight' => [
'#type' => 'weight',
'#title_display' => 'invisible',
'#default_value' => 3,
'#attributes' => [
'class' => [
'table-order-weight',
],
],
],
],
[
'#attributes' => [
'class' => [
'draggable',
],
],
'name' => [
'#plain_text' => $this->t('Enid'),
],
'color' => [
'#plain_text' => $this->t('indigo'),
],
'weight' => [
'#type' => 'weight',
'#title_display' => 'invisible',
'#default_value' => 4,
'#attributes' => [
'class' => [
'table-order-weight',
],
],
],
],
[
'#attributes' => [
'class' => [
'draggable',
],
],
'name' => [
'#plain_text' => $this->t('Joe'),
],
'color' => [
'#plain_text' => $this->t('green'),
],
'weight' => [
'#type' => 'weight',
'#title_display' => 'invisible',
'#default_value' => 5,
'#attributes' => [
'class' => [
'table-order-weight',
],
],
],
],
];
$form['tableselect'] = [
'#type' => 'table',
'#caption' => $this->t('Our favorite colors.'),
'#header' => [
$this->t('Name'),
$this->t('Favorite color'),
],
'#tableselect' => TRUE,
[
'name' => [
'#plain_text' => $this->t('Teal'),
],
'color' => [
'#plain_text' => $this->t('teal'),
],
],
[
'#attributes' => [
'class' => [
'draggable',
],
],
'name' => [
'#plain_text' => $this->t('Amber'),
],
'color' => [
'#plain_text' => $this->t('green'),
],
],
[
'#attributes' => [
'class' => [
'draggable',
],
],
'name' => [
'#plain_text' => $this->t('Blake'),
],
'color' => [
'#plain_text' => $this->t('#063'),
],
],
[
'#attributes' => [
'class' => [
'draggable',
],
],
'name' => [
'#plain_text' => $this->t('Enid'),
],
'color' => [
'#plain_text' => $this->t('indigo'),
],
],
[
'#attributes' => [
'class' => [
'draggable',
],
],
'name' => [
'#plain_text' => $this->t('Joe'),
],
'color' => [
'#plain_text' => $this->t('green'),
],
],
];
return parent::buildForm($form, $form_state);
}