public function CheeseburgerMenu::blockForm in Cheeseburger Menu 8.4
Same name and namespace in other branches
- 8 src/Plugin/Block/CheeseburgerMenu.php \Drupal\cheeseburger_menu\Plugin\Block\CheeseburgerMenu::blockForm()
- 8.2 src/Plugin/Block/CheeseburgerMenu.php \Drupal\cheeseburger_menu\Plugin\Block\CheeseburgerMenu::blockForm()
- 8.3 src/Plugin/Block/CheeseburgerMenu.php \Drupal\cheeseburger_menu\Plugin\Block\CheeseburgerMenu::blockForm()
Block form.
Overrides BlockPluginTrait::blockForm
File
- src/
Plugin/ Block/ CheeseburgerMenu.php, line 206 - Cheeseburger class extends BlockBase.
Class
- CheeseburgerMenu
- Block info.
Namespace
Drupal\cheeseburger_menu\Plugin\BlockCode
public function blockForm($form, FormStateInterface $form_state) {
$config = $this
->getConfiguration();
$menu_names = $this->renderCheesebugerMenuService
->getAllMenuLinkNames();
$taxonomy_term_names = $this->renderCheesebugerMenuService
->getAllTaxonomyTermNames();
// DEPTH.
$form['depth'] = [
'#title' => $this
->t('Maximum menu depth. Use 0 for no limit.'),
'#type' => 'number',
'#default_value' => (int) $config['depth'],
];
// CSS DEFAULT.
$form['css_default'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use default css'),
'#default_value' => (int) $config['css_default'],
];
// SHOW NAVIGATION.
$form['show_navigation'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show navigation'),
'#default_value' => (int) $config['show_navigation'],
];
$form['hidden_by_default'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Hidden by default'),
'#default_value' => (int) $config['hidden_by_default'],
];
// ACTIVE STATE ENABLE.
$form['active_state_enable'] = [
'#title' => $this
->t('Active state enable'),
'#type' => 'checkbox',
'#default_value' => (int) $config['active_state_enable'],
'#description' => $this
->t('Cheeseburger menu will try to activate active menu item based on current route, in some cases Cheeseburger is not able to do so. This feature needs to disable Drupal Caching system. In case this feature is not needed, disable this to speed up Cheeseburger menu.'),
];
// Parent menu link.
$form['parent_menu_as_link'] = [
'#title' => $this
->t('Enable link for parent menu item'),
'#type' => 'checkbox',
'#default_value' => (int) $config['parent_menu_as_link'],
];
// HEADER HEIGHT.
$form['header_height'] = [
'#title' => $this
->t('Site header height'),
'#type' => 'number',
'#default_value' => (int) $config['header_height'],
];
// LANGUAGE SWITCHER.
if ($this->languageManager
->isMultilingual()) {
$form += $this
->buildMenuItemFormElement('lang_switcher', $this
->t('Enable language switcher'));
}
if ($this->moduleHandler
->moduleExists('commerce_cart')) {
$form += $this
->buildMenuItemFormElement('cart', $this
->t('Cart'));
}
$form += $this
->buildMenuItemFormElement('phone', $this
->t('Phone'));
$options[0] = $this
->t('Manual');
if ($this->moduleHandler
->moduleExists('commerce_store')) {
$store_field_definitions = $this->entityFieldManager
->getFieldDefinitions('commerce_store', 'online');
if (array_key_exists('field_phone', $store_field_definitions)) {
$sql = $this->database
->query("SELECT store_id, name FROM commerce_store_field_data")
->fetchAll();
foreach ($sql as $stores) {
$options[$stores->store_id] = $stores->name;
}
}
}
$form['phone']['store'] = [
'#type' => 'select',
'#title' => $this
->t('Choose your store'),
'#options' => $options,
'#states' => [
'invisible' => [
':input[name="settings[phone][show]"]' => [
'checked' => FALSE,
],
],
],
'#default_value' => $config['phone']['store'],
];
$form['phone']['manual_title'] = [
'#title' => 'Phone number',
'#type' => 'textfield',
'#states' => [
'visible' => [
':input[name="settings[phone][store]"]' => [
'value' => 0,
],
':input[name="settings[phone][show]"]' => [
'checked' => TRUE,
],
],
],
'#default_value' => $config['phone']['manual_title'],
];
$form['phone']['description'] = [
'#markup' => '<div>' . $this
->t('To use phone from store, add field with machine name field_phone to your store type') . '</div>',
];
//unset($form['phone']);
// MENU.
$form['menu'] = $this
->buildConfigMenuForm($menu_names, 'menu', $this
->t('Menus'));
// TAXONOMY.
$form['taxonomy_vocabulary'] = $this
->buildConfigMenuForm($taxonomy_term_names, 'taxonomy_vocabulary', $this
->t('Vocabularies'));
$breakpoints = $this->renderCheesebugerMenuService
->returnBreakpointsForDefaultTheme();
$breakpoint_description = $this
->t('This module uses breakpoints from your default theme<br>If you want to change it, make your changes in default_theme_name.breakpoints.yml<br><br>');
if (!empty($breakpoints)) {
$form['breakpoints'] = [
'#type' => 'fieldset',
'#title' => 'Enable breakpoints',
];
$form['breakpoints']['all'] = [
'#type' => 'select',
'#options' => [
0 => 'Custom',
1 => 'All',
],
'#default_value' => (int) $config['breakpoints']['all'],
];
$options = [
'0' => '0px',
];
foreach ($breakpoints as $name => $breakpoint) {
if (strtolower($breakpoint['label']) != 'all' && strpos($breakpoint['mediaQuery'], ' 0px') === FALSE) {
$options[$name] = $breakpoint['label'];
$breakpoint_description .= $breakpoint['label'] . ': ' . $breakpoint['mediaQuery'] . '<br>';
}
}
$form['breakpoints']['from'] = [
'#prefix' => '<div class="container-inline">',
'#type' => 'select',
'#states' => [
'visible' => [
':input[name="settings[breakpoints][all]"]' => [
'value' => 0,
],
],
],
'#options' => $options,
'#title' => 'From',
'#default_value' => array_key_exists('breakpoints', $config) ? array_key_exists('from', $config['breakpoints']) ? $config['breakpoints']['from'] : '0' : '0',
];
$form['breakpoints']['to'] = [
'#type' => 'select',
'#suffix' => '</div>',
'#title' => 'To',
'#states' => [
'visible' => [
':input[name="settings[breakpoints][all]"]' => [
'value' => 0,
],
],
],
'#options' => $options,
'#default_value' => array_key_exists('breakpoints', $config) ? array_key_exists('to', $config['breakpoints']) ? $config['breakpoints']['to'] : '0' : '0',
];
if (!empty($breakpoint_description)) {
$form['breakpoints']['#description'] = $breakpoint_description;
}
}
return $form;
}