Keyword

[SOLVED] custom field K2 plugin

More
11 years 4 months ago - 11 years 4 months ago #113701 by jean-philippe
[SOLVED] custom field K2 plugin was created by jean-philippe
Hi,

It is possible to get a custom field into a k2_plugin?

error Message:

theme Element not defined for type = foldertheme

(into K2Parameter.php)

Example :

XML:
					
Emond, Jean-Philippe

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
11 years 4 months ago #113702 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic Re: custom field K2 plugin
The xml part seems valid.

perhaps there is a problem in the php file, if you can show it here, I can help to find out the problem.

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

More
11 years 4 months ago #113703 by jean-philippe
Replied by jean-philippe on topic Re: custom field K2 plugin
Hi Mohamed Abelaziz,

this is my php file :


					
Emond, Jean-Philippe

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
11 years 4 months ago #113704 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic Re: custom field K2 plugin
Hi Jean,

The element class should extend the K2Element class at first, so the class definition should look like this:
class K2ElementFoldertheme extends K2Element

Then you will create a form field class that extends the element class, like this:
class JFormFieldFoldertheme extends K2ElementFoldertheme

Have a quick look at any K2 element and you will find your way.

Hope this solves your problem

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

More
11 years 4 months ago - 11 years 4 months ago #113705 by jean-philippe
Replied by jean-philippe on topic Re: custom field K2 plugin
Thanks for fast answer Mohamed,

Just a small question,

I just see into the "administrator/components/com_k2/elements" many Elements
And I see how to make K2Element..

My php Element file is now:

(test file)
	

Attachment not found



The "T" and "h"
it is the first and second letter of the "$output" variable.

I have tried to put an HTML div but ... same thing...

I guess it is for array?

My other problems is, if I need to get "Options" because it's a list...
I have try to var_dump all parameter like $name, $value $node...
and all parameter is null...

any Idea for this?

Thanks Alot,
Emond, Jean-Philippe

=====================================

EDIT:

I have modify my php file for this:
	

Attachment not found




now... just know how to get "label" "description" and "option" if I have a custom ListElement.
					
Emond, Jean-Philippe
Attachments:

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
11 years 4 months ago #113706 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic Re: custom field K2 plugin
Good result :)

For the label, you need to override the render function, just add this function to the element class:
function render(&$xmlElement, $value, $control_name = 'params') {
        $name = $xmlElement->_attributes['name'];
        $result[0] = $xmlElement->_attributes['label'];        
        $result[1] = $this->fetchElement($name, $value, $xmlElement, $control_name);
        return $result;
    }

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

More
11 years 4 months ago - 11 years 4 months ago #113707 by jean-philippe
Replied by jean-philippe on topic Re: custom field K2 plugin
Cool Mohamed Abdelaziz,
Works now..

Attachment not found



Just a tiny fix now..
I can't save my value... ><"

Nota Bene: in the Xml.. if I change the custom type for "list".. the values is correctly saved.

!!

Emond, Jean-Philippe
Attachments:

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

More
11 years 4 months ago #113708 by jean-philippe
Replied by jean-philippe on topic Re: custom field K2 plugin
Thanks Mohamed Abdelaziz for your Help,

I have found My error...

Base on the "list.php" K2Element, I Can now save my field.

So The Problem is Fixed now!



Thanks Again,
Emond, Jean-Philippe

Emond, Jean-Philippe

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
11 years 4 months ago #113709 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic Re: custom field K2 plugin
Great Jean :)

Enjoy your weekend.

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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