Closed bleepsandblops closed 2 weeks ago
It's honestly probably a tad overkill to do all this for Vizy, which after all is just JSON data. The only real benefit of doing things this way is for fields to be able to dictate how to save content, but if you're just looking to copy data over from one field to another, that's pretty basic for Vizy.
Assume you have the following content for your Vizy field:
[
{
"type":"vizyBlock",
"attrs":{
"id":"vizy-block-7BQx04FPZ5",
"enabled":true,
"collapsed":false,
"values":{
"type":"new31-8105",
"content":{
"fields":{
"myDropdownField":"some-value"
}
}
}
}
}
]
It really is a matter of just adding the content to the other Dropdown field in your Vizy Block Type definition.
@engram-design thanks for getting back so quickly. I'm not sure I follow, are you saying I should go in the db and manually modify the JSON? Because I need to do this for dozens of entries.
NB: If the context is relevant, it's because the client wants to change the default value for "original dropdown" but I'm using that dropdown in other types of nodes where I don't want to change the default.
You can still do what you're doing programmatically, I'm just saying you don't need to dive into the individual Vizy Block fields. It's note quite clear from your example what the Vizy field is, but something along the lines of:
$entry = Entry::find()->one();
$vizyContent = $entry->vizyFieldHandle->getRawNodes();
// Make your changes to the JSON content
// ...
$entry->setFieldValue('vizyFieldHandle', $vizyContent);
Craft::$app->getElements()->saveElement($entry);
@engram-design thank you, my Vizy field is within a Supertable block (in my example above contentSuper
is the Supertable block and blocks
is my Vizy field) so am trying to get this to work like in your example but struggling a bit.
EDIT: realised I can save the super table block directly like an entry and it seems to work thank you
Ah, yes then if it's a Super Table (or Matrix), you've just got an extra step where you get the content on the block, and save the block instead of the entry itself, as that's the "owner" of the content.
Question
I'm hoping to modify some fields within a Vizy node programatically. See below what I've tried, it's just copying the value of a dropdown into another dropdown:
Am I going anywhere with this?
Thank you!
Additional context
Vizy 2.1.9 Craft 4.10.0