/**
* Method to attach a Form object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see FormField::setup()
* @since 3.2
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$return = parent::setup($element, $value, $group);
if ($return) {
// Check if its using the old way
$this->query = (string) $this->element['query'];
if (empty($this->query)) {
// Get the query from the form
$query = array();
$defaults = array();
$sql_select = (string) $this->element['sql_select'];
$sql_from = (string) $this->element['sql_from'];
if ($sql_select && $sql_from) {
$query['select'] = $sql_select;
$query['from'] = $sql_from;
$query['join'] = (string) $this->element['sql_join'];
$query['where'] = (string) $this->element['sql_where'];
$query['group'] = (string) $this->element['sql_group'];
$query['order'] = (string) $this->element['sql_order'];
// Get the filters
$filters = isset($this->element['sql_filter']) ? explode(',', $this->element['sql_filter']) : '';
// Get the default value for query if empty
if (\is_array($filters)) {
foreach ($filters as $filter) {
$name = "sql_default_{$filter}";
$attrib = (string) $this->element[$name];
if (!empty($attrib)) {
$defaults[$filter] = $attrib;
}
}
}
// Process the query
$this->query = $this->processQuery($query, $filters, $defaults);
}
}
$this->keyField = (string) $this->element['key_field'] ?: 'value';
$this->valueField = (string) $this->element['value_field'] ?: (string) $this->element['name'];
$this->translate = (string) $this->element['translate'] ?: false;
$this->header = (string) $this->element['header'] ?: false;
}
return $return;
}