11 years ago
5
Topic

Hi,
I built a plugin that allows users to have create scrambled aliases on articles. (Really, it scrambles any field, but I'm using it for aliases so my articles can have a url like www.yoursite.com/217328fsdfsd6ftsfbsdf, which is what I need.)

The issue is that since the Edit template for articles is the same as the New Article template, that field generates a new random alias every time an article is edited.

Is there a way to have a plugin field only appear on Create New Article and not appear on Edit? Or is there something fundamental that I'm missing?

I would love to share the plugin as soon as it's complete.

Thanks!

Get a VIP membership
11 years ago
3
Level 1

Hello zuber,

in your plugin have a look at the $config['pk'] variable.

  • Creation = 0
  • Edition = id of content


Regards.

Lionel

11 years ago
2
Level 2

I appreciate the reply! I got create the plugin via the Developer plugin and I don't see that $config['pk'] anywhere in the code. Should it be in the plugin's main php file? Also, this is a field type plugin, should I have created a typo one?

11 years ago
1
Level 3

Hello zuber,

yes, in the main php file of your plugin field you have many events like "onCCK_FieldPrepareForm".


And in most of events, you can access to the variable "$config" which is a table. In this table, you have an item which is named "pk" and it's value is 0 if you are in creation form, instead it take the ID of the content (from #__content).


So with a test on it you can hide it by setting:

if( $config['pk'] ){
	$field->display = 0;
	$field->form = '';
}


Regards.
Lionel
11 years ago
0
Level 4

Thanks again for the response! I tried this code in a few different places in public function onCCK_FieldPrepareForm, but it didn't work. Is that code a sample or the exact code I would need? I'm still confused about how it works. I mean I'm guess it's checking PK to see if it has a value other than 0. If it does have a value other than 0, display is 0 (which means the field should not display) and the form is ' ' (not sure what the form part means). So I think I do understand how it works, I'm just not sure where to put it.

11 years ago
0
Level 1

I just tried setting the field conditionally but it didn't work. I set it to:

This field is Disabled WHEN Article State is Equal to 1

Should this have accomplished having the field disabled in Edit mode?

Get a VIP membership