Skip to Content Skip to Menu

🌟 CB Editor Assistant 1.0.0 is here! Discover our new AI Joomla Plugin that wrote its story! (and this banner!)
Start at just $12.50/month* or 💸 save 30% with our 🛍️ Intro Black Friday Offer for a lifetime*

dynamic params on plugin developing

14 years 3 months ago #139000 by sohoprospecting
dynamic params on plugin developing was created by sohoprospecting
Hi!
I am developing a cb tab plugin. On this plugin I need to list on the backend text params that would reflect #__comprofiler_fields fields.

I am trying to find a way to get this field dynamically using:

[code:1]
<!--XML FILE-->
<url addpath="/elements">
<param name="cbfields" type="cbfields" class="JElementCbfields" default="" label="Select fields : " description="Select fields For profile completeness bar" />
</url>[/code:1]

[code:1]
//PHP CLASS
class JElementCbfields extends JElement {
var $_name = 'cbfields';

function fetchElement($name, $value, &$node, $control_name) {

$db = &JFactory::getDBO();

$query = "SELECT name, CONCAT(description,' - ','#__comprofiler.',name,' (set zero to skip field)') as description
FROM #__comprofiler_fields
WHERE published = 1
AND type IN ('text','multiselect','predefined','image')";
$db->setQuery($query);

$rows = $db->loadObjectList();
$xml = "";
foreach ( $rows as $row ) {
$xml .= "<param name=\"".$row->name."\" type=\"text\" default=\"0\" label=\"".$row->name."\" description=\"".$row->description."\" size=\"2\" />";
}
return $xml;
}
}
[/code:1]

It is a big deal that I have to give value to each field param, because I use it on my plugin.

What I need as result is something similar to the attached image.

Errors the I got on backend:
Notice: Use of undefined constant _HANDLER - assumed '_HANDLER' in /administrator/components/com_comprofiler/library/cb/cb.params.php on line 1244

Post edited by: sohoprospecting, at: 2010/07/30 01:23

Post edited by: sohoprospecting, at: 2010/07/30 01:39

---
PHP - 5.2.14 / Joomla - 1.5.20 / CB - 1.2.3
Attachments:

Please Log in or Create an account to join the conversation.

  • drdehart
  • drdehart
  • OFFLINE
  • Posts: 253
  • Thanks: 2
  • Karma: 1
14 years 3 months ago #139202 by drdehart
Replied by drdehart on topic Re:dynamic params on plugin developing
Can we get some help on this - we see the capability of displaying CB fields in CBsubs - so we're pretty sure its possible.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48554
  • Thanks: 8292
  • Karma: 1445
14 years 3 months ago #139269 by krileon
Replied by krileon on topic Re:dynamic params on plugin developing
The following is how to call an external class function inside of your plugins XML. Please note this call should be made to a class and function that is a part of your plugins actual core PHP files.

[code:1]
<param name="UNIQUE_NAME" type="custom" class="CLASS" method="FUNCTION" default="" label="TITLE" description="DESCRIPTION" />
[/code:1]

Your usage is not specifying a method (function). You just called a class is all. Based off the code you provided the parameter should be configured as follows.

[code:1]
<param name="cbfields" type="custom" class="JElementCbfields" method="fetchElement" default="" label="Select fields : " description="Select fields For profile completeness bar" />
[/code:1]


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

14 years 3 months ago #139314 by sohoprospecting
Replied by sohoprospecting on topic Re:dynamic params on plugin developing
Hi Kyle!

I tried edit my xml the way you said. But now, on the tab backend, I got the error:

[code:1]Method to render XML view element url is not implemented ![/code:1]

The file /elements/cbfields.php is part of the core by using:

[code:1]<filename plugin="plug_completeness">/elements/cbfields.php</filename> [/code:1]

Do you think is something wrong with my class? Perhaps not following a cb standart?

Thank you!

---
PHP - 5.2.14 / Joomla - 1.5.20 / CB - 1.2.3

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48554
  • Thanks: 8292
  • Karma: 1445
14 years 3 months ago #139324 by krileon
Replied by krileon on topic Re:dynamic params on plugin developing
Yes, you're not extending a CB class. You need to extend cbPluginHandler or cbTabHandler. You need to review another plugin that is using such usage as it's not done correctly. Your parameter is now correct, but the class and function are completely wrong. The following is an example of how to structure the parameter, class, and function.

Parameter
[code:1]
<param name="myfield" type="custom" class="getcbMyTab" method="loadFieldsList" default="" label="Field" description="This is a custom field." />
[/code:1]

Class
[code:1]
class getcbMyTab extends cbTabHandler {
[/code:1]

Function
[code:1]
function loadFieldsList( $name, $value, $control_name ) {
global $_CB_database;

$query = 'SELECT ' . $_CB_database->NameQuote( 'fieldid' ) . ' AS value'
. ', ' . $_CB_database->NameQuote( 'title' ) . ' AS text'
. "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_fields' )
. "\n WHERE " . $_CB_database->NameQuote( 'published' ) . " = 1"
. "\n ORDER BY " . $_CB_database->NameQuote( 'ordering' );
$_CB_database->setQuery( $query );
$rows = $_CB_database->loadObjectList();

if ( ! is_array( $rows ) ) {
trigger_error( 'CB Fields load list error: ' . $_CB_database->stderr(), E_USER_WARNING );
return false;
}

array_unshift( $rows, moscomprofilerHTML::makeOption( '', CBTxt::T( '- Select Field -' ) ) );

if ( isset( $value ) ) {
$valAsObj = array_map( create_function( '$v', '$o=new stdClass(); $o->value=$v; return $o;' ), explode( '|*|', $value ) );
} else {
$valAsObj = null;
}

return moscomprofilerHTML::«»selectList( $rows, ( $control_name ? $control_name . '[]' : $name ), null, 'value', 'text', $valAsObj, 0, true );
}
[/code:1]


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum