We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How to set formatting (not == NULL)..

Development and Programming

timkelty's avatar
timkelty
177 posts
16 years ago
timkelty's avatar timkelty

Many 3rd party extensions I use have been broken since the upgrade to 1.6.5. When publishing, they get put in the DB as NULL. Could someone post a snippet/example of how to explicitly set the formatting? I’ve changed this part, so the dropdown at least displays:

"formatting_block" => "none",
            "formatting_unavailable" => "block",

But it still seems to be NULL in the DB when published.

I thought originally I could just comment this line out, but it was still published NULL:

// automatically make this field have no formatting
        $js.= "\ndocument.field_form.field_fmt.selectedIndex = 0;\n";

The extensions I’m specifcally having trouble with are: MD Markitup! LG Image Manager LG File Manager DC URL Field, thought to have been fixed, I believe is suffering from the same…

This has been discussed here, but it turns out they just did what I did, show the dropdown and hide the no_formatting block, which didn’t actually prevent entries from being published NULL.

I should note that you can go back to change the formatting, check the update all entries, and that part works…but as it is all new entries get published NULL in the DB.

If someone could shed some light on this, or at least point me in the right direction, that would be great. Thanks.

       
Robin Sowell's avatar
Robin Sowell
13,160 posts
16 years ago
Robin Sowell's avatar Robin Sowell

Basically, there is no default for the field format field due to a change in field type. So- the field now must have a value- either via the select or a hidden field- when it’s submitted. That help at all?

       
timkelty's avatar
timkelty
177 posts
16 years ago
timkelty's avatar timkelty

Yes, makes sense, and thanks for responding …can you include bit of code or point me to an existing extension that does this to get me started?

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.
Basically, there is no default for the field format field due to a change in field type. So- the field now must have a value- either via the select or a hidden field- when it’s submitted. That help at all?

Robin, in the process of making the MD Markitup extension, I learned quite a bit, and the most important thing was that a custom field basically is a blank slate. There is no formatting menu, etc, meaning that I can do whatever I want on the publish/edit pages, which is good and bad. I was trying to get formatting to work with MD Markitup (I have a whole other thread about this called Has anyone written a custom field extension that uses the formatting dropdown). I got the formatting field to show up for my extension, but it would never update the DB with the new value when changing it and saving the entry. I don’t know if that’s related to this issue or not, but it seems worth noting, especially for anyone who wants to make EE better by trying to extend it.

Anyway, there have been enough problems around these 3rd party custom field extensions since 1.6.5, that I’m just looking for the easiest way to explicitly set the the formatting on publish/edit pages with a hidden field. Any idea what that exact line of code might look like?

I’ve spent a lot of time in cp.publish.php (see other thread linked above) and the closest thing I can find is something along these lines:

$r .= $DSP->input_hidden('field_ft_'.$row['field_id'], $field_fmt);

To my knowledge, that creates a hidden field setting the format of the entry to the field format (there’s more to it as $field_fmt obviously needs to be set somewhere) but…I’m just looking for a way to make sure MD Markitup doesn’t give people NULLs.

EDIT/ADD: Do you know of any custom field extension that has ever been written that uses field formatting? I need some reference here!

       
gridonic's avatar
gridonic
231 posts
16 years ago
gridonic's avatar gridonic

The entire hook system for custom fields is a pretty big mess if you ask me. There’s no real API for that, you have to deal with entire javascript and html code parsing it by using preg_replace or similar - no way to do this without some serious REGEX kung-fu…

In our URL field extension, we’ve used what already worked in Leevi’s extensions. An URL field certainly does not need any formatting, the solution with EE < 1.6.5 was just to hide id from displaying. The value for that custom field’s format would be NULL in the database and thus have no formatting. The typography class has changed and has now the ‘xhtml’ format by default, which made some of the extensions out there stopped from working, unfortunately.

We tried to display, instead of hide, the formatting field for our custom field. With this, you can set all the existing fields to a format by switching to another and then back to that one you want - however, this solution does not help with setting a formatting for new entries.

Strange and we did not have time so far to look into it, code and database digging to solve such problems take a lot of time :/ As soon as I know more, I’ll sure let you know.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

Peter, if I figure out anything I will report back as well. I really need MD Markitup to work on this next site, and if new entries are going NULL, it won’t cut it. It’s bad enough these fields are being set to NULL from the custom field page itself, let alone trying to change the formatting from the publish/edit screen using a dropdown similar to those underneath the textareas.

In MD Markitup, everything I used initially I got from Leevi’s Extensions, too. I’m getting more info from looking at Leevi’s work than from looking in the docs.

I need to do some more testing, but I need to get client work out the door too. Only so many hours. This shouldn’t be this difficult. I hope extending EE in 2.0 isn’t nearly this tough.

       
gridonic's avatar
gridonic
231 posts
16 years ago
gridonic's avatar gridonic

I feel you, although EE is a wonderful system, everbody who has worked with e.g. Drupal know that extending a CMS can be a bigger pleasure 😊

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

The thing is, there aren’t a lot of real examples of why we’d use a hook, so we have to look to each other’s work, and if one person is wrong, that can cause a chain reaction of add-ons with bad code.

       
gridonic's avatar
gridonic
231 posts
16 years ago
gridonic's avatar gridonic

You’re exactly right, that’s why a real API would make a big difference, but that’s another topic.

Hopefully I’ll have some time tomorrow or begining this week to look into this.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

I’m going to be doing some testing this weekend - hopefully I(we/you/us/everyone) can get to the bottom of this. I can’t stand to not have MD Markitup working!

       
Mark Drzycimski's avatar
Mark Drzycimski
19 posts
16 years ago
Mark Drzycimski's avatar Mark Drzycimski

Thought I’d post this over here too, in case someone else finds it useful. Using the code that Ryan provided above (with a slight modification–$row[‘field_fmt’] instead of $field_fmt):

$r .= $DSP->input_hidden('field_ft_'.$row['field_id'],$row['field_fmt']);

Inserting that into the MD Markitup Extension worked just fine for me. So, if you’re as desperate to have field formatting working in custom field extensions as I am, this may prove to be a temporary solution.

       
timkelty's avatar
timkelty
177 posts
16 years ago
timkelty's avatar timkelty

Thanks, Mark. Going to try it out right now…

       
timkelty's avatar
timkelty
177 posts
16 years ago
timkelty's avatar timkelty

Works for me with MarkitUp in my intial tests. Thanks, Mark. I’m going to see if I can fix LG image/File manager as well

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

I think that line will work (seems to be working on a test 1.6.5 install) but that still doesn’t solve my issue with being able to show the select box dropdown and selecting a new field format from it. I guess I’ll be satisfied with this fix for now - but if anyone has ever made a custom field that allows the user to select field formatting (and your selection actually saves) please let me know. (Or if you know of an extension that already exists that I might not know about)

       
Mark Drzycimski's avatar
Mark Drzycimski
19 posts
16 years ago
Mark Drzycimski's avatar Mark Drzycimski

Ryan -

I was just futzing around before I left work, but now I’ve got to run and I thought I’d throw this your direction in case it would help. I think the following code would get you want you’re looking for, once it’s completed:

$q = $DB->query("SELECT field_fmt AS format FROM exp_field_formatting WHERE field_id = {$row['field_id']};");
$q = $DB->query("SELECT field_fmt AS default_format FROM exp_weblog_fields WHERE field_id = {$row['field_id']};");
$r .= $DSP->input_select_header('field_ft_'.$row['field_id']);
foreach($fmt_opt as $fmt) {
    $sel = ($def_fmt == $fmt)? 1: '';
    $r .= $DSP->input_select_option($fmt,$fmt,$sel);
}
$r .= $DSP->input_select_footer();

You’d need to finish it off, of course, as I’m not doing anything with the query results yet.

       
1 2 3

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.