aChoices = $aChoices; } /** * @param mixed $value Warning can either be an array (if multiple values are allowed in the field) or a primitive : {@see \Combodo\iTop\Form\Field\MultipleChoicesField::GetCurrentValue()} * * @return array|string[] */ public function Validate($value): array { $aErrorMessages = []; if (false === is_array($value)) { $this->CheckValueAgainstChoices($value, $aErrorMessages); return $aErrorMessages; } if (count($value) === 0) { return []; } /** @noinspection PhpUnusedLocalVariableInspection */ foreach ($value as $sCode => $valueItem) { if (utils::IsNullOrEmptyString($valueItem)) { continue; } $this->CheckValueAgainstChoices($valueItem, $aErrorMessages); } return $aErrorMessages; } private function CheckValueAgainstChoices(string $sValue, array &$aErrorMessages): void { if (false === array_key_exists($sValue, $this->aChoices)) { $aErrorMessages[] = "Value ({$sValue}) is not part of the field possible values list"; } } }