Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles

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

 

Show Printable Version Email this Page Subscription
Yellow Slider Yellow Slider is offline 01-21-2011, 10:00 PM

- 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:
PHP Code:
return $pub_view
Add above it:
PHP Code:
$getFIELDNAME vB::$vbulletin->db->query_first("SELECT FIELDNAME FROM " TABLE_PREFIX "cms_node WHERE nodeid = " $this->nodeid);
$pub_view->FIELDNAME $getFIELDNAME['FIELDNAME']; 
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:
HTML Code:
</div>
<div style="clear:both"></div>
Add the following lines of code:
HTML Code:
	<div class="blockrow" >
		<label class="thirdleft">FIELD TITLE</label>
		<div class="twothirdsright"><input type="text" size="30" value="{vb:raw FIELDNAME}" name="FIELDNAME" tabindex="1" class="textbox fullwidth" /></div>
	</div>
4.
Go to your ACP --> Plugins & Products --> Add New Plugin.
Hook Location: vbcms_article_save_start.
PHP Code:
PHP Code:
vB::$vbulletin->input->clean_array_gpc('r', array(
    
'FIELDNAME' => TYPE_STR
));

vB::$vbulletin->db->query_write("UPDATE " TABLE_PREFIX "cms_node SET FIELDNAME = '" vB::$vbulletin->db->escape_string(vB::$vbulletin->GPC['FIELDNAME']) . "' WHERE nodeid = " $this->content->getNodeId()); 

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).

HTML Code:
<div>Custom Field:{vb:raw FIELDNAME}</div>
6. Then, open vbcms/item/content/article.php and add your field to the end of the protected $content_properties array.
PHP Code:
'imageheight''previewvideo''FIELDNAME' 
7. In that same file, add this line with the other similar lines:

PHP Code:
protected $FIELDNAME
8. Again, in the same file, add this with the other similar functions:
PHP Code:
    public function getFIELDNAME()
    {
        
$this->Load(self::INFO_CONTENT);
        return 
$this->FIELDNAME;
    } 
9. Then add another plugin using hook_location "vbcms_article_populate_start":
PHP Code:
$view->FIELDNAME $this->content->getFIELDNAME(); 
I think I got that all correct.


That's it, you're done.
Reply With Quote
  #22  
Old 05-03-2012, 10:17 PM
firebrand media firebrand media is offline
 
Join Date: Apr 2012
Posts: 28
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ah...
So I just add a column to the cms_node table?
Easy enough.

This is my first foray into vBulletin modding and I just get nervous about operating with a chainsaw.

--------------- Added [DATE]1336088225[/DATE] at [TIME]1336088225[/TIME] ---------------

Sorry for the noob questions.
Quote:
2.
Open packages\vbcms\item\content.php and find:
If I edit conten.php, isn't the change going to get blown away when update vBulletin?
Reply With Quote
  #23  
Old 05-04-2012, 12:23 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by firebrand media View Post
If I edit conten.php, isn't the change going to get blown away when update vBulletin?
Yes. That's why it's good to use plugins when possible, but there isn't always a hook location in place to do what you want to do.
Reply With Quote
  #24  
Old 05-04-2012, 01:29 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And this is why you should always keep notes when editing your site.
Reply With Quote
  #25  
Old 05-04-2012, 06:56 PM
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
Posts: 1,630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

anybody got this running without editing the files?
Reply With Quote
  #26  
Old 05-05-2012, 07:24 AM
charlesr charlesr is offline
 
Join Date: Aug 2009
Posts: 177
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't think it's possible because there is no hook location to call via a plugin product.
Reply With Quote
  #27  
Old 05-05-2012, 10:39 AM
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
Posts: 1,630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1. edit isn't necessary => hook vbcms_content_publish_editor
2. template edit is fine, who cares about this ( tms^^ )

but everythng else seems to be impossible
shame that they still didn't change this
Reply With Quote
  #28  
Old 05-27-2012, 05:20 PM
Yellow Slider Yellow Slider is offline
 
Join Date: Aug 2006
Posts: 249
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ragtek View Post
1. edit isn't necessary => hook vbcms_content_publish_editor
2. template edit is fine, who cares about this ( tms^^ )

but everythng else seems to be impossible
shame that they still didn't change this
Yep, it took a year but they finally added the hook. I've updated the relevant step.

I guess I should have asked them to add some other hooks back then, cause if I open a new hook request now, vB 5 would be out by the time the hooks get added
Reply With Quote
  #29  
Old 12-22-2012, 02:08 PM
christleo christleo is offline
 
Join Date: Jun 2004
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by HouseAddict View Post
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 [DATE]1295989658[/DATE] at [TIME]1295989658[/TIME] ---------------

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.

Having the same issue... $this->content->getFIELDNAME() seems like giving me blank too...
Reply With Quote
  #30  
Old 04-25-2014, 08:38 AM
pczone pczone is offline
 
Join Date: Nov 2001
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I also blank too , I try to fixed and works.

edit:
packages/vbcms/item/content/article.php

find:
Code:
$sql = "SELECT node.nodeid, node.showrating, node.setpublish, node.new
add node.FIELDNAME, at the end of the line:
Code:
$sql = "SELECT node.nodeid, node.showrating, node.setpublish, node.new,node.FIELDNAME,
Reply With Quote
  #31  
Old 06-07-2015, 01:12 AM
BlackxRam BlackxRam is offline
 
Join Date: Aug 2003
Posts: 364
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can anyone confirm that this mod still works? How many custom fields does this add to articles in your CMS?
Reply With Quote
Reply

Thread Tools

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

Forum Jump


All times are GMT. The time now is 10:13 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05207 seconds
  • Memory Usage 2,324KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_code
  • (3)bbcode_html
  • (7)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (11)post_thanks_box
  • (2)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete