0

I need a bit of help with entity references. I have Customer Profiles entity and Credit Card entity. I'd like to be able to create "credit cards" and attach them to customer profiles so that if I click hte customer profile, I'd see any credit cards attached to them. I'm not sure how to do this. I've created the credit card content type, added a reference field to it that references the customer, but I'm not sure how to display the filtered credit card entries on the customer profile. I've tried adding an entity reference field to the customer profile back to the credit cards but don't know how to filter the results.

My brain hurts a bit at this point.

1

One way to do it is with Views and a module called Eva (Entity Views Attachment). Eva allows a view to be attached to a host entity, and understands how to filter the view based using the host entity's id to display only related information.

Since you already have the entity reference field on the credit cart type, the steps would look like this:

  1. Install Eva and Views as needed

  2. Create a View for the credit card content type

  3. In the view, add an "EVA" display

  4. Configure the view to be attached to the customer (under Entity content settings)

  5. Add a Contextual filter using the field that links back to Customer. This will filter credit cards using the customer profile entity

  • Thank you. This is close to what I need except that I have to be able to see it on the profile/edit screen. EVA seems to only work on the profile display screen so it looks like I have to be able to add the display as a field. I don't know if EVA is able to do this. – Ash Jan 9 '14 at 19:40
  • Eva would just be for display, not editing. You could perhaps move the entity link to the customer, and use an entity reference field with unlimited values? I'm not sure how many fields from credit card entities you need to display, but another possibility might be the inline entity form module: drupal.org/project/inline_entity_form. I have not used this module for anything custom, only with Drupal Commerce, so I can't speak from experience. – Dave Bruns Jan 9 '14 at 21:31
  • @Ash if you need to edit the related entity you could completely change the approach and use a field collection ( drupal.org/project/field_collection ). This module allows to create a fieldable field and it could be a good solution for you usecase. What do you think about this idea? – FiNeX Jan 9 '14 at 21:57
  • @FiNex I actually started by using field_collections but I'm need to be able to pull up credit cards on other parts of the site so I needed to make sure it was reference-able. I don't think field_collections are reference-able so making them an entity was the best move in the long run. – Ash Jan 11 '14 at 0:40
0

I managed to do this with entity reference - views. I created a view with an entity reference display that displays the credit card fields. I then added a contextual filter based on the customer profile ID.

I added an entity reference field to the customer profile pointing to this view and used a token to grab the customer profile ID to filter the view. I had to patch entity reference to allow for token use but it works.

Hope this helps someone else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.