/** * Method to get the field options. * * @return array The field option objects. */ protected function getOptions() { jimport('joomla.filesystem.folder'); $component = $this->element['component']; $customfields = array(); $options = array(); $files = JFolder::files(JPATH_LIBRARIES . '/compojoom/form/customfields'); foreach ($files as $file) { $customfields[] = basename($file, '.php'); } $componentPath = JPATH_ADMINISTRATOR . '/components/' . $component . '/models/fields/customfields'; $overridePath = JPATH_SITE . '/templates/' . CompojoomTemplateHelper::getFrontendTemplate() . '/html/' . $component . '/fields/customfields'; if (file_exists($componentPath)) { $files = JFolder::files($componentPath); foreach ($files as $file) { $customfields[] = basename($file, '.php'); } } if (file_exists($overridePath)) { $files = JFolder::files($overridePath); foreach ($files as $file) { $file = basename($file, '.php'); if (!in_array($file, $customfields)) { $customfields[] = $file; } } } foreach ($customfields as $customfield) { $options[] = Jhtml::_('select.option', $customfield, $customfield); } return $options; }
/** * Returns the translated label for a value * * @param object $field - the field config object * @param string $value - string * @param string $component - if we want to load overriden customfields provide the component where we should check * * @return mixed */ public static function render($field, $value, $component = null) { $class = 'CompojoomFormCustomfields' . ucfirst($field->type); if ($component) { JLoader::discover('CompojoomFormCustomfields', JPATH_ADMINISTRATOR . '/components/' . $component . '/models/fields/customfields'); JLoader::discover('CompojoomFormCustomfields', JPATH_SITE . '/templates/' . CompojoomTemplateHelper::getFrontendTemplate() . '/html/' . $component . '/fields/customfields'); } if (!isset(self::$customFields[$class])) { self::$customFields[$class] = new $class(); } return self::$customFields[$class]->render($field, $value); }