(that title should of course be "on relation type save")

Relation types are entity bundles, so it should be expected that Drupal's bundle hooks get called appropriately when things are done with relation type bundles.

Unfortunately, Drupal's bundle hooks are a mess (see this issue in core where a very slow moving consensus is looking at tidying them up) - they are hook_field_attach hooks and they don't get called unless every module that defines entities explicitly calls them at the appropriate time...

It looks like this call has been put in for relation_type_delete(), but not for relation_type_save().

We need this line to trigger hook_field_attach_create_bundle somewhere in relation_type_save()...

field_attach_create_bundle('relation', $relation_type->relation_type);

...like how we have field_attach_delete_bundle('relation', $relation_type); in relation_type_delete()

Comments

alanom’s picture

StatusFileSize
new974 bytes

After testing a bit, here's a super simple rough and ready patch to hopefully get something rolling. Checks that it's creating a new relation, and if it is, it calls the hook. Seems to work.

(probably won't pass testing since it's gitted locally)

chx’s picture

Status: Active » Fixed

Thanks, committed.

Status: Fixed » Closed (fixed)

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

alexverb’s picture

Version: 7.x-1.0-rc2 » 7.x-1.x-dev
Category: task » bug
Status: Closed (fixed) » Needs review
StatusFileSize
new1.13 KB

I don't know what happend since Relation 7.x-1.0-rc2 but it seems like field_attach_delete_bundle() isn't used anymore. I've attached a patch against 7.x-1.x-dev. It looks like sometimes patches aren't applied to the correct branch and old bugs sneek back in.

Status: Needs review » Needs work
alexverb’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
alexverb’s picture

Hmmm, looks like there's a reason field_attach_delete_bundle() is not being used...

alexverb’s picture

My bad, it still needs to delete the bundle from the database itself. First though the field_attach_delete_bundle() took care of that.

alexverb’s picture

Status: Needs work » Needs review

Change status

mikran’s picture

Version: 7.x-1.x-dev » 7.x-1.0-rc2
Category: bug » task
Status: Needs review » Closed (fixed)

...like how we have field_attach_delete_bundle('relation', $relation_type); in relation_type_delete()

After some git blaming on that I found this issue #1260144: Unexpected behaviour when deleting a relation type. There was conversation going on whether to keep everything or delete everything, and apparently keep everything was chosen. Your patch partially restores the old behaviour.

This issue was wrong on to re-open so I'm restoring original status. If you think current behaviour needs improvement please file a new feature request.

mikran’s picture

Issue summary: View changes

clarity