UPDATE 4: I'm now attempting to duplicate the blocks but I can't seem to load the blocks from the variant config.
$conf = $var_clone->getVariantPlugin()->getConfiguration();
$blocks_config = $conf['blocks'];
foreach ($blocks_config as $uuid => $block_data) {
var_dump($uuid);
var_dump($block_data);
}
Gives me the UUID but I want to actually have an object instead of an array so I can do
$block_clone = $block->createDuplicateBlock();
But I can't seem to get the block object from the UUID. I've even tried loading by the Uuid specifying every type of entity possible like so.
$conf = $var_clone->getVariantPlugin()->getConfiguration();
$blocks_config = $conf['blocks'];
foreach ($blocks_config as $uuid => $bdata) {
foreach (array_keys(\Drupal::entityTypeManager()->getDefinitions()) as $etype) {
$block = \Drupal::service('entity.repository')->loadEntityByUuid($etype, $uuid);
var_dump($block);
}
}
But I get nothing but NULL when trying to print each attempt at loading the entity by the UUID I got from the variant block configuration. Are config entities loaded a different way? Or does the UUID supplied not refer to something that can be loaded?