public static function SqlContentEntityStorageSchema::castValue in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::castValue()
- 10 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::castValue()
Typecasts values to proper datatypes.
MySQL PDO silently casts, e.g. FALSE and '' to 0, when inserting the value into an integer column, but PostgreSQL PDO does not. Use the schema information to correctly typecast the value.
@internal
Parameters
array $info: An array describing the schema field info. See hook_schema() and https://www.drupal.org/node/146843 for details.
mixed $value: The value to be converted.
Return value
mixed The converted value.
See also
https://www.drupal.org/node/146843
6 calls to SqlContentEntityStorageSchema::castValue()
- drupal_schema_get_field_value in core/
includes/ schema.inc - Typecasts values to proper data types.
- SchemaLegacyTest::testSchemaGetFieldValue in core/
tests/ Drupal/ KernelTests/ Core/ Database/ SchemaLegacyTest.php - Tests deprecation of the drupal_schema_get_field_value() function.
- SqlContentEntityStorage::mapToStorageRecord in core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorage.php - Maps from an entity object to the storage record.
- SqlContentEntityStorage::saveToDedicatedTables in core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorage.php - Saves values of fields that use dedicated tables.
- SqlContentEntityStorageSchema::getSharedTableFieldSchema in core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorageSchema.php - Gets the schema for a single field definition.
File
- core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorageSchema.php, line 2608
Class
- SqlContentEntityStorageSchema
- Defines a schema handler that supports revisionable, translatable entities.
Namespace
Drupal\Core\Entity\SqlCode
public static function castValue(array $info, $value) {
// Preserve legal NULL values.
if (isset($value) || !empty($info['not null'])) {
if ($info['type'] === 'int' || $info['type'] === 'serial') {
return (int) $value;
}
elseif ($info['type'] === 'float') {
return (double) $value;
}
return (string) $value;
}
return $value;
}