[SOLVED] New Field Type help

13 years 3 months ago #147620 by clwweb
[SOLVED] New Field Type help was created by clwweb
I would have liked the webaddress field to have the option for opening in the same window, or in a new window, but that was not available, so I am trying to make a duplicate webaddress field type, with the small change of opening in the same window.

I added several things to the core files to get this started, but part of the field is missing.

First, I edited the cb.core.php file, I added [code:1]'webaddress2' => 'CBfield_webaddress_self'[/code:1]in the initial Array

I then duplicated the webaddress class, and adjusted the name to match the above.

I also edited the cb.core.xml and duplicated the webaddress field there, with a change to the name of it.

The field will show up as a selectable option now in CB, but it is missing the drop down at the bottom which lets you select URL only or Hypertext + Url.

Any ideas how I can get that last bit to display? Do I need to keep the duplicate webaddress name in the xml file, or should its type show "webaddress2" as in the array? Do I need to add something to the mysql db?


Post edited by: clwweb, at: 2010/12/24 04:36

Post edited by: krileon, at: 2010/12/27 15:36

Please Log in to join the conversation.

13 years 3 months ago #147671 by krileon
Replied by krileon on topic Re:New Field Type help
I don't recommend core edits. For examples on how to add a new fieldtype please see the ajax file and text fieldtype plugins available to documentation subscribers. The ajax text field is the best example is it provides how to enhance an existing field while maintain a separate type.

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 to join the conversation.

13 years 2 months ago #149409 by clwweb
Replied by clwweb on topic Re:New Field Type help
I resolved the issue. I know you frown upon core edits, but I think you should add these edits to your own core for future releases.

I added a drop down box to the web address field that lets you select to open on self or in a new window.

Code changes for the cb.core.php:

On or around line 1988, I added
[code:1]$target = $field->params->get( 'targetUrl' );[/code:1] which was right below this line, [code:1]$value = $user->get( $field->name );[/code:1] (but it doesn't really matter where you place it, just somewhere up around there)

On or around line 2000, I changed the line of [code:1]return '<a href="http://' . htmlspecialchars( $oReturn[0] ) . '" target="_blank" rel="nofollow">' . htmlspecialchars( $oReturn[1] ) . '</a>';[/code:1]
[code:1]return '<a href="http://' . htmlspecialchars( $oReturn[0] ) . '" target="' . $target . '" rel="nofollow">' . htmlspecialchars( $oReturn[1] ) . '</a>';[/code:1] (replaced the static "target" html with a variable, that is chosen from a drop down list in the field management page)

Code changes for cb.core.xml:

Look for the webaddress field type. On or around line 295 is a closing if tag, </if>
below that, add the following code,
[code:1]<param name="targetUrl" type="list" default="" label="How to Open the Web Address" description="Choose to open the site url in a new window or in same window (on Self).">
<option value="_self">Open on Self</option>
<option value="_blank">Open in New Window</option>
The code should be before the </fieldset> tag, and that's It.

Now go into your Field Management page, create new field, and look at the right side under Field Entry Validation, it should show a drop down box with the options of opening on self or in a new window! (Self by default)
(I could have put this somewhere that made more sense such as at the bottom of all that, but it works so I'm leaving it alone)

Now if an admin will look over the edit and tell me if there is anything wrong with it, that would be great. Otherwise, I hope this becomes a part of CB in future releases. Feel free to use this code for whatever, if it gets added to the release, I won't have to re-add them after updates
The following user(s) said Thank You: makles

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.238 seconds

Facebook Twitter LinkedIn