Get Asset Information on Creation


(Nic Hubbard) #1

When I am creating a custom asset I would like to be able to write to some of the asset fields that are available for that asset, so that when the asset is created, there is pre-defined information.


In my_asset_edit_fns.inc I am using the processFileUpload() function, and trying to add my extra processing to this. I am sure this is the correct step to take, but I am stuck on how to even set the attributes of fields that have not even been created yet! If they have not been created yet, how is it possible to write info to those fields? Is there some temp that I should write to, and then somehow enter that value after the field is created? Am I missing something there with using the $info array?



I am trying to use:


    $asset->setAttrValue('new_attribute', 'My predefined value');


I normally do this, but since this attribute "new_attribute" has not even been created, there is no way to write to is. What is the way for getting around this problem?

Thanks guys, I really appreciate your help in understanding how Matrix asset creation works. I am really starting to get the basics down, and I am loving it!

(Greg Sherwood) #2

Are you trying to pre-fill fields on the create screen or just set values while the asset is being created so it the fields are populated on the Details screen on that initial load?


If the first, I think you'd have to use a custom function for the field rather than use the built-in offerings.



If the seconds, setAttrValue is the right function to call. Just make sure you return TRUE from your processing function so the asset saves its attributes. You could also try calling $asset->saveAttributes() manually if that doesn't work.


(Huan Nguyen) #3

if you want to have extra attributes for the asset, you would have to declare them in your asset management file, and you can also set the default value for that asset attribute. I don't think you can create a new attribute for the asset which hasn't been defined in the management file (you probably "can" but that's not how it's supposed to be done).


(Nic Hubbard) #4

[quote]Are you trying to pre-fill fields on the create screen or just set values while the asset is being created so it the fields are populated on the Details screen on that initial load?


If the first, I think you'd have to use a custom function for the field rather than use the built-in offerings.



If the seconds, setAttrValue is the right function to call. Just make sure you return TRUE from your processing function so the asset saves its attributes. You could also try calling $asset->saveAttributes() manually if that doesn't work.[/quote]





I am trying to set values while the asset is being created so that the fields are already populated on the Details screen on that initial load.

When trying to do this, I am getting Undefined index for my attributes. Maybe I missed the step of returning TRUE from my processing function…



Huan, sorry if I was not clear. These fields are already defined in my management file, and there will be no static default for these fields, it will be based on the file being updated. :slight_smile:


(Nic Hubbard) #5

Ok, I got it working. I had an error in my code. :slight_smile:


Thanks again.