On a site I'm working on, when I updated the codebase from beta10 to beta11 it seems as if none of the existing fields are available to Views. Its only when I create a new field or delete and recreate one that it shows in Views as an option to add as a field or filter.

I haven't tested this out yet on a clean build but thought I'd report it here in case anyone else has noticed it and has a solution.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tanc’s picture

I've tracked down the issue to the field definitions for the fields created in beta10 not being stored in entity.definitions.bundle_field_map in key_value table. When fields are created in beta11 they run through the preSave() method and if isNew returns true it'll trigger $entity_manager->onFieldDefinitionCreate. onFieldDefinitionCreate will update the definition which in turn allows Views to see the fields again. So what we need is some way of triggering a rebuild of all the field definitions. Anyone got any ideas?

Berdir’s picture

Status: Active » Closed (won't fix)

Edit: Ignore me, I was confused.

tanc’s picture

This is the head2head project!

Berdir’s picture

Status: Closed (won't fix) » Active

I was confused :)

tanc’s picture

Status: Active » Needs review
FileSize
1.53 KB

Here is a patch which rebuilds the field map. This works nicely for my situation and allows all fields to be recognised by Views again. Thanks for the guidance Berdir.

Berdir’s picture

That means you also add the base fields to the map, that's not needed.

I'd suggest to just loop over FieldConfig::loadMultiple() and only add those.

As discussed in IRC, this relies on the entity storage not doing anything onFieldDefinitionCreate(), the alternative is to inline the code from the entity manager. Has the advantage that we would only require a single set() per entity type, and not one per field.

tanc’s picture

ok, here's another attempt, this time gathering the configs from FieldConfig::loadMultiple(). I'm not sure whether I need to include some code to initialise field map or should it be fine as this function will run as an update?

eiriksm’s picture

Status: Needs review » Reviewed & tested by the community

Just ran into the same issue. Patch and update function fixed it for me.

  • amateescu committed d2647ff on 8.x-1.x authored by tanc
    Issue #2496599 by tanc, Berdir: Fields only available in views when...
amateescu’s picture

Status: Reviewed & tested by the community » Fixed
FileSize
1.7 KB
1.38 KB

Cleaned up the patch a little and committed to 8.x-1.x. Thanks everyone!

Status: Fixed » Closed (fixed)

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