protected function getOptions($forceReset = false)
{
$myFormKey = $this->form->getName() . '#$#' . (string) $this->element['model'];
if ($forceReset && isset(static::$loadedOptions[$myFormKey])) {
unset(static::$loadedOptions[$myFormKey]);
}
if (!isset(static::$loadedOptions[$myFormKey])) {
$options = array();
// Initialize some field attributes.
$key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
$value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
$valueReplace = StringHelper::toBool($this->element['parse_value']);
$translate = StringHelper::toBool($this->element['translate']);
$applyAccess = StringHelper::toBool($this->element['apply_access']);
$modelName = (string) $this->element['model'];
$nonePlaceholder = (string) $this->element['none'];
$with = $this->element['with'] ? (string) $this->element['with'] : null;
if (!is_null($with)) {
$with = trim($with);
$with = explode(',', $with);
$with = array_map('trim', $with);
}
if (!empty($nonePlaceholder)) {
$options[] = JHtml::_('select.option', null, JText::_($nonePlaceholder));
}
// Explode model name into component name and prefix
$componentName = $this->form->getContainer()->componentName;
$mName = $modelName;
if (strpos($modelName, '.') !== false) {
list($componentName, $mName) = explode('.', $mName, 2);
}
// Get the applicable container
$container = $this->form->getContainer();
if ($componentName != $container->componentName) {
$container = Container::getInstance($componentName);
}
/** @var DataModel $model */
$model = $container->factory->model($mName)->setIgnoreRequest(true)->savestate(false);
// Get the model object
if ($applyAccess) {
$model->applyAccessFiltering();
}
if (!is_null($with)) {
$model->with($with);
}
// Process state variables
/** @var \SimpleXMLElement $stateoption */
foreach ($this->element->children() as $stateoption) {
// Only add <state /> elements.
if ($stateoption->getName() != 'state') {
continue;
}
$stateKey = (string) $stateoption['key'];
$stateValue = (string) $stateoption;
$model->setState($stateKey, $stateValue);
}
// Set the query and get the result list.
$items = $model->get(true);
// Build the field options.
if (!empty($items)) {
foreach ($items as $item) {
if ($translate == true) {
$options[] = JHtml::_('select.option', $item->{$key}, JText::_($item->{$value}));
} else {
if ($valueReplace) {
$text = $this->parseFieldTags($value, $item);
} else {
$text = $item->{$value};
}
$options[] = JHtml::_('select.option', $item->{$key}, $text);
}
}
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
static::$loadedOptions[$myFormKey] = $options;
}
return static::$loadedOptions[$myFormKey];
}