public function WidgetDefaults::getInitialParentDefaults in Simple hierarchical select 8
Same name and namespace in other branches
- 2.0.x src/WidgetDefaults.php \Drupal\shs\WidgetDefaults::getInitialParentDefaults()
Gets an initial default values array.
Parameters
string $default_value: The default value.
int $cardinality: (optional) The field's cardinality. Defaults to 1.
Return value
array The initial default value array.
Overrides WidgetDefaultsInterface::getInitialParentDefaults
File
- src/
WidgetDefaults.php, line 40
Class
- WidgetDefaults
- Helper class for setting default values on SHS widgets.
Namespace
Drupal\shsCode
public function getInitialParentDefaults($default_value, $cardinality = 1) {
$parents = [];
// In case of unlimited(-1) we also need one iteration.
if ($cardinality < 0) {
$cardinality = 1;
}
for ($i = 1; $i <= $cardinality; $i++) {
$parents[] = [
[
'parent' => 0,
'defaultValue' => $default_value,
],
];
}
return $parents;
}