Problem/Motivation

There are many modules that provide Field Formatter and Field Widget plugins for core Entity Reference fields, but they don't support Primary Entity Reference fields because they explicitly specify the "entity_reference" field type ID.

Steps to reproduce

Proposed resolution

Implement alter hooks to insert ourselves.

This is the approach taken by the Group module, which we could easily adapt:

/**
 * Implements hook_field_formatter_info_alter().
 */
function primary_entity_reference_field_formatter_info_alter(array &$info) {
  // Anything that supports entity reference fields should also work for ours.
  foreach ($info as $key => $formatter_info) {
    if (in_array('entity_reference', $formatter_info['field_types'], TRUE)) {
      $info[$key]['field_types'][] = 'primary_entity_reference';
    }
  }
}

Remaining tasks

User interface changes

API changes

Data model changes

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

jdleonard created an issue. See original summary.

bluegeek9’s picture

Issue summary: View changes

Field Widgets can mishandle the primary part of the field. Limiting it Field Formatters is a safer change.

  • bluegeek9 committed 60308043 on 1.0.x
    feat: #3559176 Support for Field Formatters and Field Widgets defined...
bluegeek9’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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