function testScaffoldSearchFields()
 {
     $autoCompleter = new GridFieldAddExistingAutocompleter($targetFragment = 'before', array('Test'));
     $gridFieldTest_Team = singleton('GridFieldTest_Team');
     $this->assertEquals($autoCompleter->scaffoldSearchFields('GridFieldTest_Team'), array('Name:PartialMatch', 'City:StartsWith', 'Cheerleaders.Name:StartsWith'));
     $this->assertEquals($autoCompleter->scaffoldSearchFields('GridFieldTest_Cheerleader'), array('Name:StartsWith'));
 }
 /**
  * Detect searchable fields and searchable relations
  * Only has_many relations may be searched.
  * Falls back to Title or Name if no earchableFields are defined.
  *
  * @param string $dataClass The class name to get fields for
  * 
  * @return array
  * 
  * @return array|null
  *
  * @author Sebastian Diel <sdiel@pixeltricks.de>
  * @since 15.04.2014
  */
 public function scaffoldSearchFields($dataClass)
 {
     $fields = parent::scaffoldSearchFields($dataClass);
     $has_many = Config::inst()->get($dataClass, 'has_many');
     $many_many = Config::inst()->get($dataClass, 'many_many');
     $belongs_many_many = Config::inst()->get($dataClass, 'belongs_many_many');
     foreach ($fields as $key => $value) {
         if (strpos($value, '.') !== false) {
             $parts = explode('.', $value, 2);
             $relationName = $parts[0];
             $searchField = $parts[1];
             if (is_array($has_many) && array_key_exists($relationName, $has_many)) {
                 $fields[$key] = $has_many[$relationName] . '.' . $searchField;
             } elseif (is_array($many_many) && array_key_exists($relationName, $many_many)) {
                 unset($fields[$key]);
             } elseif (is_array($belongs_many_many) && array_key_exists($relationName, $belongs_many_many)) {
                 unset($fields[$key]);
             }
         }
     }
     return $fields;
 }
 /**
  * Set core properties
  *
  * @since version 1.0.0
  *
  * @param string $targetFragment
  * @param object $searchFields
  *
  * @return void
  **/
 public function __construct($targetFragment = 'before', $searchFields = null)
 {
     $this->targetFragment = $targetFragment;
     $this->searchFields = (array) $searchFields;
     parent::__construct();
 }
 /**
  * Sets the number of items to limit to
  * @param {string} $targetFragment Fragment to place the component in
  * @param {array} $searchFields Which fields on the object in the list should be searched
  * @param {int} $limit Number of items to limit the gridfield's relationship to
  * @return {LRGridFieldAddExistingAutocompleter} Returns self
  */
 public function __construct($targetFragment = 'before', $searchFields = null, $itemLimit = null)
 {
     $this->_item_limit = $itemLimit;
     parent::__construct($targetFragment, $searchFields);
 }