1

I looking if there is a solution for creating a custom field in the xml file so i tried to create a field

<field name="inject_label"
    type="note"
    default="WRAPROTECT_PLG_INJECT_LABEL"
    label="WRAPROTECT_PLG_INJECT_LABEL"
/>

Now in my language file i did this

WRAPROTECT_PLG_INJECT_LABEL="<div class='control-group'>
<label class='control-label'>.htaccess</label>
<div class='controls'>
<p class='help-block'> %s </p></div>
</div>"

In my plugin i want to replace

%S

by checking

JRequest::getVar('clean_cache');

and

sprintf('WRAPROTECT_PLG_INJECT_LABEL',$someVar);

I'm searching if there is a best practice to do this in a different way

1

If you want to replace %s, then you can use the following:

$jinput  = JFactory::getApplication()->input;
$someVar = $jinput->get('clean_cache', '');

echo JText::sprintf('WRAPROTECT_PLG_INJECT_LABEL', $someVar);

As you can see, I've made use of JInput instead of JRequest, as this is deprecated.

  • I used a custom type in my xml so i'll paste it in the answer – G. Mansour Oct 14 '16 at 7:24
1

For creating a custom field in xml, do it as-

provide type ="your_desired_name", like i have given abcd.

Now, create a php file with name abcd.php and place it in 'fields' folder. Now define a class in it as-

<?php

defined('JPATH_BASE') or die;
jimport('joomla.form.formfield');

class JFormFieldAbcd extends JFormField {
    protected $type = 'abcd';

    protected function getInput() {
        return 'required value';
    }

}
0

In my XML file i used

<fieldset label="WRAPROTECT_PLG_GLOBAL_LABEL" name="basic_1" addfieldpath="plugins/system/wraprotect/fields">
</fieldset>

In my php file i used the function

getInput()

and

return '<tag>'.JText::_('some text %s').'</tag>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.