As the title states, removal of the available options PHP field, because storing PHP in the database is evil for so many reasons. Will provide a hook to still be able to add options programmatically.

CommentFileSizeAuthor
#1 remove_available-2443811-1.patch13 KBlegolasbo

Comments

legolasbo’s picture

Status: Active » Needs review
StatusFileSize
new13 KB

Attached patch removes code for 'available options php' and adds a hook to provide options via a custom module. I could use some help testing this to make sure I didn't miss anything.

  • legolasbo committed affbee6 on 7.x-3.x
    Issue #2443811 by legolasbo: Remove available options PHP
    
legolasbo’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mautumn’s picture

Thanks very much legolasbo for the hook. It works as expected. Here is some code which might help someone :-

/**
* Implements hook_select_or_other_available_options().
*
*/
function mymodulename_select_or_other_available_options($entity_type, $bundle, $field_name){

  $kv_options = array();
  // for course-deliverer->field_crs_id_or_email_address get key|value list of course deliverers for select_or_other
  if ($entity_type === 'node' && $bundle === 'course_deliverer' && $field_name === 'field_crs_id_or_email_address') {
    $result = db_query("SELECT node.nid AS nid, node.title AS title
      FROM {node} node
      WHERE (( (node.status = '1') AND (node.type IN  ('course_deliverer')) ))");

    // make sure some row/s has/have been found
    if ($result) {
      // add all found rows to the KV array
      foreach($result as $row) {
        // the nid with be the key and the node title will be the value
        $kv_options[] = $row->nid . '|' . $row->title;
      }
    }
  }
  return $kv_options;
}