Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
How to add a new field to the CMS
Yellow Slider
Join Date: Aug 2006
Posts: 249

by Yellow Slider Yellow Slider is offline 22 Jan 2011
Rating: (2 votes - 3.50 average)

- Apply the changes mentioned in this how-to at your own risk.
- You must have a basic understanding of php, html and vbulletin.
- This is a how-to for vb4.1, and may not work on previous versions.

Everywhere you see FIELDNAME, replace it with your field name (must not contain spaces).

1.
Create a new field in the cms_node table.

2.
If you run vB 4.1.9 or lower , open packages\vbcms\item\content.php and find:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Add above it:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

If you run 4.1.10+, you can just create a new plugin with the above code, the hook is vbcms_content_publish_editor.

3.
Go to the template vbcms_edit_publisher.
At the bottom of the template, before these lines:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Add the following lines of code:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

4.
Go to your ACP --> Plugins & Products --> Add New Plugin.
Hook Location: vbcms_article_save_start.
PHP Code:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


The following steps have been written by Lynne, thank you

5. To get the field to spit out, you must add it to the vbcms_content_article_page somewhere (this is rough, you'll have to add your own class/styling).


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

6. Then, open vbcms/item/content/article.php and add your field to the end of the protected $content_properties array.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

7. In that same file, add this line with the other similar lines:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

8. Again, in the same file, add this with the other similar functions:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

9. Then add another plugin using hook_location "vbcms_article_populate_start":

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I think I got that all correct.


That's it, you're done.

Last edited by Yellow Slider; 27 May 2012 at 19:20..
Views: 10758
Reply With Quote
Comments
  #2  
Old 22 Jan 2011, 17:49
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Real name: Lynne
Thank you! I'll have to try this out.
__________________
Former vBulletin.org Staff Member

Try a search before posting for help. Many users won't, and don't, help if the question has been answered several times before.
W3Schools -
Online vBulletin Manual
If I post some CSS and don't say where it goes, put it in the additional.css template.
I will NOT help via PM (you will be directed to post in the forums for help.)
Reply With Quote
  #3  
Old 25 Jan 2011, 11:08
HouseAddict HouseAddict is offline
 
Join Date: Jul 2008
I tried that for 3 fields (instead of one) and I can't get any of the data submitted to save into the database... some troubleshooting of the above code might be needed... have you tried this yourself?
Reply With Quote
  #4  
Old 25 Jan 2011, 12:06
Yellow Slider Yellow Slider is offline
 
Join Date: Aug 2006
Originally Posted by HouseAddict View Post
I tried that for 3 fields (instead of one) and I can't get any of the data submitted to save into the database... some troubleshooting of the above code might be needed... have you tried this yourself?
Please paste the relevant lines of code from packages\vbcms\item\content.php, vbcms_edit_publisher and the plugin.
Reply With Quote
  #5  
Old 25 Jan 2011, 18:31
HouseAddict HouseAddict is offline
 
Join Date: Jul 2008
Originally Posted by Yellow Slider View Post
Please paste the relevant lines of code from packages\vbcms\item\content.php, vbcms_edit_publisher and the plugin.
Sure.

content.php:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.



article.php:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.



vbcms_content_article_inline template

added this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

right below this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.



plugin with vbcms_article_populate_start hook:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.



and plugin with vbcms_article_save_start hook:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.



As I said, the fields show up just fine, but when I enter anything into them and click Save or Apply, the values are not shown.

They are correctly saved in the mysql, but are not being shown in the Edit Article page under those fields when the changes to the article are saved.

Last edited by HouseAddict; 25 Jan 2011 at 18:47.
Reply With Quote
  #6  
Old 25 Jan 2011, 18:54
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Real name: Lynne
I have tried this and it works fine for me. Have you tried spitting out your last query to see if it is correct?

This is incorrect:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

You are using $geturl_text for all three of them. I would actually do this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________
Former vBulletin.org Staff Member

Try a search before posting for help. Many users won't, and don't, help if the question has been answered several times before.
W3Schools -
Online vBulletin Manual
If I post some CSS and don't say where it goes, put it in the additional.css template.
I will NOT help via PM (you will be directed to post in the forums for help.)
Reply With Quote
  #7  
Old 25 Jan 2011, 19:00
HouseAddict HouseAddict is offline
 
Join Date: Jul 2008
Doh!

Obvious mistake.

That was it, in a way...

Now, the problem I have is if I put those fields in "vbcms_edit_publisher" template, they show up just fine and work ok. But if I put them in "vbcms_content_article_inline" template - no go, they don't show the values at all, even though they save them properly.

And I'd rather have those extra fields in vbcms_content_article_inline, below the actual content box instead of in vbcms_edit_publisher which adds them into the right-hand column which makes that long column even longer now...

Thoughts?

Maybe this has something to do with the hooks?
Reply With Quote
  #8  
Old 25 Jan 2011, 19:20
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Real name: Lynne
If you want them in other templates, you must write a plugin to register them for use in the other template. Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide
__________________
Former vBulletin.org Staff Member

Try a search before posting for help. Many users won't, and don't, help if the question has been answered several times before.
W3Schools -
Online vBulletin Manual
If I post some CSS and don't say where it goes, put it in the additional.css template.
I will NOT help via PM (you will be directed to post in the forums for help.)
Reply With Quote
  #9  
Old 25 Jan 2011, 20:10
HouseAddict HouseAddict is offline
 
Join Date: Jul 2008
Originally Posted by Lynne View Post
If you want them in other templates, you must write a plugin to register them for use in the other template. Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide
And that's a short guide?

Geez... I just spent almost an hour going through it and trying it out without any success.

Tsk, why does this have to be so darn complicated...

Hmm, how can I extend that $pub_view array to be available to other templates, not just vbcms_edit_publisher (as defined in content.php) in an easier manner...

--------------- Added 25 Jan 2011 at 21:07 ---------------

It seems that I am having some issue with spitting out the value in the front-end as well... adding that code to vbcms_content_article_page prints out nothing.

Seems the root of the problem is $view->FIELDNAME = $this->content->getFIELDNAME(); in the plugin attached to vbcms_article_populate_start... as if I change that $view->FIELDNAME value to a constant, I get a value out on the front-end and in all the other templates (weird). If I leave it as $this->content->getFIELDNAME(), it ends up blank.

Last edited by HouseAddict; 25 Jan 2011 at 21:07. Reason: Auto-Merged DoublePost
Reply With Quote
  #10  
Old 25 Jan 2011, 23:08
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Real name: Lynne
Ah yes, steps 5 through 9 were written to add the fields to the article page. That's it. If you need it on another page, you'd have to probaby do all those steps on another page. Perhaps someone else will look into that part and post it.
__________________
Former vBulletin.org Staff Member

Try a search before posting for help. Many users won't, and don't, help if the question has been answered several times before.
W3Schools -
Online vBulletin Manual
If I post some CSS and don't say where it goes, put it in the additional.css template.
I will NOT help via PM (you will be directed to post in the forums for help.)
Reply With Quote
  #11  
Old 04 Feb 2011, 10:32
Miss T Miss T is offline
 
Join Date: Sep 2008
hey Yellow

cant you please check you PM inbox - you qouta is up and the reply you asked me for cannot be sent to you
Reply With Quote
  #12  
Old 11 May 2011, 20:09
edyy edyy is offline
 
Join Date: Jul 2010
I can't manage to make this to work, I've made everthing it says in here but when I put the data into the fields and push SAVE I get this error

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Reply With Quote
  #13  
Old 11 May 2011, 21:22
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Real name: Lynne
That's because you have a comma right before the WHERE line which isn't supposed to be there.
__________________
Former vBulletin.org Staff Member

Try a search before posting for help. Many users won't, and don't, help if the question has been answered several times before.
W3Schools -
Online vBulletin Manual
If I post some CSS and don't say where it goes, put it in the additional.css template.
I will NOT help via PM (you will be directed to post in the forums for help.)
Reply With Quote
  #14  
Old 12 May 2011, 15:30
edyy edyy is offline
 
Join Date: Jul 2010
The problem it is as you said a comma, thank you verry much for the help. Now i have the same problem as HouseAddict, the date is inserted into the database but is not spit out on the article page. Can you help me fix that problem too ?

Thanks again for the help.
Reply With Quote
  #15  
Old 12 May 2011, 23:57
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Real name: Lynne
I haven't any need for adding a new field to my CMS, so I haven't looked into this in anyway past what I posted for Yellow Slider.
__________________
Former vBulletin.org Staff Member

Try a search before posting for help. Many users won't, and don't, help if the question has been answered several times before.
W3Schools -
Online vBulletin Manual
If I post some CSS and don't say where it goes, put it in the additional.css template.
I will NOT help via PM (you will be directed to post in the forums for help.)
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 23:55.

Layout Options | Width: Wide Color: