I get the desired options from the following code, but I need to add an empty option as the first value of the returned array as '' => 'none',
then the rest of values.
function dropdown() {
return db_select('node', 'n')
->condition('n.type', 'abc')
->condition('n.status', 1)
->fields('n', array('nid', 'title'))
->orderBy('n.title', 'ASC')
->execute()
->fetchAllKeyed();
}
This, however, gives only values from the database.
You could prepend the entry before to return the data:
Possible output:
If there are no nodes available for your conditions, it will returns: