Updated: Comment #14

Problem/Motivation

  1. comment_field_instance_create() contains logic to ensure that the default value of comment fields at least contains entries for each of the sub-values of a comment field, many of which are calculated (ie not present in comment_field_schema()). The logic incorrectly sets the value without respecting any existing default values the calling code may have set.
  2. Also it creates a body field on entity create, but should only do so on insert - which causes sync issues.
  3. Finally, there is some code referencing #731724: Convert comment settings into a field to make them work with CMI and non-node entities in field_purge_batch() that can be removed.

Proposed resolution

  1. Don't blindly set the default value, instead check for its presence first and only append the missing values..
  2. Don't create the body field in hook_field_instance_create, use hook_field_instance_insert instead.
  3. Remove chunk from field_purge_batch().

Remaining tasks

Reviews

User interface changes

None

API changes

None

Original report by @chx

Comments

larowlan’s picture

Title: Comment settings can not be migrated » comment_field_instance_create() overwrites default values
Issue summary: View changes
larowlan’s picture

Status: Active » Needs review
StatusFileSize
new1.06 KB
new1.99 KB

should be red/green

The last submitted patch, 2: comment-default-2172123.fail_.patch, failed testing.

The last submitted patch, 2: comment-default-2172123.fail_.patch, failed testing.

chx’s picture

Title: comment_field_instance_create() overwrites default values » comment_field_instance_create() overwrites default values and breaks the migration

Status: Needs review » Needs work

The last submitted patch, 2: comment-default-2172123.pass_.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
benjy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

andypost’s picture

+++ b/core/modules/comment/comment.module
@@ -232,14 +232,18 @@ function comment_field_instance_create(FieldInstanceInterface $instance) {
+    $instance->default_value += array(array());
+    $instance->default_value[0] += array(

comment field cardinality is 1. so first line is useless

andypost’s picture

StatusFileSize
new632 bytes
new1.99 KB

the fix, still rtbc

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: 2172123-10.patch, failed testing.

alexpott’s picture

comment_field_instance_create() also causes issues for syncing configuration and properly removing comment fields (currently excluded from field_purge_batch())

This blocks #1808248: Add a separate module install/uninstall step to the config import process

larowlan’s picture

Title: comment_field_instance_create() overwrites default values and breaks the migration » Fix various issues with comment_field_instance_create()
Issue summary: View changes

Updated issue summary/title
Working on this

larowlan’s picture

Assigned: larowlan » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new1.7 KB
new3.1 KB

Have at it bot.

larowlan’s picture

Issue summary: View changes
larowlan’s picture

Issue summary: View changes
andypost’s picture

Not sure we still need hook create implementation because it was a workaround for fields created via Field UI that does not set default values. Suppose now Entity field api should set this defaults

chx’s picture

So what's up with this critical now?

larowlan’s picture

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

This was RTBC before, and @larowlan linked to the defaults issue.
The code looks good to me!

berdir’s picture

The referenced issue is only about FieldDefinition, meaning base fields *and* it's about settings, this is about the default value. Not related.

webchick’s picture

Assigned: Unassigned » alexpott

This looks straight-forward to me, but shooting it over to alexpott since he can better evaluate whether the fixes here unblock that other issue.

alexpott’s picture

Assigned: alexpott » Unassigned
Status: Reviewed & tested by the community » Fixed

Committed 854c866 and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

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