Current we have failing test.

This is stalling development of 2 issue that I can see.

The same error are visible when I locally test without any patches applied.

#2454557: Fix AJAX link plugin id
#2446311: Flag::types and Flag::entity_type should be protected

Comments

martin107’s picture

Assigned: martin107 » Unassigned

Sorry getting interrupted.. will try and find time to come back to this.

martin107’s picture

Issue summary: View changes

So 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...

joachim’s picture

I get this error when I save the field settings:


Error message
Notice: Undefined index: flag_1 in Drupal\field_ui\Form\FieldEditForm->buildForm() (line 80 of core/modules/field_ui/src/Form/FieldEditForm.php).

Drupal\field_ui\Form\FieldEditForm->buildForm(Array, Object, Object)
call_user_func_array(Array, Array)
Drupal\Core\Form\FormBuilder->retrieveForm('field_ui_field_edit_form', Object)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\PageCache->pass(Object, 1, 1)
Drupal\Core\StackMiddleware\PageCache->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1)
Stack\StackedHttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)
joachim’s picture

That line is:

      '%bundle' => $bundles[$entity_type][$bundle]['label'],

and a debug() of $bundles shows that we have this:

    [flag] => Array
        (
            [flag] => Array
                (
                    [label] => Flag
                )

        )

    [flagging] => Array
        (
            [flagging] => Array
                (
                    [label] => Flagging
                )

        )

-- which is *completely* wrong. There should not be a bundle of 'flagging' called flagging. The bundles of the flagging entity are the flag names.

joachim’s picture

More problems...

The Flagging entity believes its bundle key is 'type':

 *  entity_keys = {
 *    "id" = "id",
 *    "bundle" = "type",
 *    "uuid" = "uuid"
 *  },

However, when flaggings are created, the 'type' field is set to a hardcoded string:

    $flagging = $this->entityManager->getStorage('flagging')->create([
      'type' => 'flag',
      'uid' => $account->id(),
      'fid' => $flag->id(),
      'entity_id' => $entity->id(),
      'entity_type' => $entity->getEntityTypeId(),
    ]);

And also in the config table, I see 'node.type.article', but 'flag.flag.flag_1'. That looks wrong.

joachim’s picture

The field appears to be correctly defined -- its config table ID is 'field.field.flagging.flag_1.field_foobar'.

joachim’s picture

Huh. 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 (!!!)

martin107’s picture

Status: Active » Closed (cannot reproduce)

I 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.

martin107’s picture

Status: Closed (cannot reproduce) » Active

I 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.

joachim’s picture

Title: Broken HEAD Drupal\flag\Tests\FlagFieldEntryTest » Flagging bundles are not correctly set up

On a fresh install, I create a flag and then do this in Devel's exec php block:

$bundles = entity_get_bundles();
dsm($bundles['flagging']);

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.

joachim’s picture

Title: Flagging bundles are not correctly set up » entity bundle caches are not correctly cleared when a flag is created
berdir’s picture

You need to extend Flag from ConfigEntityBundleBase, that should take care of this.

joachim’s picture

I'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.

joachim’s picture

I 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... :/)

martin107’s picture

Status: Active » Needs review
StatusFileSize
new822 bytes

Berdir 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++

joachim’s picture

StatusFileSize
new387 bytes

Ha, you beat me to it -- I was about to upload the exact same patch! :)

EDIT: which somehow I seem to have uploaded anyway!

Status: Needs review » Needs work

The last submitted patch, 17: 2455493-17.flag_.flagging-bundle-sync.patch, failed testing.

martin107’s picture

StatusFileSize
new822 bytes

I hope you don't mind I a re-uploading my last patch - its got an extra use statement which will clear the errors

martin107’s picture

Status: Needs work » Needs review

  • joachim committed 8f46673 on 8.x-4.x authored by martin107
    Issue #2455493 by martin107: Fixed entity bundle caches are not...
joachim’s picture

Status: Needs review » Fixed

Ah yes. I missed that! :)

Committed. Thanks for working on this!

Status: Fixed » Closed (fixed)

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