public function SettingTrait::previousValue in Fasttoggle 8.2
Move to the previous setting value and save it.
(Allows some widget to implement forward and back buttons if desired).
Parameters
string $attribute: The name of the particular attribute being toggled.
Return value
mixed The array key for the new value.
File
- src/
Plugin/ Setting/ SettingTrait.php, line 211 - Fasttoggle Object List of Values Setting
Class
- SettingTrait
- Abstract interface for settings.
Namespace
Drupal\fasttoggle\Plugin\SettingCode
public function previousValue($instance) {
$values = $this
->getValueList();
$current = $this
->get_value($instance);
$previousKey = NULL;
$newKey = NULL;
foreach (array_keys($values) as $key) {
if ($key == $current) {
if (isNull($previousKey)) {
// Return the last key.
end($values);
$this
->set_value($instance, current($values));
}
else {
$newKey = $previousKey;
}
}
}
// If not found use the default.
if (isNull($newKey)) {
$newKey = $this
->getDefault();
}
$this
->set_value($instance, $newKey);
return $this;
}