本文整理汇总了PHP中JForm::setField方法的典型用法代码示例。如果您正苦于以下问题:PHP JForm::setField方法的具体用法?PHP JForm::setField怎么用?PHP JForm::setField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JForm
的用法示例。
在下文中一共展示了JForm::setField方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display
/**
* Display the view
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->assoc = $this->get('Assoc');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
// Preprocess the list of items to find ordering divisions.
foreach ($this->items as &$item) {
$this->ordering[$item->parent_id][] = $item->id;
}
// Levels filter - Used in Hathor.
$this->f_levels = array(JHtml::_('select.option', '1', JText::_('J1')), JHtml::_('select.option', '2', JText::_('J2')), JHtml::_('select.option', '3', JText::_('J3')), JHtml::_('select.option', '4', JText::_('J4')), JHtml::_('select.option', '5', JText::_('J5')), JHtml::_('select.option', '6', JText::_('J6')), JHtml::_('select.option', '7', JText::_('J7')), JHtml::_('select.option', '8', JText::_('J8')), JHtml::_('select.option', '9', JText::_('J9')), JHtml::_('select.option', '10', JText::_('J10')));
// We don't need toolbar in the modal window.
if ($this->getLayout() !== 'modal') {
$this->addToolbar();
$this->sidebar = JHtmlSidebar::render();
} else {
// In article associations modal we need to remove language filter if forcing a language.
if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'CMD')) {
// If the language is forced we can't allow to select the language, so transform the language selector filter into an hidden field.
$languageXml = new SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />');
$this->filterForm->setField($languageXml, 'filter', true);
// Also, unset the active language filter so the search tools is not open by default with this filter.
unset($this->activeFilters['language']);
}
}
return parent::display($tpl);
}
示例2: display
/**
* Display the view.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
if ($this->getLayout() !== 'modal') {
ContactHelper::addSubmenu('contacts');
}
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
// Preprocess the list of items to find ordering divisions.
// TODO: Complete the ordering stuff with nested sets
foreach ($this->items as &$item) {
$item->order_up = true;
$item->order_dn = true;
}
// We don't need toolbar in the modal window.
if ($this->getLayout() !== 'modal') {
$this->addToolbar();
$this->sidebar = JHtmlSidebar::render();
} else {
// In article associations modal we need to remove language filter if forcing a language.
// We also need to change the category filter to show show categories with All or the forced language.
if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'CMD')) {
// If the language is forced we can't allow to select the language, so transform the language selector filter into an hidden field.
$languageXml = new SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />');
$this->filterForm->setField($languageXml, 'filter', true);
// Also, unset the active language filter so the search tools is not open by default with this filter.
unset($this->activeFilters['language']);
// One last changes needed is to change the category filter to just show categories with All language or with the forced language.
$this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter');
}
}
return parent::display($tpl);
}
示例3: display
/**
* Display the view
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
if ($this->getLayout() !== 'modal') {
ContentHelper::addSubmenu('articles');
}
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->authors = $this->get('Authors');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
$this->vote = JPluginHelper::isEnabled('content', 'vote');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
// Levels filter - Used in Hathor.
$this->f_levels = array(JHtml::_('select.option', '1', JText::_('J1')), JHtml::_('select.option', '2', JText::_('J2')), JHtml::_('select.option', '3', JText::_('J3')), JHtml::_('select.option', '4', JText::_('J4')), JHtml::_('select.option', '5', JText::_('J5')), JHtml::_('select.option', '6', JText::_('J6')), JHtml::_('select.option', '7', JText::_('J7')), JHtml::_('select.option', '8', JText::_('J8')), JHtml::_('select.option', '9', JText::_('J9')), JHtml::_('select.option', '10', JText::_('J10')));
// We don't need toolbar in the modal window.
if ($this->getLayout() !== 'modal') {
$this->addToolbar();
$this->sidebar = JHtmlSidebar::render();
} else {
// In article associations modal we need to remove language filter if forcing a language.
// We also need to change the category filter to show show categories with All or the forced language.
if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'CMD')) {
// If the language is forced we can't allow to select the language, so transform the language selector filter into an hidden field.
$languageXml = new SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />');
$this->filterForm->setField($languageXml, 'filter', true);
// Also, unset the active language filter so the search tools is not open by default with this filter.
unset($this->activeFilters['language']);
// One last changes needed is to change the category filter to just show categories with All language or with the forced language.
$this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter');
}
}
return parent::display($tpl);
}
示例4: preprocessForm
/**
* @param object $form A form object.
* @param mixed $data The data expected for the form.
*
* @return void
* @since 1.1.0
* @throws Exception if there is an error in the form event.
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
$contentTypeID = $this->getState($this->getName() . '.content_type_id', 0);
if ($contentTypeID) {
$isNew = !(bool) $this->getState($this->getName() . '.id', 0);
$fieldsForm = new KextensionsForm($form->getName());
$fieldsData = FieldsandfiltersFieldsHelper::getFieldsByTypeIDColumnFieldType($contentTypeID);
$fieldsForm->setPath('filters');
$fieldsetXML = new SimpleXMLElement('<fieldset />');
$fieldsetXML->addAttribute('name', 'fieldsandfilters');
JPluginHelper::importPlugin('fieldsandfilterstypes');
// Trigger the onFieldsandfiltersPrepareFormField event.
JFactory::getApplication()->triggerEvent('onFieldsandfiltersPrepareFormField', array($fieldsForm, $fieldsData, $isNew));
if ($fieldsFormXML = $fieldsForm->getFormFields()) {
// Load the XML Helper
KextensionsXML::setFields($fieldsetXML, $fieldsFormXML);
$form->setField($fieldsetXML, 'fields');
if ($default = $fieldsForm->getData()) {
$form->bind($default);
}
}
}
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
示例5: onFieldsandfiltersPrepareForm
/**
* @param JForm $form The form to be altered.
* @param array $data The associated data for the form.
*
* @return boolean
* @since 1.0.0
*/
public function onFieldsandfiltersPrepareForm(JForm $form, $data)
{
$context = $form->getName();
if (!($context == $this->_context || $context == 'com_fieldsandfilters.elements.filter')) {
return true;
}
$app = JFactory::getApplication();
if ($context == 'com_fieldsandfilters.elements.filter') {
$form->addFieldPath(JPATH_ADMINISTRATOR . '/components/com_categories/models/fields');
$addform = new SimpleXMLElement('<form />');
$fields = $addform->addChild('fields');
$fields->addAttribute('name', 'filter');
$field = $fields->addChild('field');
$field->addAttribute('name', 'item_category');
$field->addAttribute('type', 'category');
$field->addAttribute('label', 'JOPTION_FILTER_CATEGORY');
$field->addAttribute('description', 'JOPTION_FILTER_CATEGORY_DESC');
$field->addAttribute('extension', 'com_content');
$field->addAttribute('onchange', 'this.form.submit();');
KextensionsXML::addOptionsNode($field, array('JOPTION_SELECT_CATEGORY' => ''));
$form->load($addform, false);
} elseif ($context == $this->_context) {
if ($app->isSite() && !$this->params->get('frontend_edit', false) || !($extension = FieldsandfiltersFactory::getExtensions()->getExtensionsByName($this->_name)->get($this->_name))) {
return true;
}
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fieldsandfilters/models', 'FieldsandfiltersModel');
if (!($elementModel = JModelLegacy::getInstance('element', 'FieldsandfiltersModel', array('ignore_request' => true, 'table_path' => JPATH_ADMINISTRATOR . '/components/com_fieldsandfilters/tables')))) {
return true;
}
// Load Extension Language
KextensionsLanguage::load('com_fieldsandfilters', JPATH_ADMINISTRATOR);
$fieldsForm = new KextensionsForm($this->_context . '.' . $this->_name);
$fieldsData = FieldsandfiltersFieldsHelper::getFieldsByTypeIDColumnFieldType($extension->content_type_id);
$formPath = $app->isAdmin() ? 'attribs.fieldsandfilters' : 'fieldsandfilters';
$fieldsForm->setPath($formPath);
$fieldsetXML = new SimpleXMLElement('<fieldset />');
$fieldsetXML->addAttribute('name', 'fieldsandfilters');
$fieldsetXML->addAttribute('label', 'COM_FIELDSANDFILTERS');
// $fieldsetXML->addAttribute( 'description', 'COM_FIELDSANDFILTERS_FIELDSET_DESC' );
$fielsXML = $fieldsetXML->addChild('fields');
$fielsXML->addAttribute('name', 'fieldsandfilters');
$fieldXML = $fielsXML->addChild('field');
$fieldXML->addAttribute('name', '_fieldsandfilters');
$fieldXML->addAttribute('type', 'hidden');
$fieldXML->addAttribute('fieldset', 'fieldsandfilters');
if (!empty($data)) {
$data = (object) $data;
$elementModel->setState($elementModel->getName() . '.item_id', $data->id);
$elementModel->setState($elementModel->getName() . '.content_type_id', $extension->content_type_id);
$elementItem = $elementModel->getItem();
}
$isNew = empty($elementItem->id);
JPluginHelper::importPlugin('fieldsandfilterstypes');
// Trigger the onFieldsandfiltersPrepareFormField event.
$app->triggerEvent('onFieldsandfiltersPrepareFormField', array($fieldsForm, $fieldsData, $isNew));
if ($fieldsFormXML = $fieldsForm->getFormFields()) {
// Load the XML Helper
KextensionsXML::setFields($fielsXML, $fieldsFormXML);
$form->setField($fieldsetXML, $app->isAdmin() ? 'attribs' : null);
// For joomla 2.5 && Key Reference
if (!FieldsandfiltersFactory::isVersion()) {
$fieldsetXML = new SimpleXMLElement('<fieldset />');
$fieldsetXML->addAttribute('name', 'key_reference');
$fieldsetXML->addAttribute('label', 'Key Reference');
$form->setField($fieldsetXML, 'attribs');
}
if ($default = $fieldsForm->getData()) {
$form->bind($default);
}
if (!$isNew) {
$data = new JRegistry();
$data->set($formPath, $elementItem->get('fields', new JObject()));
$form->bind($data);
}
}
return true;
}
}
示例6: setField
/**
* Attach element into the form.
*
* @param JForm $form Form where attach the field
* @param array $data Data
* @param string $group Group of the field
* @param bool $replace Replace the field
*
* @return void
*
* @throws RuntimeException
*/
public function setField(JForm $form, array $data, $group = null, $replace = true)
{
if (!isset($data['name'], $data['label'])) {
throw new RuntimeException("Internal error: Data field requires mandatory 'name' and 'label' attributes.");
}
$element = new SimpleXMLElement('<field type="' . $this->fieldType . '" />');
foreach ($this->fieldProperties as $property) {
if (!isset($data[$property])) {
continue;
}
$element->addAttribute($property, $data[$property]);
}
$form->setField($element, $group, $replace);
}