-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add
Field#castContainedValues()
method
- Loading branch information
Showing
1 changed file
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -663,7 +663,41 @@ Field.setMethod(function getRecordValue(record, path_to_value_hint) { | |
}); | ||
|
||
/** | ||
* Cast the given value to this field's type | ||
* Cast the value (could be in a container) | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.4.0 | ||
* @version 1.4.0 | ||
* | ||
* @param {*} value | ||
* @param {boolean} to_datasource Is this meant for the datasource? | ||
* | ||
* @return {*} | ||
*/ | ||
Field.setMethod(function castContainedValues(value, to_datasource) { | ||
|
||
if (this.is_translatable && value && this.is_translatable) { | ||
let prefix; | ||
|
||
for (prefix in value) { | ||
value[prefix] = this.cast(value[prefix], to_datasource); | ||
} | ||
} else if (this.is_array && value) { | ||
let i; | ||
|
||
for (i = 0; i < value.length; i++) { | ||
value[i] = this.cast(value[i], to_datasource); | ||
} | ||
} else { | ||
value = this.cast(value, to_datasource); | ||
} | ||
|
||
return value; | ||
}); | ||
|
||
/** | ||
* Cast the given value to this field's type. | ||
* Containers should not be passed (like the array or translation object container) | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.2.0 | ||
|