1

Is there a way to create parent-child entities in Drupal 8? I'm trying to create a structure where the top entity is for County, and the next level entity is for departments, and next level would be staff. There will be different counties so the departments created at the second level entity will only be tied to the county it's created for, and same goes for staff which will only be associated to the the 2nd level entity(departments). So Let's say department 1 on County 1 will have different staff from department 2 of the sane county 1.

Also how will the path for this be programmed? Where in Drupal or what files should be created or modified so that it will structured like myowndrupalxx.xxx\module\county\1\department\2\staff\1 to display staff information for staff #1 of department 2 of county 1?

Lastly, can the database tables have a key for each table, so let's say for the Staff table being at the 3 level, it will have 3 keys, County, Department, and Staff, vs. the County table will have 1 key County. This way it does follow the parent-child or relational database structure.

I am not a very skilled programmer in Drupal so please provide your explanations in lay man terms as much as possible.

1
  • 1
    Read up on Taxonomy Terms to see it that will meet your need. You can create a hierarchy of terms, and assign them to entities. Commented Jan 6, 2018 at 15:54

1 Answer 1

0

What about using entity reference (included in D8) ? In your case, Each "department" has "county" and each "staff" has "department" : you may just add field to your department and staff content type (or taxonomy term depend on what you need to do with these).

Your may use pathauto to generate the URL you need for each content type :

county/{county_nid}

county/{county_nid}/department/{department_nid}

county/{county_nid}/department/{department_nid}/staff/{staff_nid}

This can be easylly used with views / content type display mode and could imho fit all your needs.

2
  • Hi, What I'm not sure is how to update the values for the fields for let's say the Staff through a front end when I use Drupal only as a backend. I guess I need to create this structure for a front end to be able to create values for such a structure in place that I will define in Drupal and not at the Front end. I hope this makes sense.
    – M Pabilona
    Commented Jan 7, 2018 at 16:50
  • If you are using drupal as a backend, you can use REST service to CRUD data. Commented Jan 8, 2018 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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