I am working on this project, parking management system. I have the admin populating the parking slots available in the building. Then an anonymous user visits the site, puts their details and those of their car, and then in drop down selects a parking slot. The parking slots are an entity reference fetched from what the admin populated. How do I make the system dynamically populate this dropdown so that the user only sees the empty slots? Like after they book slot A, I want it to disappear so that the next person booking does not see it in the dropdown list of available slots. This is to avoid two or more people booking the same slot. The image below shows the drop down am talking about. enter image description here

1 Answer 1


I guess the Parking slot 1, Parking slot 2, etc. are nodes or fieldable entities. Most likely those nodes (or entities) have a boolean field which indicates if the parking slot is reserved already. For the sake of this example, I call it field_reserved.

In this case you need to implement in a custom module a hook_form_alter(). I am going to write a pseudo code.

function mymodule_form_alter($form, $form_state) {

  // Check if the form id is the id of your form.

  // Use entity query that selects the node ids  of the nodes that are reserved. 

  //Store the result in some array (let's say reserved_slots array).

  // With a foreach loop, check each select option id against the reserved_slots array of ids. 

  //If such option exists, unset it.

Hopefully this gives you some guidance. If you need a complete snippet, you will have to provide more data about your setup, like machine name of the fields, etc.

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.