Problem/Motivation

The StyleEntityReferenceItem class appears unnecessary. It is almost a wholesale copy/paste from the core EntityReferenceItem class. This looks like a place we could refactor and remove a bunch of code from the style_entity module.

There are indeed a few niceties that come along with the custom field type.

1. "Style Entity reference" appears as an option in the "Select a field type" dropdown when adding a field to an entity.

Unfortunately, it also make a bunch of unwanted and probably invalid options appear like field_ui:style_entity_reference:taxonomy_term. I set this issue as a task but these weird fields probably make this more of a bug.

Luckily, "Styles" can easily appear in the list of Reference fields simply by adding common_reference_target = TRUE, to the annotation for the Styles entity type.

2. Having a dedicated field type for style entities makes the following logic very simple:

if ($field->getType() == 'style_entity_reference') {
   $style_field = $delta;
}

Instead we'd have to check if it's an entity_reference field and then load the storage to check if the target_type is styles. But that's not too bad.

Proposed resolution

1. Make an update to account for point #1 above
2. Make an update to account for point #2 above.
3. Remove StyleEntityReferenceItem
4. Remove StyleEntityReferenceFormatter
5. Remove schema related to #3 and #4
6. Remove style_entity_field_widget_info_alter
7. Add an update hook (ahh!)
8. Update config in test module

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

danflanagan8 created an issue. See original summary.

danflanagan8’s picture

Status: Active » Needs review

Turns out we can't remove the style_entity_reference field type yet because I get this error during the updates:

> In FieldStorageConfigStorage.php line 167:
>                                                                                                                                      
>   Unable to determine class for field type 'style_entity_reference' found in the 'field.storage.media.field_style' configuration 

So instead I'm just deprecating it and hiding it form the UI. We'll have to wait til later to remove it.

  • danflanagan8 committed 2ad52dc on 2.x
    Issue #3302083 by danflanagan8: Replace StyleEntityReferenceItem with...
danflanagan8’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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