public function CheeseburgerMenuBlock::buildConfigurationForm in Cheeseburger Menu 5.0.x
Form constructor.
Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.
Parameters
array $form: An associative array containing the initial structure of the plugin form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Return value
array The form structure.
Overrides BlockBase::buildConfigurationForm
File
- src/
Plugin/ Block/ CheeseburgerMenuBlock.php, line 161
Class
- CheeseburgerMenuBlock
- Provides a 'CheeseburgerMenu' block.
Namespace
Drupal\cheeseburger_menu\Plugin\BlockCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['default_css'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use default css'),
'#description' => $this
->t('Use default css provided by cheeseburger menu module'),
'#default_value' => $this
->getConfigValue('default_css'),
];
$form['default_js'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use default js'),
'#description' => $this
->t('Use default js provided by cheeseburger menu module'),
'#default_value' => $this
->getConfigValue('default_js'),
];
$form['hidden'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Hidden by default'),
'#default_value' => $this
->getConfigValue('hidden'),
'#access' => FALSE,
];
$form['parent_menu_as_link'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show parent menu item as link'),
'#default_value' => $this
->getConfigValue('parent_menu_as_link'),
];
$form['show_navigation'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show navigation'),
'#default_value' => $this
->getConfigValue('show_navigation'),
];
$form['invoke_hooks'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Invoke hooks'),
'#description' => $this
->t('If you are not using advantage of alter hooks, disable this for performance reasons. For more info about hooks see cheeseburger_menu.api.php file'),
'#default_value' => $this
->getConfigValue('invoke_hooks'),
];
$form['menus'] = [
'#type' => 'table',
'#header' => [
'label' => $this
->t('Label'),
'weight' => $this
->t('Weight'),
'menu_type' => $this
->t('Menu type'),
'settings' => $this
->t('Settings'),
],
'#empty' => $this
->t('There are no menus yet.'),
'#tabledrag' => [
[
'action' => 'order',
'relationship' => 'sibling',
'group' => 'weight',
],
],
] + $this->service
->getMenusAsRows($this
->getConfigValue('menus', []));
$form['colors'] = [
'#type' => 'table',
'#header' => [
'left_side_background' => $this
->t('Left side background'),
'left_side_text' => $this
->t('Left side text'),
'right_side_background' => $this
->t('Right side background'),
'right_side_text' => $this
->t('Right side text'),
'trigger' => $this
->t('Trigger'),
'trigger_background' => $this
->t('Trigger background'),
'scrollbar' => $this
->t('Scrollbar'),
],
];
// Colors.
$form['colors']['row'] = [];
$row =& $form['colors']['row'];
$row['left_side_background']['left_side_background_color'] = [
'#type' => 'color',
'#title' => $this
->t('Left side background color'),
'#default_value' => strtoupper($this
->getConfigValue('left_side_background_color')),
];
$row['left_side_background']['left_side_background_opacity'] = [
'#type' => 'number',
'#title' => $this
->t('Left side background opacity'),
'#max' => 1,
'#min' => 0,
'#step' => 0.1,
'#default_value' => $this
->getConfigValue('left_side_background_opacity'),
];
$row['left_side_text']['left_side_text_color'] = [
'#type' => 'color',
'#title' => $this
->t('Left side text color'),
'#default_value' => strtoupper($this
->getConfigValue('left_side_text_color')),
];
$row['left_side_text']['left_side_text_opacity'] = [
'#type' => 'number',
'#title' => $this
->t('Left side text opacity'),
'#max' => 1,
'#min' => 0,
'#step' => 0.1,
'#default_value' => $this
->getConfigValue('left_side_text_opacity'),
];
$row['right_side_background']['right_side_background_color'] = [
'#type' => 'color',
'#title' => $this
->t('Right side background color'),
'#default_value' => strtoupper($this
->getConfigValue('right_side_background_color')),
];
$row['right_side_background']['right_side_background_opacity'] = [
'#type' => 'number',
'#title' => $this
->t('Right side background opacity'),
'#max' => 1,
'#min' => 0,
'#step' => 0.1,
'#default_value' => $this
->getConfigValue('right_side_background_opacity'),
];
$row['right_side_text']['right_side_text_color'] = [
'#type' => 'color',
'#title' => $this
->t('Right side text color'),
'#default_value' => strtoupper($this
->getConfigValue('right_side_text_color')),
];
$row['right_side_text']['right_side_text_opacity'] = [
'#type' => 'number',
'#title' => $this
->t('Right side text opacity'),
'#max' => 1,
'#min' => 0,
'#step' => 0.1,
'#default_value' => $this
->getConfigValue('right_side_text_opacity'),
];
$row['trigger']['trigger_color'] = [
'#type' => 'color',
'#title' => $this
->t('Trigger color'),
'#default_value' => strtoupper($this
->getConfigValue('trigger_color')),
];
$row['trigger']['trigger_opacity'] = [
'#type' => 'number',
'#title' => $this
->t('Trigger opacity'),
'#max' => 1,
'#min' => 0,
'#step' => 0.1,
'#default_value' => $this
->getConfigValue('trigger_opacity'),
];
$row['trigger_background']['trigger_background_color'] = [
'#type' => 'color',
'#title' => $this
->t('Trigger background color'),
'#default_value' => strtoupper($this
->getConfigValue('trigger_background_color')),
];
$row['trigger_background']['trigger_background_opacity'] = [
'#type' => 'number',
'#title' => $this
->t('Trigger background opacity'),
'#max' => 1,
'#min' => 0,
'#step' => 0.1,
'#default_value' => $this
->getConfigValue('trigger_background_opacity'),
];
$row['scrollbar']['scrollbar_color'] = [
'#type' => 'color',
'#title' => $this
->t('Scrollbar color'),
'#default_value' => strtoupper($this
->getConfigValue('scrollbar_color')),
];
$row['scrollbar']['scrollbar_opacity'] = [
'#type' => 'number',
'#title' => $this
->t('Scrollbar opacity'),
'#max' => 1,
'#min' => 0,
'#step' => 0.1,
'#default_value' => $this
->getConfigValue('scrollbar_opacity'),
];
return $form;
}