1

With a content plugin and the onContentPrepareForm trigger, I inject custom extra fields into article's edit page.

The problem is that my Custom Fields Tab binds with the Article's Options Tab (layouts/ /joomla/edit/params).

What I mean is that any extra tab with form <fields> that is injected with the onContentPrepareForm, it is "generated" in conjunction with the "Options" Tab (params/attrib form layout for).

Com_content has settings to show/hide article options tab (and other tabs). But my custom tab listen also to this show/hide.

What I want is to have the article options set to component's default set in "Options" and hidden for the user, while only displaying my custom fields tab. But I have no success so far.

Have anyone any idea of what I should look for?

1 Answer 1

2

Getting all that functionality with a plugin will be difficult. The xml form system Joomla uses for its forms/tabs is pretty complex in how it builds itself. Also to my knowledge there is no key "events" at stages that will let you change what form XML may be loaded (that and a Joomla update that renames a couple things or adds another field would ruin it).

But here is my thought.

//regex
$regex  = '/\<input[^>]*\stype=\"hidden\"[^>]*\sname=\"jform\[params\]\[plugin\]\"[^>]*\sid=\"jform_params_plugin\"[^>]*\svalue=\"1\"[^>]*\s\/\>/i';

//check for match
if(preg_match($regex,$buffer)){

   //bind an xml form
   $xml = simplexml_load_file(PATH_TO_XML_FILE.'.xml');
   if($form = JForm::getInstance((string)$xml->name,$xml->asXML())){
       $arr = array();
       //here you need to build an array to auto fill the data from the form, 
       //if you already had this working to an extent I am sure it will be fine.
       $form->bind($arr);
   }

   $content = '';
   //here you need to basically get the form fields into content as text to be added to
   //the current output, there are many ways to do this.

   //replace the current output of Joomla to add the extra fields
   $buffer = preg_replace($regex,$content,$buffer);
   JFactory::getDocument()->setBuffer($buffer, 'component');
}

To explain, first the regular expression is finding a form field in the current output of the page (this can be ones from your options tab). If it finds a match it loads an xml file of your fields and then replaces them with yours. Given that you had said that you got some distance I am sure this might only build on that if anything.

4
  • Not sure I was able to follow you on this. I might have to re-study thoroughly and with peace your answer.
    – FFrewin
    Aug 26, 2014 at 17:20
  • It is complex, tried to keep it simple but anytime regex is involved that can be hard x.x. Basically it searched for the html output of the form after it was rendered, then inserts your own afterword. Aug 27, 2014 at 14:57
  • @JordanRamstad Oh no!! You didn't!!! Did you just try to parse html with Regex??? Feb 8, 2015 at 22:11
  • Only way i could see in this case to get the effect I wanted without messing with the core. It's nothing major, based on this the exact tag is known, so its a find and replace just like any other {tag replace} in Joomla. Feb 9, 2015 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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