public function ChecklistapiChecklist::__construct in Checklist API 8
Constructs a ChecklistapiChecklist object.
Parameters
array $definition: A checklist definition, as returned by checklistapi_get_checklist_info().
File
- src/
ChecklistapiChecklist.php, line 109
Class
- ChecklistapiChecklist
- Defines the checklist class.
Namespace
Drupal\checklistapiCode
public function __construct(array $definition) {
foreach (Element::children($definition) as $group_key) {
$this->numberOfItems += count(Element::children($definition[$group_key]));
$this->items[$group_key] = $definition[$group_key];
unset($definition[$group_key]);
}
foreach ($definition as $property_key => $value) {
if ($property_key === '#storage') {
continue;
}
$property_name = checklistapi_strtolowercamel(mb_substr($property_key, 1));
$this->{$property_name} = $value;
}
$storage = 'config';
$allowed_storage_values = [
'config',
'state',
];
if (isset($definition['#storage']) && in_array($definition['#storage'], $allowed_storage_values)) {
$storage = $definition['#storage'];
}
$this->storage = \Drupal::service("checklistapi_storage.{$storage}")
->setChecklistId($this->id);
$this->savedProgress = $this->storage
->getSavedProgress();
}