public function CheeseburgerMenu::blockForm in Cheeseburger Menu 8
Same name and namespace in other branches
- 8.4 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()
Return value
$form builds up the block form
Overrides BlockPluginTrait::blockForm
File
- src/
Plugin/ Block/ CheeseburgerMenu.php, line 69
Class
- CheeseburgerMenu
- Plugin annotation @Block( id = "cheesebuger_menu_block", admin_label = @Translation("Cheeseburger Menu"), category = @Translation("Block") )
Namespace
Drupal\cheeseburger_menu\Plugin\BlockCode
public function blockForm($form, FormStateInterface $form_state) {
$config = $this
->getConfiguration();
$controller = new renderCheeseburgerMenuBlock();
$menu_names = $controller
->getAllMenuLinkNames();
$menu_ids = $controller
->getAllMenuLinkId();
$taxonomy_term_names = $controller
->getAllTaxonomyTermNames();
$taxonomy_term_ids = $controller
->getAllTaxonomyTermIds();
$moduleHandler = \Drupal::service('module_handler');
/** @var Drupal\Core\Language\LanguageManager $languageManager */
$languageManager = \Drupal::service('language_manager');
// TITLE AND LANGUAGE SWITCHER
if ($languageManager
->isMultilingual()) {
$form['lang_switcher_checkbox'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable language switcher'),
'#default_value' => isset($config['lang_switcher']) ? $config['lang_switcher'] : 0,
];
$form['language_switcher_weight'] = [
'#type' => 'weight',
'#default_value' => isset($config['language_switcher_weight']) ? $config['language_switcher_weight'] : 0,
'#states' => [
'invisible' => [
':input[name="settings[lang_switcher_checkbox]"]' => [
'checked' => FALSE,
],
],
],
];
}
$container_inline = [
'#type' => 'container',
'#attributes' => [
'class' => [
'container-inline',
],
],
];
$form['css_default'] = [
'#prefix' => '<div class="container-inline">',
'#type' => 'checkbox',
'#suffix' => '<label>Use default CSS file</label></div>',
'#default_value' => isset($config['css_default']) ? $config['css_default'] : TRUE,
];
$form['headerHeight'] = [
'#title' => 'Header height',
'#type' => 'number',
'#default_value' => isset($config['headerHeight']) ? $config['headerHeight'] : 0,
];
$form['headerPadding'] = [
'#title' => 'Header padding',
'#type' => 'number',
'#default_value' => isset($config['headerPadding']) ? $config['headerPadding'] : 0,
];
//ADDITIONAL OPTIONS
$form['additional_options'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Additional options'),
];
$form['additional_options']['hr1'] = [
'#type' => 'markup',
'#markup' => '<hr>',
];
if ($moduleHandler
->moduleExists('commerce_cart')) {
$form['additional_options']['cart'] = [
'#prefix' => '<div class="container-inline">',
'#type' => 'checkbox',
'#suffix' => '<label>Cart</label></div>',
'#default_value' => isset($config['cart_appear']) ? $config['cart_appear'] : FALSE,
];
$form['additional_options']['cart_weight'] = [
'#type' => 'weight',
'#default_value' => isset($config['cart_weight']) ? $config['cart_weight'] : 0,
'#states' => [
'invisible' => [
':input[name="settings[additional_options][cart]"]' => [
'checked' => FALSE,
],
],
],
];
}
$form['additional_options']['hr2'] = [
'#type' => 'markup',
'#markup' => '<hr>',
];
$form['additional_options']['phone'] = [
'#prefix' => '<div class="container-inline">',
'#type' => 'checkbox',
'#suffix' => '<label>Phone</label></div>',
'#default_value' => isset($config['phone_appear']) ? $config['phone_appear'] : FALSE,
];
$form['additional_options']['phone_weight'] = [
'#type' => 'weight',
'#default_value' => isset($config['phone_weight']) ? $config['phone_weight'] : 0,
'#states' => [
'invisible' => [
':input[name="settings[additional_options][phone]"]' => [
'checked' => FALSE,
],
],
],
];
$options[0] = 'manual';
if ($moduleHandler
->moduleExists('commerce_store')) {
$sql = db_query("SELECT store_id, name FROM commerce_store_field_data")
->fetchAll();
foreach ($sql as $stores) {
$options[$stores->store_id] = $stores->name;
$store = Store::load($stores->store_id);
}
}
$form['additional_options']['phone_store'] = [
'#type' => 'select',
'#title' => $this
->t('Choose your store'),
'#options' => $options,
'#states' => [
'invisible' => [
':input[name="settings[additional_options][phone]"]' => [
'checked' => FALSE,
],
],
],
'#default_value' => isset($config['phone_store']) ? $config['phone_store'] : 0,
];
$form['additional_options']['phone_number'] = [
'#title' => 'Phone number',
'#type' => 'textfield',
'#states' => [
'visible' => [
':input[name="settings[additional_options][phone_store]"]' => [
'value' => 0,
],
':input[name="settings[additional_options][phone]"]' => [
'checked' => TRUE,
],
],
],
'#default_value' => isset($config['phone_number']) ? $config['phone_number'] : '',
];
$form['additional_options']['hr3'] = [
'#type' => 'markup',
'#markup' => '<hr>',
];
$form['menu_fieldset'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Check the menus you want to appear:'),
];
foreach ($menu_names as $name) {
$form['menu_fieldset'][$menu_ids[$name] . '_hr1'] = [
'#type' => 'markup',
'#markup' => '<hr>',
];
// container used to display the elements inline
$form['menu_fieldset'][$menu_ids[$name] . '_container'] = $container_inline;
$form['menu_fieldset'][$menu_ids[$name] . '_container'][$menu_ids[$name] . '_checkbox'] = [
'#type' => 'checkbox',
'#default_value' => isset($config['menus_appear'][$menu_ids[$name]]) ? $config['menus_appear'][$menu_ids[$name]] : 0,
];
$form['menu_fieldset'][$menu_ids[$name] . '_container'][$name] = [
'#type' => 'markup',
'#markup' => $this
->t($name),
];
$form['menu_fieldset'][$menu_ids[$name] . '_weight'] = [
'#type' => 'weight',
'#default_value' => isset($config['menus_weight'][$menu_ids[$name]]) ? $config['menus_weight'][$menu_ids[$name]] : 0,
'#states' => [
'invisible' => [
':input[name="settings[menu_fieldset][' . $menu_ids[$name] . '_container][' . $menu_ids[$name] . '_checkbox]"]' => [
'checked' => FALSE,
],
],
],
];
if (isset($config['menus_title'][$menu_ids[$name]]) && $config['menus_title'][$menu_ids[$name]] === FALSE) {
$default_value = 0;
}
elseif (isset($config['menus_title'][$menu_ids[$name]]) && $config['menus_title'][$menu_ids[$name]] === TRUE) {
$default_value = 1;
}
elseif (isset($config['menus_title'][$menu_ids[$name]])) {
$default_value = 2;
}
else {
$default_value = 0;
}
$form['menu_fieldset'][$menu_ids[$name] . '_title'] = [
'#type' => 'select',
'#title' => $this
->t('Choose title'),
'#options' => [
0 => 'Do not show',
1 => 'Use default title',
2 => 'Manual title',
],
'#states' => [
'invisible' => [
':input[name="settings[menu_fieldset][' . $menu_ids[$name] . '_container][' . $menu_ids[$name] . '_checkbox]"]' => [
'checked' => FALSE,
],
],
],
'#default_value' => $default_value,
];
$form['menu_fieldset'][$menu_ids[$name] . '_manual_title'] = [
'#title' => 'Manual title',
'#type' => 'textfield',
'#states' => [
'visible' => [
':input[name="settings[menu_fieldset][' . $menu_ids[$name] . '_title]"]' => [
'value' => 2,
],
':input[name="settings[menu_fieldset][' . $menu_ids[$name] . '_container][' . $menu_ids[$name] . '_checkbox]"]' => [
'checked' => TRUE,
],
],
],
'#default_value' => $default_value == 2 ? $config['menus_title'][$menu_ids[$name]] : '',
];
$form['menu_fieldset'][$menu_ids[$name] . '_hr2'] = [
'#type' => 'markup',
'#markup' => '<hr>',
];
}
$form['taxonomies'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Check the taxonomies you want to appear:'),
];
foreach ($taxonomy_term_names as $name) {
$form['taxonomies'][$taxonomy_term_ids[$name] . '_hr1'] = [
'#type' => 'markup',
'#markup' => '<hr>',
];
$name = trim($name);
$form['taxonomies'][$taxonomy_term_ids[$name] . '_container'] = $container_inline;
$form['taxonomies'][$taxonomy_term_ids[$name] . '_container'][$taxonomy_term_ids[$name] . '_checkbox'] = [
'#type' => 'checkbox',
'#default_value' => isset($config['taxonomy_appear'][$taxonomy_term_ids[$name]]) ? $config['taxonomy_appear'][$taxonomy_term_ids[$name]] : 0,
];
$form['taxonomies'][$taxonomy_term_ids[$name] . '_container'][$name] = [
'#type' => 'markup',
'#markup' => $this
->t($name),
];
$form['taxonomies'][$taxonomy_term_ids[$name] . '_weight'] = [
'#type' => 'weight',
'#default_value' => isset($config['taxonomy_weight'][$taxonomy_term_ids[$name]]) ? $config['taxonomy_weight'][$taxonomy_term_ids[$name]] : 0,
'#states' => [
'invisible' => [
':input[name="settings[taxonomies][' . $taxonomy_term_ids[$name] . '_container][' . $taxonomy_term_ids[$name] . '_checkbox]"]' => [
'checked' => FALSE,
],
],
],
];
if (isset($config['taxonomy_title'][$taxonomy_term_ids[$name]]) && $config['taxonomy_title'][$taxonomy_term_ids[$name]] === FALSE) {
$default_value = 0;
}
elseif (isset($config['taxonomy_title'][$taxonomy_term_ids[$name]]) && $config['taxonomy_title'][$taxonomy_term_ids[$name]] === TRUE) {
$default_value = 1;
}
elseif (isset($config['taxonomy_title'][$taxonomy_term_ids[$name]])) {
$default_value = 2;
}
else {
$default_value = 0;
}
$form['taxonomies'][$taxonomy_term_ids[$name] . '_title'] = [
'#type' => 'select',
'#title' => $this
->t('Choose title'),
'#options' => [
0 => 'Do not show',
1 => 'Use default title',
2 => 'Manual title',
],
'#states' => [
'invisible' => [
':input[name="settings[taxonomies][' . $taxonomy_term_ids[$name] . '_container][' . $taxonomy_term_ids[$name] . '_checkbox]"]' => [
'checked' => FALSE,
],
],
],
'#default_value' => $default_value,
];
$form['taxonomies'][$taxonomy_term_ids[$name] . '_manual_title'] = [
'#title' => 'Manual title',
'#type' => 'textfield',
'#states' => [
'visible' => [
':input[name="settings[taxonomies][' . $taxonomy_term_ids[$name] . '_title]"]' => [
'value' => 2,
],
':input[name="settings[taxonomies][' . $taxonomy_term_ids[$name] . '_container][' . $taxonomy_term_ids[$name] . '_checkbox]"]' => [
'checked' => TRUE,
],
],
],
'#default_value' => $default_value == 2 ? $config['taxonomy_title'][$taxonomy_term_ids[$name]] : '',
];
$form['taxonomies'][$taxonomy_term_ids[$name] . '_hr2'] = [
'#type' => 'markup',
'#markup' => '<hr>',
];
}
$breakpoints = $controller
->returnBreakpointsForDefaultTheme();
if (!empty($breakpoints)) {
$form['breakpoint_fielset_data'] = [
'#type' => 'fieldset',
'#title' => 'Enable breakpoints',
];
$default_value_all = isset($config['breakpoint_all']) ? $config['breakpoint_all'] : TRUE;
$default_value_all = $default_value_all == TRUE ? 0 : 1;
$form['breakpoint_fielset_data']['all'] = [
'#type' => 'select',
'#options' => [
0 => 'All',
1 => 'Custom',
],
'#default_value' => $default_value_all,
];
$i = 0;
foreach ($breakpoints as $name => $breakpoint) {
if (strtolower($breakpoint['label']) != 'all') {
if (isset($config['breakpoints'][$i]['name']) && $config['breakpoints'][$i]['name'] != FALSE) {
$default_value = 1;
}
else {
$default_value = 0;
}
$form['breakpoint_fielset_data']['breakpoint_checkbox_' . $name] = [
'#type' => 'checkbox',
'#title' => t($breakpoint['label']),
'#default_value' => $default_value,
'#states' => [
'visible' => [
':input[name="settings[breakpoint_fielset_data][all]"]' => [
'value' => 1,
],
],
],
];
$i++;
}
}
}
return $form;
}