Display suite has a handy field formatter for outputting terms in a single field comma separated (space, dash and slash alos available) as a single string. The labels can be either linked or not linked.

There is also exposed a drupal_alter to allow developers to add additional separators.

I have basically implemented this into the entityreference module which I will make available as a patch. I would love to see it accepted.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nlisgo’s picture

Status: Active » Needs review
FileSize
3.29 KB

Here is the patch. Please review.

nlisgo’s picture

Looking at the code more closely I recognise that the limit feature (introduced by display suite) is not working the patch in #1. This is an error I brought across from the ds taxonomy term separator formatter code. This latest patch addresses that.

StevenWill’s picture

This is a much needed patch. For the most part the patch works, but the display is still wrapping each entity reference in Divs and causing them to not be on the same line. The display suite taxonomy term wraps all terms in one div.

brunodbo’s picture

Attached patch addresses the issue of each entity reference being wrapped in a div, by adding all field items in the first result item. This also gets rid of some unwanted spaces between items.

I also added an option to separate the last item with an ampersand, especially useful when separating items with a comma.

brunodbo’s picture

Title: A request for an additional field formatter which outputs a string of entity labels separated by a chosen delimited » Add field formatter which outputs a string of entity labels separated by a chosen delimiter

Updating title.

brunodbo’s picture

Just found https://www.drupal.org/project/textformatter, which supports Entity reference.

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 4 year old patch in #4 to entityreference.module does not apply to the latest 7.x-1.x-dev and if still relevant needs a reroll.

Checking patch entityreference.module...
error: while searching for:
        'links' => TRUE,
      ),
    ),
  );
}

error: patch failed: entityreference.module:1098
error: entityreference.module: patch does not apply
rpayanm’s picture

Status: Needs work » Needs review
FileSize
3.82 KB
rpayanm’s picture

Issue tags: -Needs reroll