public function SettingTrait::nextValue in Fasttoggle 8.2
Move to the next setting value.
Return value
\Drupal\fasttoggle\Plugin\SettingObject\SettingObjectInterface The related object, so you can chain a call to its the save method.
File
- src/
Plugin/ Setting/ SettingTrait.php, line 172 - Fasttoggle Object List of Values Setting
Class
- SettingTrait
- Abstract interface for settings.
Namespace
Drupal\fasttoggle\Plugin\SettingCode
public function nextValue($instance) {
$values = $this
->getValueList();
$current = $this
->get_value($instance);
$useNext = FALSE;
foreach (array_keys($values) as $key) {
if ($useNext) {
$this
->set_value($instance, $key);
return $this;
}
if ($key == $current) {
$useNext = TRUE;
}
}
// Return the first value or the default.
if ($useNext) {
reset($values);
$newValue = key($values);
}
else {
$newValue = $this
->getDefault();
}
$this
->set_value($instance, $newValue);
return $this;
}