Problem/Motivation

Split deprecation of drupal_schema_get_field_value() from #2124069: Convert schema.inc to the update.update_hook_registry service (UpdateHookRegistry)

Proposed resolution

Add static \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::castValue()

Remaining tasks

User interface changes

None

API changes

drupal_schema_get_field_value() deprecated in favour of \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::castValue()

CommentFileSizeAuthor
#2 3051981-2.patch8.96 KBandypost

Comments

andypost created an issue. See original summary.

andypost’s picture

Status: Active » Needs review
StatusFileSize
new8.96 KB

Here's a patch

amateescu credited Berdir.

amateescu’s picture

Component: base system » entity system
Status: Needs review » Reviewed & tested by the community

Looks great to me!

Added credit for everyone who worked on this part of the patch from the parent issue.

alexpott’s picture

Issue summary: View changes

amateescu credited voleger.

amateescu’s picture

Fixing the credits after reading the parent issue again, I forgot quite a few people. Sorry! :(

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed ecf0410 and pushed to 8.8.x. Thanks!

Discussed this with @amateescu, @Berdir and @larowlan a bit. Whilst I think burying this in entity storage is in someways sub-optimal - this is one fo those hard choices and sat least we've marked it internal. Hopefully at some point we can remove this entirely and replace it with PHP strict typing and scalar type hints.

  • alexpott committed ecf0410 on 8.8.x
    Issue #3051981 by andypost, alexpott, amateescu, kim.pepper, Berdir,...
plach’s picture

+++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
@@ -1097,7 +1097,7 @@ protected function mapToStorageRecord(ContentEntityInterface $entity, $table_nam
+        $value = SqlContentEntityStorageSchema::castValue($definition->getSchema()['columns'][$column_name], $value);

@@ -1398,7 +1398,7 @@ protected function saveToDedicatedTables(ContentEntityInterface $entity, $update
+            $record[$column_name] = SqlContentEntityStorageSchema::castValue($attributes, $value);

+++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
@@ -2099,7 +2099,7 @@ protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $st
+        $schema['fields'][$schema_field_name]['initial'] = SqlContentEntityStorageSchema::castValue($column_schema, $initial_value[$field_column_name]);

Do these mean we're loading SqlContentEntityStorageSchema on every request (~2300 LoC)? I'd rather have put this into the storage class itself to avoid that...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.