values(array_values($enumValues)); if ( array_key_exists('default', $params) ) { $schema->defaultValue($params['default']); } parent::__construct($schema, $id, $store, $params); } public function isChoiceEnabled($value) { $schema = $this->getSchema(); if ( $schema instanceof Enum ) { return $schema->isValueEnabled($value); } return true; //Should never happen, but just in case. } /** * @param mixed $value * @param string|null $label * @param string|null $description * @param bool|callable|null $state * @param string|null $icon * @return $this */ public function describeChoice($value, $label, $description = '', $state = null, $icon = null) { $schema = $this->getSchema(); if ( $schema instanceof Enum ) { $schema->describeValue($value, $label, $description, $state, $icon); } return $this; } /** * Automatically generate dropdown/radio/etc options from the setting's * possible values. * * Will use custom labels/descriptions if available. * * @return ChoiceControlOption[] */ public function generateChoiceOptions() { return ChoiceControlOption::fromEnumSetting($this); } /** * @return array */ public function getEnumValues() { $schema = $this->getSchema(); if ( $schema instanceof Enum ) { return $schema->getEnumValues(); } return []; } public function getChoiceDetails($value) { $schema = $this->getSchema(); if ( $schema instanceof Enum ) { return $schema->getValueDetails($value); } return null; } }