Render attribute with "default" value

Permalink
Hi,

I'm stuck...

I have multiple collection attributes in a block-form.
$ak->render('form');

It saves perfectly and works in my view, but when I want to edit the block I can't seem to load the attribute with the saved values from the block.
I would like to do the following:
$ak->render('form', $my_value);


How do I get this to work?

Best,

Corretje

DeWebmakers
 
mnakalay replied on at Permalink Reply
mnakalay
That should work you just have to make sure you have the proper value.

The proper value is not a string or anything like that, it is a value object for the attribute.

Say your attribute is attached to a Page object $page.
You would do $my_value = $page->getAttributeValueObject($ak);
DeWebmakers replied on at Permalink Reply
DeWebmakers
Hi,

Thanks for answering!

Is there a way that I can "create" the AttributeValueObject based on a string or int?
mnakalay replied on at Permalink Reply
mnakalay
Yes but it's not straightforward because each attribute type has a different value object.

For instance the address attribute has different properties for each part of the address.

The select attribute is a bit of a monster with an option list object and option item objects
DeWebmakers replied on at Permalink Reply
DeWebmakers
Any example code?
I've been trying this for 2 days now, but I can't seem to make it happen... :(

Thanx
mnakalay replied on at Permalink Reply
mnakalay
If you look at any attribute in the core, inside its controller there's a method createAttributeValue($value) that shows you how to do it for each attribute type.

Some are pretty simple like the Boolean attribute and others like the Select attribute are a pain in the neck