user-pic

How to add object types to Custom Fields?

Vote 0 Votes

Greetings,

Today's problem is that I need to be able to add a Caption field to an uploaded file. Unfortunately, uploaded files aren't included in the list of System Objects in the New Field form, so I need to be able to add an object type and provide some kind of handling for it.

To avoid ugly hacks into Commercial.pack code, the best solution seems to be to write my own plugin and use a callback, but I'm still pretty new to MT and my deadline doesn't allow much time for learning curve. Can somebody with better understanding of custom fields describe how this would work, or at least point me in the right direction so I can ask more succinct and intelligent questions in a few days?

thanks,
Bill

Reported on Movable Type 4.3

6 Replies

| Add a Reply
  • Is there a reason not to use the asset's description or title field for a caption? I don't know the specifics of what you're after, but that's the first place I'd go.

  • I need to provide a way for a user to add their own caption when they upload a file. Here's what I've come up with so far:

    1. Added file in addons/Commercial.pack/config.yaml so Asset shows up in System Objects select list in Custom Fields > New Field form:


    customfields:
    file:
    context: all

    2. added callbacks in addons/Commercial/config.yaml

    callbacks:
    api_save_filter.file: $Commercial::CustomFields::App::CMS::CMSSaveFilter_customfield_objs
    api_post_save.file: $Commercial::CustomFields::App::CMS::CMSPostSave_customfield_objs


    cms:
    callbacks:
    cms_post_save.file: $Commercial::CustomFields::App::CMS::CMSPostSave_customfield_objs
    cms_save_filter.file: $Commercial::CustomFields::App::CMS::CMSSave_customfield_obj

    3. Added caption input to tmpl/cms/dialog/asset_options.tmpl so Captions field shows up when I'm uploading a file:


    <mtapp:setting
    id="file_caption"
    label_class="top-label"
    label="<__trans phrase="Caption">">
    <textarea name="caption" id="file_caption" cols="" rows="" class="full-width short"></textarea>
    </mtapp:setting>

    4. Added the tag provided by Custom Field to my Entry template


    <mt:If tag="Upload_file_caption">
    Upload File Caption: <mt:Upload_file_caption>
    </mt:If>

    With all of that, the caption field that does show up in the upload file form when I do Create > Upload File in my blog and I can enter a caption. The only thing that isn't happening now is for the caption doesn't show up with my uploaded file. Any ideas what I'm missing, or where my caption goes when I post an upload?

    thanks,
    Bill

    PS--of course, this should probably all go into its own plugin instead of hacks on Commercial.pack and MT, but I need to get something working first.

  • I will admit to not studying your code, because I'm left going back to myoriginal question: what's wrong with using the asset title or description fields that are included for this very purpose?

  • It's mostly just that being able to add a caption is a requirement that was presented to me by the people I work for, not something I decided to do on my own. If I just can't get this to work, then it might be time to try to talk them into using the description.

  • Updating:
    Since using Description could make my life a lot easier, I just tried uploading a file and providing a description. Unfortunately, my description didn't show up anywhere either, just like my caption doesn't. Any ideas on that?

    cheers,
    Bill

  • Are you publishing the description? I'm guessing not, because it's not done by default. http://www.movabletype.org/documentation/appendices/tags/assetdescription.html You could use Custom Asset Markup (http://plugins.movabletype.org/custom-asset-markup/) to rewrite the markup to include this.

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1773 6162

Last Topic: Excluding categories from blog by kholechek on Feb 9, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1428 5076

Last Topic: Stupid Question? How to make a static homepage by Jeremy on Feb 3, 2012

694 2908

Last Topic: Blogspot to Movable Type by sdude on Feb 8, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

173 737

Last Topic: About the MT version stated in HTML source by Alex E. Schneider on Feb 7, 2012

190 565

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012