/** * Get the field configuration * * @return array */ protected function getConfig() { // If no custom options were defined let's figure out which ones of the // defaults we shall use... $config = array('published' => 1, 'unpublished' => 1, 'archived' => 0, 'trash' => 0, 'all' => 0); if (isset($this->element['show_published'])) { $config['published'] = StringHelper::toBool($this->element['show_published']); } if (isset($this->element['show_unpublished'])) { $config['unpublished'] = StringHelper::toBool($this->element['show_unpublished']); } if (isset($this->element['show_archived'])) { $config['archived'] = StringHelper::toBool($this->element['show_archived']); } if (isset($this->element['show_trash'])) { $config['trash'] = StringHelper::toBool($this->element['show_trash']); } if (isset($this->element['show_all'])) { $config['all'] = StringHelper::toBool($this->element['show_all']); } return $config; }
/** * Method to get the field input markup. * * @param array $fieldOptions Options to be passed into the field * * @return string The field HTML */ public function getFieldContents(array $fieldOptions = array()) { $id = isset($fieldOptions['id']) ? 'id="' . $fieldOptions['id'] . '" ' : ''; $class = $this->class . (isset($fieldOptions['class']) ? ' ' . $fieldOptions['class'] : ''); $translate = StringHelper::toBool($this->element['translate']) ? true : false; $html = '<span ' . ($id ? $id : '') . 'class="' . $class . '">'; foreach ($this->value as $value) { $html .= '<span>'; if ($translate == true) { $html .= JText::_($value); } else { $html .= $value; } $html .= '</span>'; } $html .= '</span>'; return $html; }
/** * Method to get the field options. * * Ordering is disabled by default. You can enable ordering by setting the * 'order' element in your form field. The other order values are optional. * * - order What to order. Possible values: 'name' or 'value' (default = false) * - order_dir Order direction. Possible values: 'asc' = Ascending or 'desc' = Descending (default = 'asc') * - order_case_sensitive Order case sensitive. Possible values: 'true' or 'false' (default = false) * * @return array The field option objects. * * @since Ordering is available since FOF 2.1.b2. */ protected function getOptions() { // Ordering is disabled by default for backward compatibility $order = false; // Set default order direction $order_dir = 'asc'; // Set default value for case sensitive sorting $order_case_sensitive = false; if ($this->element['order'] && $this->element['order'] !== 'false') { $order = $this->element['order']; } if ($this->element['order_dir']) { $order_dir = $this->element['order_dir']; } if ($this->element['order_case_sensitive']) { // Override default setting when the form element value is 'true' if ($this->element['order_case_sensitive'] == 'true') { $order_case_sensitive = true; } } // Create a $sortOptions array in order to apply sorting $i = 0; $sortOptions = array(); foreach ($this->element->children() as $option) { $name = JText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)); $sortOptions[$i] = new \stdClass(); $sortOptions[$i]->option = $option; $sortOptions[$i]->value = $option['value']; $sortOptions[$i]->name = $name; $i++; } // Only order if it's set if ($order) { jimport('joomla.utilities.arrayhelper'); \JArrayHelper::sortObjects($sortOptions, $order, $order_dir == 'asc' ? 1 : -1, $order_case_sensitive, false); } // Initialise the options $options = array(); // Get the field $options foreach ($sortOptions as $sortOption) { /** @var \SimpleXMLElement $option */ $option = $sortOption->option; $name = $sortOption->name; // Only add <option /> elements. if ($option->getName() != 'option') { continue; } $tmp = JHtml::_('select.option', (string) $option['value'], $name, 'value', 'text', (string) $option['disabled'] == 'true'); // Set some option attributes. $tmp->class = (string) $option['class']; // Set some JavaScript option attributes. $tmp->onclick = (string) $option['onclick']; // Add the option object to the result set. $options[] = $tmp; } // Do we have a class and method source for our options? $source_file = empty($this->element['source_file']) ? '' : (string) $this->element['source_file']; $source_class = empty($this->element['source_class']) ? '' : (string) $this->element['source_class']; $source_method = empty($this->element['source_method']) ? '' : (string) $this->element['source_method']; $source_key = empty($this->element['source_key']) ? '*' : (string) $this->element['source_key']; $source_value = empty($this->element['source_value']) ? '*' : (string) $this->element['source_value']; $source_translate = is_null($this->element['source_translate']) ? 'true' : (string) $this->element['source_translate']; $source_translate = StringHelper::toBool($source_translate) ? true : false; $source_format = empty($this->element['source_format']) ? '' : (string) $this->element['source_format']; if ($source_class && $source_method) { // Maybe we have to load a file? if (!empty($source_file)) { $source_file = $this->form->getContainer()->template->parsePath($source_file, true); if ($this->form->getContainer()->filesystem->fileExists($source_file)) { include_once $source_file; } } // Make sure the class exists if (class_exists($source_class, true)) { // ...and so does the option if (in_array($source_method, get_class_methods($source_class))) { // Get the data from the class if ($source_format == 'optionsobject') { $options = array_merge($options, $source_class::$source_method()); } else { // Get the data from the class $source_data = $source_class::$source_method(); // Loop through the data and prime the $options array foreach ($source_data as $k => $v) { $key = empty($source_key) || $source_key == '*' ? $k : @$v[$source_key]; $value = empty($source_value) || $source_value == '*' ? $v : @$v[$source_value]; if ($source_translate) { $value = JText::_($value); } $options[] = JHtml::_('select.option', $key, $value, 'value', 'text'); } } } } } reset($options); return $options; }
/** * Method to get the field input markup. * * @param array $fieldOptions Options to be passed into the field * * @return string The field HTML */ public function getFieldContents(array $fieldOptions = array()) { $id = isset($fieldOptions['id']) ? 'id="' . $fieldOptions['id'] . '" ' : ''; $class = $this->class . (isset($fieldOptions['class']) ? ' ' . $fieldOptions['class'] : ''); $show_link = StringHelper::toBool((string) $this->element['show_link']); $empty_replacement = $this->element['empty_replacement'] ? (string) $this->element['empty_replacement'] : ''; if (!empty($empty_replacement) && empty($this->value)) { $this->value = JText::_($empty_replacement); } $value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'); $html = $value; if ($show_link) { if ($this->element['url']) { $link_url = $this->parseFieldTags((string) $this->element['url']); } else { $link_url = $value; } $html = '<a href="mailto:' . $link_url . '">' . $value . '</a>'; } return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' . $html . '</span>'; }
/** * Get the rendering of this field type for static display, e.g. in a single * item view (typically a "read" task). * * @since 2.0 * * @return string The field HTML */ public function getInput() { $this->label = ''; $allowedElement = array('button', 'a'); if (in_array($this->element['htmlelement'], $allowedElement)) { $type = $this->element['htmlelement']; } else { $type = 'button'; } $text = $this->element['text'] ? (string) $this->element['text'] : ''; $class = $this->class ? $this->class : ''; $icon = $this->element['icon'] ? '<span class="icon ' . (string) $this->element['icon'] . '"></span> ' : ''; if ($this->element['listItemTask']) { $this->onclick = "listItemTask('cb" . $this->item->getId() . "', '" . (string) $this->element['listItemTask'] . "')"; } $onclick = $this->onclick ? 'onclick="' . $this->onclick . '" ' : ''; $url = $this->element['url'] ? 'href="' . $this->parseFieldTags((string) $this->element['url']) . '" ' : ''; $title = $this->element['title'] ? 'title="' . JText::_((string) $this->element['title']) . '" ' : ''; $useValue = StringHelper::toBool((string) $this->element['use_value']); if (!$useValue) { $this->value = JText::_($text); } $html = '<' . $type . ' id="' . $this->id . '" class="btn ' . $class . '" ' . $onclick . $url . $title . '>'; $html .= $icon . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'); $html .= '</' . $type . '>'; return $html; }
/** * Render a toolbar element. * * @param string $type The element type. * @param mixed $value The element value. * @param array $attributes The element attributes. * * @return void * * @codeCoverageIgnore * @throws \InvalidArgumentException */ private function renderToolbarElement($type, $value = null, array $attributes = array()) { switch ($type) { case 'title': $icon = isset($attributes['icon']) ? $attributes['icon'] : 'generic.png'; if (isset($attributes['translate'])) { $value = JText::_($value); } JToolbarHelper::title($value, $icon); break; case 'divider': JToolbarHelper::divider(); break; case 'custom': $task = isset($attributes['task']) ? $attributes['task'] : ''; $icon = isset($attributes['icon']) ? $attributes['icon'] : ''; $iconOver = isset($attributes['icon_over']) ? $attributes['icon_over'] : ''; $alt = isset($attributes['alt']) ? $attributes['alt'] : ''; $listSelect = isset($attributes['list_select']) ? StringHelper::toBool($attributes['list_select']) : true; JToolbarHelper::custom($task, $icon, $iconOver, $alt, $listSelect); break; case 'preview': $url = isset($attributes['url']) ? $attributes['url'] : ''; $update_editors = isset($attributes['update_editors']) ? StringHelper::toBool($attributes['update_editors']) : false; JToolbarHelper::preview($url, $update_editors); break; case 'help': if (!isset($attributes['help'])) { throw new MissingAttribute('help', 'help'); } $ref = $attributes['help']; $com = isset($attributes['com']) ? StringHelper::toBool($attributes['com']) : false; $override = isset($attributes['override']) ? $attributes['override'] : null; $component = isset($attributes['component']) ? $attributes['component'] : null; JToolbarHelper::help($ref, $com, $override, $component); break; case 'back': $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_BACK'; $href = isset($attributes['href']) ? $attributes['href'] : 'javascript:history.back();'; JToolbarHelper::back($alt, $href); break; case 'media_manager': $directory = isset($attributes['directory']) ? $attributes['directory'] : ''; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UPLOAD'; JToolbarHelper::media_manager($directory, $alt); break; case 'assign': $task = isset($attributes['task']) ? $attributes['task'] : 'assign'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_ASSIGN'; JToolbarHelper::assign($task, $alt); break; case 'addNew': case 'new': $area = isset($attributes['acl']) ? $attributes['acl'] : 'create'; if ($this->checkACL($area)) { $task = isset($attributes['task']) ? $attributes['task'] : 'add'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_NEW'; $check = isset($attributes['check']) ? StringHelper::toBool($attributes['check']) : false; JToolbarHelper::addNew($task, $alt, $check); } break; case 'copy': $area = isset($attributes['acl']) ? $attributes['acl'] : 'create'; if ($this->checkACL($area)) { $task = isset($attributes['task']) ? $attributes['task'] : 'copy'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JLIB_HTML_BATCH_COPY'; $icon = isset($attributes['icon']) ? $attributes['icon'] : 'copy.png'; $iconOver = isset($attributes['iconOver']) ? $attributes['iconOver'] : 'copy_f2.png'; JToolBarHelper::custom($task, $icon, $iconOver, $alt, false); } break; case 'publish': $area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate'; if ($this->checkACL($area)) { $task = isset($attributes['task']) ? $attributes['task'] : 'publish'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_PUBLISH'; $check = isset($attributes['check']) ? StringHelper::toBool($attributes['check']) : false; JToolbarHelper::publish($task, $alt, $check); } break; case 'publishList': $area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate'; if ($this->checkACL($area)) { $task = isset($attributes['task']) ? $attributes['task'] : 'publish'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_PUBLISH'; JToolbarHelper::publishList($task, $alt); } break; case 'unpublish': $area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate'; if ($this->checkACL($area)) { $task = isset($attributes['task']) ? $attributes['task'] : 'unpublish'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UNPUBLISH'; $check = isset($attributes['check']) ? StringHelper::toBool($attributes['check']) : false; JToolbarHelper::unpublish($task, $alt, $check); } break; case 'unpublishList': $area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate'; if ($this->checkACL($area)) { $task = isset($attributes['task']) ? $attributes['task'] : 'unpublish'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UNPUBLISH'; JToolbarHelper::unpublishList($task, $alt); } break; case 'archiveList': $area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate'; if ($this->checkACL($area)) { $task = isset($attributes['task']) ? $attributes['task'] : 'archive'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_ARCHIVE'; JToolbarHelper::archiveList($task, $alt); } break; case 'unarchiveList': $area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate'; if ($this->checkACL($area)) { $task = isset($attributes['task']) ? $attributes['task'] : 'unarchive'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UNARCHIVE'; JToolbarHelper::unarchiveList($task, $alt); } break; case 'edit': case 'editList': $area = isset($attributes['acl']) ? $attributes['acl'] : 'edit'; if ($this->checkACL($area)) { $task = isset($attributes['task']) ? $attributes['task'] : 'edit'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_EDIT'; JToolbarHelper::editList($task, $alt); } break; case 'editHtml': $task = isset($attributes['task']) ? $attributes['task'] : 'edit_source'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_EDIT_HTML'; JToolbarHelper::editHtml($task, $alt); break; case 'editCss': $task = isset($attributes['task']) ? $attributes['task'] : 'edit_css'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_EDIT_CSS'; JToolbarHelper::editCss($task, $alt); break; case 'deleteList': case 'delete': $area = isset($attributes['acl']) ? $attributes['acl'] : 'delete'; if ($this->checkACL($area)) { $msg = isset($attributes['msg']) ? $attributes['msg'] : ''; $task = isset($attributes['task']) ? $attributes['task'] : 'remove'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_DELETE'; JToolbarHelper::deleteList($msg, $task, $alt); } break; case 'trash': $area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate'; if ($this->checkACL($area)) { $task = isset($attributes['task']) ? $attributes['task'] : 'trash'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_TRASH'; $check = isset($attributes['check']) ? StringHelper::toBool($attributes['check']) : true; JToolbarHelper::trash($task, $alt, $check); } break; case 'apply': $task = isset($attributes['task']) ? $attributes['task'] : 'apply'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_APPLY'; JToolbarHelper::apply($task, $alt); break; case 'save': $task = isset($attributes['task']) ? $attributes['task'] : 'save'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE'; JToolbarHelper::save($task, $alt); break; case 'savenew': $task = isset($attributes['task']) ? $attributes['task'] : 'savenew'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE_AND_NEW'; $icon = isset($attributes['icon']) ? $attributes['icon'] : 'save-new.png'; $iconOver = isset($attributes['iconOver']) ? $attributes['iconOver'] : 'save-new_f2.png'; JToolBarHelper::custom($task, $icon, $iconOver, $alt, false); break; case 'save2new': $task = isset($attributes['task']) ? $attributes['task'] : 'save2new'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE_AND_NEW'; JToolbarHelper::save2new($task, $alt); break; case 'save2copy': $task = isset($attributes['task']) ? $attributes['task'] : 'save2copy'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE_AS_COPY'; JToolbarHelper::save2copy($task, $alt); break; case 'checkin': $task = isset($attributes['task']) ? $attributes['task'] : 'checkin'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_CHECKIN'; $check = isset($attributes['check']) ? StringHelper::toBool($attributes['check']) : true; JToolbarHelper::checkin($task, $alt, $check); break; case 'cancel': $task = isset($attributes['task']) ? $attributes['task'] : 'cancel'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_CANCEL'; JToolbarHelper::cancel($task, $alt); break; case 'preferences': if (!isset($attributes['component'])) { throw new MissingAttribute('component', 'preferences'); } $component = $attributes['component']; $height = isset($attributes['height']) ? $attributes['height'] : '550'; $width = isset($attributes['width']) ? $attributes['width'] : '875'; $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JToolbar_Options'; $path = isset($attributes['path']) ? $attributes['path'] : ''; JToolbarHelper::preferences($component, $height, $width, $alt, $path); break; default: throw new UnknownButtonType($type); } }
/** * Method to get the field options. * * @param bool $forceReset * * @return array The field option objects. */ 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]; }