本文整理汇总了PHP中JForm::getFieldAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP JForm::getFieldAttribute方法的具体用法?PHP JForm::getFieldAttribute怎么用?PHP JForm::getFieldAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JForm
的用法示例。
在下文中一共展示了JForm::getFieldAttribute方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preprocessForm
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
$app = JFactory::getApplication();
$params = JComponentHelper::getParams('com_djcatalog2');
$user = JFactory::getUser();
$switchable_fields = array('contact_phone', 'contact_street', 'contact_city', 'contact_zip', 'contact_country', 'contact_company_name', 'contact_email_copy');
foreach ($switchable_fields as $field_name) {
if ($params->get($field_name . '_field', '0') == '0') {
$form->removeField($field_name);
} else {
if ($params->get($field_name . '_field', '0') == '2') {
$form->setFieldAttribute($field_name, 'required', 'required');
$form->setFieldAttribute($field_name, 'class', $form->getFieldAttribute($field_name, 'class') . ' required');
}
}
}
$plugin = JFactory::getApplication()->getParams()->get('contact_captcha', JFactory::getConfig()->get('captcha'));
if ($user->id > 0 || ($plugin === 0 || $plugin === '0' || $plugin === '' || $plugin === null)) {
$form->removeField('captcha');
} else {
$form->setFieldAttribute('captcha', 'plugin', $plugin, 'captcha');
}
}
示例2: 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')
{
$data = $data instanceof JRegistry ? $data : new JRegistry($data);
$fieldType = $data->get('type', $this->getState($this->getName() . '.type'));
$typeMode = $data->get('type_mode', FieldsandfiltersModes::getModeName($data->get('mode', $this->getState($this->getName() . '.mode')), FieldsandfiltersModes::MODE_NAME_TYPE));
try {
if ($fieldType && $typeMode && ($type = FieldsandfiltersFactory::getTypes()->getTypes(true)->get($fieldType))) {
$path = $type->forms->get($typeMode, new JObject())->get('path');
$form::addFormPath($path);
if (!$form->loadFile($typeMode, true, '/metadata/form/*')) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
if ($layoutType = $data->get('params.type.' . $typeMode . '_layout', $this->getState($this->getName() . '.layoutType'))) {
$paths = array(JPath::clean(JPATH_PLUGINS . '/' . $type->type . '/' . $type->name . '/tmpl/' . $typeMode));
if (strpos($layoutType, ':') > 0 && strpos($layoutType, '_:') !== 0) {
list($template, $layoutType) = explode(':', $layoutType);
$paths[] = JPATH::clean(JPATH_SITE . '/templates/' . $template . '/html/plg_' . $type->type . '_' . $type->name . '/' . $typeMode);
}
$path = JPath::find($paths, $layoutType . '.xml');
if (is_file($path)) {
if (!$form->loadFile($path, true, '/form/*')) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
}
}
// load plugin language
KextensionsLanguage::load('plg_' . $type->type . '_' . $type->name, JPATH_ADMINISTRATOR);
}
$contentTypeId = $data->get('content_type_id', $this->getState($this->getName() . '.content_type_id'));
$extensionForm = $data->get('extension_form', 'extension');
// get extension type objet by type id or plugin type
if ($contentTypeId && ($extension = FieldsandfiltersFactory::getExtensions()->getExtensionsByTypeID($contentTypeId, true, true)->get($contentTypeId))) {
$path = $extension->forms->get($extensionForm, new JObject())->get('path');
$form::addFormPath($path);
if (!$form->loadFile($extensionForm, true, '/metadata/form/*')) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
// load plugin language
KextensionsLanguage::load('plg_' . $extension->type . '_' . $extension->name, JPATH_ADMINISTRATOR);
}
} catch (Exception $e) {
$this->setError($e->getMessage());
return;
}
// overwrite the mode default of the plugin type mode
$form->setFieldAttribute('mode', 'default', FieldsandfiltersModes::getMode($form->getFieldAttribute('mode', 'value', 'field.text', 'properties')));
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
示例3: display
/**
* Display the view
*/
public function display($tpl = null)
{
JHtml::_('behavior.framework', true);
JHtml::_('behavior.keepalive');
$this->container = RokCommon_Service::getContainer();
$this->form = $this->get('Form');
$this->item = $this->get('Item');
$this->state = $this->get('State');
$this->articles = $this->getModel()->getArticles($this->item->id, $this->item->params);
$this->layout = isset($this->item->params['layout']) ? $this->item->params['layout'] : $this->form->getFieldAttribute('layout', 'default', 'text', 'params');
$this->provider = isset($this->item->params['provider']) ? $this->item->params['provider'] : $this->form->getFieldAttribute('provider', 'default', 'text', 'params');
if (!isset($this->container[sprintf('roksprocket.layouts.%s', $this->layout)])) {
JError::raiseWarning(500, rc__(ROKSPROCKET_UNABLE_TO_FIND_LAYOUT_ERROR, $this->layout));
$app = JFactory::getApplication();
$app->redirect(JRoute::_(sprintf('index.php?option=%s&view=modules', RokSprocket_Helper::getRedirectionOption()), false));
return false;
}
$this->perItemForm = $this->getModel()->getPerItemsForm($this->layout);
/** @var $i18n RokCommon_I18N */
/** @var $i18n RokCommon_I18N */
$i18n = $this->container->i18n;
foreach ($this->container['roksprocket.layouts'] as $layout_type => $layoutinfo) {
$layout_lang_paths = $this->container[sprintf('roksprocket.layouts.%s.paths', $layout_type)];
foreach ($layout_lang_paths as $lang_path) {
@$i18n->loadLanguageFiles('roksprocket_layout_' . $layout_type, $lang_path);
}
}
$load_more_total = count($this->articles);
$module_params = new RokCommon_Registry($this->item->params);
$limit = 10;
if ($load_more_total > $limit) {
$this->articles = $this->articles->trim($limit);
$load_more = 'true';
} else {
$load_more = 'false';
}
$load_more_script = sprintf('RokSprocket.Paging = {more: %s, page: 1, next_page: 2, amount: %d};', $load_more, $load_more_total);
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
// Read cookie for showing/hide per-article items
if (!isset($_COOKIE['roksprocket-showitems'])) {
$showitems_cookie = 1;
setcookie("roksprocket-showitems", $showitems_cookie, time() + 60 * 60 * 24 * 365, '/');
} else {
$showitems_cookie = $_COOKIE['roksprocket-showitems'];
}
$this->showitems = (bool) $showitems_cookie;
$siteURL = JURI::root(true);
$adminURL = JURI::base(true);
$this->addToolbar();
$this->compileLess();
$this->compileJS();
RokCommon_Header::addInlineScript("RokSprocket.params = 'jform_params';RokSprocket.SiteURL = '" . $siteURL . "'; RokSprocket.AdminURL = '" . $adminURL . "'; RokSprocket.URL = RokSprocket.AdminURL + '/index.php?option=" . JFactory::getApplication()->input->getString('option') . "&task=ajax&format=raw';" . $load_more_script);
RokCommon_Header::addStyle($siteURL . '/components/com_roksprocket/fields/filters/css/datepicker.css');
$template_path_param = sprintf('roksprocket.providers.registered.%s.templatepath', strtolower($this->provider));
if ($this->container->hasParameter($template_path_param)) {
RokCommon_Composite::addPackagePath('roksprocket', $this->container->getParameter($template_path_param), 30);
}
parent::display($tpl);
}
示例4: hideFormField
/**
*
* hide some form field
* @param $form
*/
public static function hideFormField(JForm $form, $field, $group = "")
{
$class = $form->getFieldAttribute($field, "class", "", $group);
if (!empty($class)) {
$class .= " hidden";
} else {
$class == "hidden";
}
$form->setFieldAttribute($field, "hidden", "true", $group);
$form->setFieldAttribute($field, "class", $class, $group);
}
示例5: preprocessForm
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
if (!$form instanceof JForm) {
$this->setError('JERROR_NOT_A_FORM');
return false;
}
$app = JFactory::getApplication();
$params = JComponentHelper::getParams('com_djcatalog2');
$user = JFactory::getUser();
$plugin = JFactory::getApplication()->getParams()->get('cart_order_captcha', JFactory::getConfig()->get('captcha'));
if ($user->guest == false || ($plugin === 0 || $plugin === '0' || $plugin === '' || $plugin === null)) {
$form->removeField('captcha', 'captcha');
} else {
$form->setFieldAttribute('captcha', 'plugin', $plugin, 'captcha');
}
$form->removeField('client_type', 'djcatalog2profile');
$form->removeField('customer_group_id', 'djcatalog2profile');
$fields = array('company', 'position', 'address', 'city', 'postcode', 'country_id', 'vat_id', 'phone', 'fax', 'www', 'customer_note');
$group = 'djcatalog2profile';
foreach ($fields as $field) {
// in case config is broken - using defaults from XML file
if ($params->get('cart_orderfield_' . $field, false) === false) {
continue;
}
if ($params->get('cart_orderfield_' . $field, '0') == '0') {
$form->removeField($field, $group);
} else {
if ($params->get('cart_orderfield_' . $field, '0') == '2') {
$form->setFieldAttribute($field, 'required', 'required', $group);
$form->setFieldAttribute($field, 'class', $form->getFieldAttribute($field, 'class') . ' required', $group);
} else {
$form->setFieldAttribute($field, 'required', false, $group);
$class = $form->getFieldAttribute($field, 'class', '', $group);
$class = str_replace('required', '', $class);
$form->setFieldAttribute($field, 'class', $class, $group);
}
}
}
}
示例6: onContentPrepareForm
/**
* adds additional fields to the user editing form
*
* @param JForm $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
* @since 2.5.20
*/
public function onContentPrepareForm($form, $data)
{
$app = JFactory::getApplication();
$version = new JVersion();
if (!$version->isCompatible('3.4')) {
return true;
}
if (!$form instanceof JForm) {
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
$params = JComponentHelper::getParams('com_jce');
if ((bool) $params->get('replace_media_manager', 1) === false) {
return;
}
// get form name.
$name = $form->getName();
if (!$version->isCompatible('3.6')) {
$valid = array('com_content.article', 'com_categories.categorycom_content', 'com_templates.style', 'com_tags.tag', 'com_banners.banner', 'com_contact.contact', 'com_newsfeeds.newsfeed');
// only allow some forms, see - https://github.com/joomla/joomla-cms/pull/8657
if (!in_array($name, $valid)) {
return true;
}
}
$config = JFactory::getConfig();
$user = JFactory::getUser();
if ($user->getParam('editor', $config->get('editor')) !== "jce") {
return true;
}
if (!JPluginHelper::getPlugin('editors', 'jce')) {
return true;
}
$hasMedia = false;
$fields = $form->getFieldset();
foreach ($fields as $field) {
$name = $field->getAttribute('name');
// avoid processing twice
if (strpos($form->getFieldAttribute($name, 'class'), 'wf-media-input') !== false) {
return;
}
$type = $field->getAttribute('type');
if (strtolower($type) === "media") {
// get filter value for field, eg: images, media, files
$filter = $field->getAttribute('filter', 'images');
// get file browser link
$link = $this->getLink($filter);
// link not available for environment
if (empty($link)) {
continue;
}
$group = (string) $field->group;
$form->setFieldAttribute($name, 'link', $link, $group);
$form->setFieldAttribute($name, 'class', 'input-large wf-media-input', $group);
$hasMedia = true;
}
}
if ($hasMedia) {
// Include jQuery
JHtml::_('jquery.framework');
$document = JFactory::getDocument();
$document->addScriptDeclaration('jQuery(document).ready(function($){$(".wf-media-input").removeAttr("readonly");});');
$document->addStyleSheet(JURI::root(true) . '/plugins/content/jce/css/media.css');
}
return true;
}
示例7: preprocessForm
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
$app = JFactory::getApplication();
$params = JComponentHelper::getParams('com_djcatalog2');
$user = JFactory::getUser();
$allowed_categories = $params->get('fed_allowed_categories', array());
JArrayHelper::toInteger($allowed_categories);
if (!empty($allowed_categories)) {
$form->setFieldAttribute('cat_id', 'allowed_categories', implode(',', $allowed_categories));
}
if ($params->get('fed_multiple_categories', '0') == '0') {
$form->removeField('categories');
} else {
if (!empty($allowed_categories)) {
$form->setFieldAttribute('categories', 'allowed_categories', implode(',', $allowed_categories));
}
if ((int) $params->get('fed_multiple_categories_limit', 3) > 0) {
$form->setFieldAttribute('categories', 'limit', (int) $params->get('fed_multiple_categories_limit', 3));
if (!empty($data->cat_id)) {
$form->setFieldAttribute('categories', 'ignored_values', $data->cat_id);
}
} else {
if ($params->get('fed_multiple_categories_limit', 3) == '0') {
$form->removeField('categories');
}
}
}
if ($params->get('fed_producer', '0') == '0') {
$form->removeField('producer_id');
} else {
if ($params->get('fed_producer', '0') == '2') {
$form->setFieldAttribute('producer_id', 'required', 'required');
$form->setFieldAttribute('producer_id', 'class', $form->getFieldAttribute('producer_id', 'class') . ' required');
}
if ($params->get('fed_producer_restrict', 0) == '1') {
$form->setFieldAttribute('producer_id', 'validate', 'djcproducer');
if (!empty($data->created_by) && $data->created_by > 0) {
$form->setFieldAttribute('producer_id', 'validate_user', $data->created_by);
}
}
}
if ($params->get('fed_price', '0') == '0') {
$form->removeField('price');
$form->removeField('special_price');
} else {
if ($params->get('fed_price', '0') == '2') {
$form->setFieldAttribute('price', 'required', 'required');
$form->setFieldAttribute('price', 'class', $form->getFieldAttribute('price', 'class') . ' required');
}
}
if ($params->get('fed_featured', '0') == '0') {
$form->removeField('featured');
} else {
if ($params->get('fed_featured', '0') == '2') {
$form->setFieldAttribute('featured', 'required', 'required');
$form->setFieldAttribute('featured', 'class', $form->getFieldAttribute('featured', 'class') . ' required');
}
}
if ($params->get('fed_group', '0') == '0') {
$form->removeField('group_id');
} else {
if ($params->get('fed_group', '0') == '2') {
$form->setFieldAttribute('group_id', 'required', 'true');
//$form->setFieldAttribute('group_id', 'class', $form->getFieldAttribute('group_id', 'class').' required');
}
}
if ($params->get('fed_meta', '0') == '0') {
$form->removeField('metatitle');
$form->removeField('metakey');
$form->removeField('metadesc');
}
if ($params->get('fed_intro_description_editor', null)) {
$form->setFieldAttribute('intro_desc', 'editor', $params->get('fed_intro_description_editor'));
}
if ($params->get('fed_intro_description', '0') == '0') {
$form->removeField('intro_desc');
} else {
if ($params->get('fed_intro_description', '0') == '2') {
$form->setFieldAttribute('intro_desc', 'required', 'required');
$form->setFieldAttribute('intro_desc', 'class', $form->getFieldAttribute('intro_desc', 'class') . ' required');
}
}
if ($params->get('fed_description_editor', null)) {
$form->setFieldAttribute('description', 'editor', $params->get('fed_description_editor'));
}
if ($params->get('fed_description', '0') == '0') {
$form->removeField('description');
} else {
if ($params->get('fed_description', '0') == '2') {
$form->setFieldAttribute('description', 'required', 'required');
$form->setFieldAttribute('description', 'class', $form->getFieldAttribute('description', 'class') . ' required');
}
}
$default_state = $params->get('fed_default_state', '0');
$form->setFieldAttribute('published', 'default', $default_state);
$is_owner = empty($data->created_by) && !empty($data) || isset($data->created_by) && (int) JFactory::getUser()->id === (int) $data->created_by ? true : false;
if (!(JFactory::getUser()->authorise('core.edit.state', 'com_djcatalog2') || JFactory::getUser()->authorise('core.edit.state.own', 'com_djcatalog2') && $is_owner)) {
if (isset($data->published)) {
$form->removeField('published');
}
//.........这里部分代码省略.........