5.5.2 save error on singlepage editor > custom image attribute, min/max width/height error

Permalink
I've developed a singlepage editor in 5.5.1 and was stoked to get the new simplified image editor in 5.5.2. I upgraded last night and all worked well on my current code, but when I add the min/max height/width the editor works like it should, but I can no longer save the page without it throwing an error.

Prior code for image selector (works great in 5.5.2, no errors saving:
echo $al->image('site_banner', 'site_banner', 'Choose Site Banner', $sitePage->getAttribute('site_banner'));


Updated selector code to set min/max parameters (selector/editor works fine, just can't save, gets an error):
echo $al->image('site_banner', 'site_banner', 'Choose Site Banner', $sitePage->getAttribute('site_banner'), array('minHeight' => '80', 'maxHeight' => '80', 'minWidth' => '80', 'maxWidth' => '1290'));


Error with new code:
Fatal error: Call to a member function setAttribute() on a non-object in /public_html/lpsites/updates/concrete5.5.2/concrete/models/collection.php on line 229

I've checked the collection.php file with the 5.5.1 version, and they're identical.

My controller code to save the attribute:
$fObj = File::getByID($site_banner);
$page->setAttribute(CollectionAttributeKey::getByHandle('site_banner'), $fObj);


Any suggestions would be greatly appreciated.

baryongroup
 
baryongroup replied on at Permalink Reply
baryongroup
Looks like I found my issue. I pass my form array to a function that assembles all the form inputs together to save the posted variables to their respective custom attributes. It appears that adding the array for min/max Height/Width add new form inputs:

Adding this to image selector:
array('minHeight' => '80', 'maxHeight' => '80', 'minWidth' => '80', 'maxWidth' => '1290')


Adds this to the form:
<input type="hidden" class="ccm-file-manager-filter" name="minHeight" value="80">
<input type="hidden" class="ccm-file-manager-filter" name="maxHeight" value="80">
<input type="hidden" class="ccm-file-manager-filter" name="minWidth" value="80">
<input type="hidden" class="ccm-file-manager-filter" name="maxWidth" value="1290">


I just filtered out my those keys with an if/then statement in my controller save function:
if (($key != 'minHeight') && ($key != 'minWidth') && ($key != 'maxHeight') && ($key != 'maxWidth')) {
     //assemble variables > custom attribute fields
}


That did the trick!
baryongroup replied on at Permalink Best Answer Reply
baryongroup
I also had a regular file selector that I added a filter option to filter the filemanager to only display CSS files I had:

echo $al->file('site_custom_color_theme', 'site_custom_color_theme', 'Add Custom Color Theme File', $sitePage->getAttribute('site_custom_color_theme'),array('fExtension'=>'css'));


This added another input to my form:
<input type="hidden" class="ccm-file-manager-filter" name="fExtension" value="css">


I just updated my new if/then statment in my controller save function:
if (($key != 'minHeight') && ($key != 'minWidth') && ($key != 'maxHeight') && ($key != 'maxWidth') && ($key != 'fExtension')) {
     //assemble variables > custom attribute fields
}


I guess since I am using the full form $_POST[] array to assemble the variables to custom attributes, any "extra" inputs that C5 puts in for special functions would have to be filtered out. I've got a lot going on in this single page editor, so I'm glad it was an easy fix!