I have a view of assignments, and want students to be able to post their work from that node. If they already have a work node, I want to display an edit link. Otherwise, I want to display an add link. In a previous version of this view, I used a Views PHP field that queried the DB for a work node matching the assignment, but I am rewriting the view because of a bug and I wanted to revisit this because it seemed a but ugly. Can anyone think of a better way?


2 Answers 2


I am assuming the following things for this answer

  1. There is a content type called assignments.

  2. There is a content type called workbook which has a reference to the assignments content type

  3. The view is of the assignment content type.

Now to achieve what you are looking for follow the below steps

  1. Add a relationship of the type "Entity Reference: Referenced Entity"

  2. Now add the field Content: Edit link. Choose the relationship we created in step one

  3. Set the "NO RESULTS BEHAVIOR" and add the link to add a workbook page like <a href="node/add/workbook">Add workbook</a>
  4. Add a CONTEXTUAL FILTER of the type "Content: Author uid" and provide default value and select "User ID from Logged in user" from the list.

That should do it.


I have had a similar situation and I did the following which is probably not the best thing to do - I will use your terms:

  • When an assignment node is created a work node for each student is created with the field field_submitted set to false

  • On the view, the field field_submitted is included but excluded from display

  • I have a php field with this code which displays edit or submit, both are actually sending to the same node but they will give the student some insight about what he should do next:

       echo l(t('edit')/*, ... */);
       echo l(t('submit')/*, ... */);

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.