3

I have three content types, Events, Disciplines and Championships. An Event has entity references to Disciplines and Championships and Championship has an entity reference to Disciplines.

 ----- 1..n    1..n ------------
|Event|------------|Championship|
 -----              ------------
   |0..n               |0..n
   |                   |
   |                   |
   |1..n               |
 ---------- 1          |
|Discipline|-----------/
 ----------

When users are creating new Event nodes they initially select which Disciplines are involved from a list of checkboxes and then similarly the Championship(s) involved.

At the moment all Championships nodes appear, allowing users to potentially select Championships for Disciplines which are not part of the Event.

Is it possible to use the conditional fields module to create a dependency to display only Championships where the Championship's Discipline field matches the Discipline(s) selected when the dependency is triggered?

How would one fill the 'Set of values' in the conditional fields module?

For example when creating Event1, I select DisciplineA and DisciplineB. The list of Championships should only contain those which have DisciplineA or DisciplineB associations and not contain any Championships that do not have the correct associations

if event.disciplines were a list of selected disciplines I'd like something along these lines (with the dynamic aspects of conditional fields)

SELECT championships c WHERE c.discipline IN (event.disciplines)

edit

Dependent Fields seems to do the sort of thing i'd like but there's no D7 version...

edit 2

Changed the structure a little.

I suppose Discipline didn't need to be an entity in itself and have created a taxonomy vocabulary Discipline instead with terms for each discipline. Event and Championship now have term references to the same field_discipline.

Using the Reference field limit option module the Championship entity reference in Event has the 'Limit this field's options according to the matching field values' option selected and the matching field being discipline (field_discipline).

When creating an Event the list of Championships is empty but when I select the Discipline(s) the expected Championships do not appear.

No options are available for the current form values. Try selecting different values for the following fields: discipline.

edit 3...

Firebug suggested that the ajax wasn't actually firing for checkbox/radio button but was for select menu. Applied this patch and the section is now updating but still not finding any values. There are appropriate Championship nodes to find.

edit 4!

The Championship nodes didn't have the discipline taxonomies selected...

1

I got this sorted (eventually...)

Rather than having Discipline as a content type (since it was only really storing the name) I created a taxonomy vocabulary called Discipline and added all the relevant discipline names as terms.

Removed the entity references to Discipline in Event and Championship. Added a term reference (field_discipline) to Event and the same term reference to Championship.

Using the Reference Option Limit module (and patch; see question) in the entity reference in Event to Championship added the 'Limit this field's options according to matching field values' and selected the matching field field_discipline.

So now when creating an Event node the user is presented with a list of checkboxes to select the discipline(s) involved and when each is selected the appropriate championships are added to the list of available championships.

0

Another way i found to do this uses entity references, reference option limit and views modules.

  -----               ----
 |Event|-------------|Race|
  -----  1..*    1..* ----
   *|                  |*
    |                  |
  1 |                  |
 --------- 1           |
|Organiser|------------/
 ---------

An Event is made up of Races An Organiser can organise Event(s) and/or Races according to two Boolean fields Event? and Race? in the Organiser content type.

When creating, for example, an Event node we want only the possible options to be those Organiser nodes with Event? field set to 'true'.

Assuming the content types already defined, with Event having an entity reference to Orgainser, first create a new view...

In this case I called the view 'Event Organisers - Limit Options' and set it to show Content of type Organiser. Untick create Page then click Continue & edit.

With the blank Master view, click + Add and select 'Entity Reference'.

Add the field Event? to the FIELDS

In the Format Settings select the Event? field.

In the FILTER CRITERIA add Event? and set Operator to is one of and select true from the Options.

Then edit the Entity Reference field in the Event content type which links to Organiser type.

Entity Selection in Mode select 'Views:Filter by an entity reference view' then select the newly created view.

This is obviously applicable to any use case and seems a simple enough way to implement. I did pretty much exactly the same to limit available race organisers too.

Hope this helps someone, i spent quite a while scratching my head over this...

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.