Creating a new attribute type from "Select"

Permalink
So I'm trying to create a specialized drop-down attribute, which populates from an external data source. If possible, I'd prefer not to have to try to keep that as a list of choices INSIDE C5 because it's subject to external change.

I made a copy of the "Select" stuff in /models/attribute/types/customselect and changed the class names accordingly.


The problem I'm having is when it records the data from the select box.

I replaced the line in form.php, about line 98, which reads
$options = $this->controller->getOptions();

with

$options=new SelectAttrributeTypeOptionList();
      $db= Loader::db();
      $line=$db->getAll("select * from Attorney where 1=1 order by LastName, FirstName");
      $iii=0;
      foreach($line as $li) {
      $options->add(new SelectAttributeTypeOption($li["AttorneyID"],$li["LastName"].", ".$li["FirstName"],$iii));
      $iii++;
      }


Now, it works on one half of the coin: I get a select-like field, filled in with the names. The choices persist nicely.

The weird thing is, however, when it writes out the selection to the database.

When you load up the CollectionSearchIndexAttributes table, instead of the IDs you'd expect (which are things like "3", "4", "5"), you get text values, which I suspect are chosen from other dropdowns with the same ID.

When you reconstitute the data on a page, you can iterate through the attribute, and get the ID, to get the numbers... which is okay for presentation, but not search.

Is there a way to hijack the process before it converts the selected ids into text and stores them in CollectionSearchIndexAttributes? I'm not sure where to look-- I expect I'll have to subclass some aspect of Concrete5_Controller_AttributeType_Select

 
nobulart replied on at Permalink Reply
nobulart
Hi HakFoo

I'm trying to do the same thing. Did you find a solution? I too have managed to populate my custom attribute select list with external database calue, but I'm a bit stuck as to how to successfully store and retrieve the user's selected option.

Hope you came right! Could save me a bunch of time if you did.

Cheers.