Closed (fixed)
Project:
Flag
Version:
8.x-4.x-dev
Component:
Flag core
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
19 Mar 2015 at 13:16 UTC
Updated:
7 Apr 2015 at 20:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
martin107 commentedSorry getting interrupted.. will try and find time to come back to this.
Comment #2
martin107 commentedSo I am just posting a breakdown of the bug... in the hope someone else will think - Oh I can fix that that it is easy.....
It seems one of the conventions involved in making custom entities fieldable has changes and the flag module need to adapt...
There seems to be a difference between the first time \Drupal\field_ui\Form\FieldEditForm::buildForm() is called and the second time, say when it is used to edit the field
So in steps ...
1) create a flag called flag_A
2) create a field "field_one" attached to the flag
Home-Administration-Structure-Flags-Edit Flag click the "Add field" button.
following the through a few form to this page :-
Home- Administratio- Structure-Flags-Edit Flag-Manage field- field_one and clicking "Save field settings" submit button
this is enough to trigger the error... following the stack trace highlights the form \Drupal\field_ui\Form\FieldEditForm::buildForm()
On creation the call to entity_get_bundles() aka \Drupal::entityManager()->getAllBundleInfo() - well the array that comes back is malformed $bundles[$entity_type][$bundle] exists as expected but $bundles[$entity_type][$bundle]['label'] does not
When I come to edit the field a second time or create a second field on the same flag the array structure is defined as everything works as normal....
Hmm is there something non-standard about the schema definition of a flag? or are we missing a standard code fragment in flag.module --- flag_entity_extra_field_info()
That is the question I seem unable to answer...
Comment #3
joachim commentedI get this error when I save the field settings:
Comment #4
joachim commentedThat line is:
and a debug() of $bundles shows that we have this:
-- which is *completely* wrong. There should not be a bundle of 'flagging' called flagging. The bundles of the flagging entity are the flag names.
Comment #5
joachim commentedPossibly related:
#2457059: Rationalize fields fid and type on flagging entity
#2457057: 'type' column in flagging table is set to 'flag'
Comment #6
joachim commentedMore problems...
The Flagging entity believes its bundle key is 'type':
However, when flaggings are created, the 'type' field is set to a hardcoded string:
And also in the config table, I see 'node.type.article', but 'flag.flag.flag_1'. That looks wrong.
Comment #7
joachim commentedThe field appears to be correctly defined -- its config table ID is 'field.field.flagging.flag_1.field_foobar'.
Comment #8
joachim commentedHuh. I can't reproduce this any more! I could earlier, but now it works fine with no error messages at all.
So one of the following is the explanation:
- the error only happens with the first field that's created on a flag. (I've tried a 2nd field on my first flag, and a new field on a 2nd flag)
- the fix for #2457403: Flag edit form doesn't appear in same tab set as flag field admin also fixes this -- I have my code currently patched with that (!!)
- gremlins (!!!)
Comment #9
martin107 commentedI am happy to confirm this has gone away....
Ah the joys of developing modules when d8 is still beta
@joachim thanks for looking into it.
Comment #10
martin107 commentedI closed this too soon .... early comments described how to expose the failing test through the browser.
Manual testing is fixed.... but the tests still fail and so this issue is still blocking progress on other issues.
Comment #11
joachim commentedOn a fresh install, I create a flag and then do this in Devel's exec php block:
This shows the problem -- the single bundle that Flagging entities have so far is called 'flagging'.
Then I do 'drush cr', and repeat.
*NOW* the list of bundles is correct.
So it looks like we're missing some sort of cache clear when the new flag is created.
Comment #12
joachim commentedComment #13
berdirYou need to extend Flag from ConfigEntityBundleBase, that should take care of this.
Comment #14
joachim commentedI've picked through the node type form and I don't see anything it does that we should be doing. The only likely candidate is
$this->entityManager->clearCachedFieldDefinitions();, but adding that to ours doesn't fix the problem.Comment #15
joachim commentedI suspect the problem is that we're not extending from https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Config!Entity!Con..., which NodeType does.
The code at https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Config!Entity!Con... looks like it might be doing stuff in this area, eg $entity_manager->onBundleCreate().
(Not that Drupal core code is documented as well as it used to be... :/)
Comment #16
martin107 commentedBerdir to the rescue - again....
Yeay Flag now picks up a postSave() method that at the appropriate moment clears the right cache...
Please understand I say this with a lot of love.... but flag testing is at a developmental stage... so the fact that the once failing test now passes
should not be enough to say that there are no unintended consequences of this improvement ...
To that end I have done some manual testing, swung the ole module through its paces ...
I can add flags/edit flags and add fields without seeing any problems.
Berdir++
Comment #17
joachim commentedHa, you beat me to it -- I was about to upload the exact same patch! :)
EDIT: which somehow I seem to have uploaded anyway!
Comment #19
martin107 commentedI hope you don't mind I a re-uploading my last patch - its got an extra use statement which will clear the errors
Comment #20
martin107 commentedComment #22
joachim commentedAh yes. I missed that! :)
Committed. Thanks for working on this!