Commit 2b31d29c authored by Igor Biki's avatar Igor Biki
Browse files

ISTWCMS-3830 Update to configuration form.

parent a55991f3
......@@ -147,21 +147,12 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl
* {@inheritDoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
$menu_items = $this->getContentMenuItems(TRUE);
// Use configuration if exists, otherwise select all available. Using
// serialize because dot is not supported as array key, exception will be
// thrown from ConfigBase.php:211.
$config_menu = unserialize($this->configuration['selected_menus']);
// Merging two arrays to ensure new menu items are selected by default.
// Using plus(+) instead of array_merge because don't want to update
// array values for keys found in both arrays.
if ($config_menu) {
$default_values = array_keys(array_filter($config_menu + $menu_items));
}
else {
$default_values = array_keys(array_filter($menu_items));
}
$selected_menus = unserialize($this->configuration['selected_menus']);
// Get all content menu items, load them.
$menu_first_level = $this->getContentMenuItems();
$form['details'] = [
......@@ -174,11 +165,23 @@ class ContentManagementMenuBlock extends BlockBase implements ContainerFactoryPl
if (!empty($sub_tree)) {
$primary = $item_first_level->link;
$form['details'][$primary->getPluginId()] = [
$primary_id = $primary->getPluginId();
// Merging two arrays to ensure new menu items are selected by default.
// Using plus(+) instead of array_merge because don't want to update
// array values for keys found in both arrays.
if (isset($selected_menus[$primary_id])) {
$default_value = array_keys(array_filter($selected_menus[$primary_id] + $sub_tree));
}
else {
$default_value = array_keys($sub_tree);
}
$form['details'][$primary_id] = [
'#type' => 'checkboxes',
'#title' => $primary->getTitle(),
'#options' => $sub_tree,
'#default_values' => $config_menu[$primary->getPluginId()],
'#default_value' => $default_value,
];
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment