Commit 918d31b1 authored by chr.fritsch's avatar chr.fritsch Committed by TravisCarden

Issue #2843860 by chr.fritsch, TravisCarden: Config schema validation fails

parent 34d10843
<?php
/**
* @file
* Install, update, and uninstall functions for the Checklist API module.
*/
use \Drupal\Core\Render\Element;
use \Drupal\checklistapi\ChecklistapiChecklist;
/**
* Update saved progress configuration to new schema.
*/
function checklistapi_update_8001() {
$definitions = checklistapi_get_checklist_info();
foreach ($definitions as $id => $definition) {
$checklist = checklistapi_checklist_load($id);
$config = $checklist->config->get(ChecklistapiChecklist::PROGRESS_CONFIG_KEY);
$config['#items'] = [];
$groups = $checklist->items;
foreach (Element::children($groups) as $group_key) {
$group = $groups[$group_key];
// Loop through items.
foreach (Element::children($group) as $item_key) {
if ($config[$item_key]) {
$config['#items'][$item_key] = $config[$item_key];
}
unset($config[$item_key]);
}
}
$checklist->config->set(ChecklistapiChecklist::PROGRESS_CONFIG_KEY, $config)
->save();
}
}
# Schema for the configuration files of the Checklist API module.
checklistapi.progress.*:
type: config_object
label: 'Checklist saved progress'
mapping:
progress:
type: mapping
label: 'The saved progress data.'
mapping:
'#changed':
type: integer
label: 'Last changed timestamp'
'#changed_by':
type: string
label: 'Last change user ID'
'#completed_items':
type: integer
label: 'Number of completed items'
'#items':
type: sequence
label: 'Checklist items'
sequence:
type: mapping
mapping:
'#completed':
type: integer
label: 'Completed timestamp'
'#uid':
type: string
label: 'Completed user ID'
......@@ -237,6 +237,7 @@ class ChecklistapiChecklist {
'#changed' => $time,
'#changed_by' => $user->id(),
'#completed_items' => 0,
'#items' => [],
];
// Loop through groups.
......@@ -268,16 +269,15 @@ class ChecklistapiChecklist {
];
$num_changed_items++;
}
$progress['#items'][$item_key] = $new_item;
}
else {
// Item is unchecked.
$new_item = 0;
if ($old_item) {
// Item was previously checked.
$num_changed_items++;
}
}
$progress[$item_key] = $new_item;
}
}
......
......@@ -79,7 +79,7 @@ class ChecklistapiChecklistForm implements FormInterface {
// Loop through items.
foreach (Element::children($group) as $item_key) {
$item = &$group[$item_key];
$saved_item = !empty($checklist->savedProgress[$item_key]) ? $checklist->savedProgress[$item_key] : 0;
$saved_item = !empty($checklist->savedProgress['#items'][$item_key]) ? $checklist->savedProgress['#items'][$item_key] : 0;
// Build title.
$title = Xss::filter($item['#title']);
if ($saved_item) {
......
Markdown is supported
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