-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Referencing a different entity type is broken in the complex widget #163
Referencing a different entity type is broken in the complex widget #163
Conversation
…he entity that the field is attached to. This is a logical mistake. Target type should be the group type. Changed to $this->getFieldSetting('target_type') in order to obtaing the target type of the original widget field. Similar to: amitaibu#120
Can you be a little bit more specific in the instructions how to reproduce the problem? When I try to replicate it I indeed hit a bug, but it is different than what you describe, and the fix doesn't solve it. A test case would be even better :) Here's what I tried:
Result: the AJAX call fails with the following error:
From a first look this is due to my field config being incorrectly saved, I see this in
That |
I manually fixed my field settings to the following:
But I still couldn't reference my Group custom block. I digged into With these changes I can reference the custom blocks. Two things to do:
|
|
There is still a bug here. The "Other Groups" field works now, but the "Groups Audience" field still doesn't work as expected. |
This is how
This is how
We need to decide on either format. |
The first block code looks like the correct one
Further more I believe (btw, just to set the common language -- a single (group audience) field has to "field modes" default and admin, or could be called "my groups" and "other groups") |
Ok let's wait until #161 is in. |
Going to continue on this. I'm currently blocked on #162 on the saving of target_bundles, and the solution I'm working on is causing the OgComplexTest to fail. I need some fixes in the OgComplex widget, meaning I need either this or #161 to be finished. I had a look at #161 but it still needs some work. This doesn't really interfere with that either it seems, the merge conflicts will be pretty minimal. |
I think it's fixed now. Still needs a test. |
I started on the test by using the Custom Block entity type instead of Node to create the group. So far it seems to work fine for the Other Groups field. Still need to test the Groups Audience field as mentioned in one of my previous comments. I am only working for two days this week because of some religious holiday, and I will have to work on other tasks for the moment. I will probably be able to pick this back up next Monday at the earliest. |
Picking this back up since it is blocking my work in #162 |
I now have the strange situation that if I follow the steps from the first comment manually it doesn't work as expected, but when I run the test it does. It appears that when the group audience field is added in the setup of the test the field storage settings are correct, but when I add it through the interface it is incorrectly set to "node" instead of "block_content". I compared it with a vanilla entityreference field to make sure that my assumptions are correct. This is the field storage config of the group audience field (
Here is the config of the vanilla entity reference field I created to compare:
I also checked the field instance config, the target type is erroneously set here it seems. This is
As reference, here is the vanilla entityreference equivalent:
|
Fixed it in the UI. We can also better add a test for this, to check that the fields are correctly saved when created through the UI. So remaining work here:
|
To prove that the tests correctly detect the bug I created a temporary branch that only contains the tests: https://github.com/amitaibu/og/tree/PR163-test-only It is currently being tested at https://travis-ci.org/amitaibu/og/builds/119533962 - if all goes well these tests should fail. |
Great, both tests fail as expected in the PR163-test-only branch. The first test fails with a 500 error which is due to uncaught InvalidArgumentException that I mentioned in my first comment:
The second one correctly fails since the target entity type is not set correctly:
That means that this is ready for review. If you want to test this manually you can follow the steps in the first comment after the issue summary. |
Awesome! I'm finally going to have some OG time this coming week(s), so I plan to review this properly. |
@@ -75,18 +76,20 @@ function og_ui_entity_type_save(EntityInterface $entity) { | |||
} | |||
|
|||
// Change the field target type and bundle. | |||
if ($field_storage = FieldStorageConfig::loadByName($entity_type_id, OgGroupAudienceHelper::DEFAULT_FIELD)) { | |||
$target_type = $field_storage->getSetting('target_type'); | |||
if ($entity->og_target_type !== $target_type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, couldn't hold myself :)
where in the UI to you see the posibility to change the target type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a minor comment, but this is good to go. Thanks! |
Awesome, thanks! |
Og membership state cache context
$this->fieldDefinition->getTargetEntityTypeId() returns the type of the entity that the field is attached to.
This is a logical mistake. Target type should be the group type.
Changed to $this->getFieldSetting('target_type') in order to obtaing the target type of the original widget field.
Similar to: #120
To reproduce, you can create an entity type other than node or user and make it a og group.
Then create a content type and make it a candidate member of that group.
Create some dummy group content.
Try to add content as an admin of og in order to get the "Other groups" field.
The functionality should be problematic because the target type of the "Other group" field is set to node (our content type) instead of the group entity type.
if you enter something and submit, the site also breaks.