V8: how to set image_file attribute to page programmatically?

How can I set an image_file attribute to a page programmatically? I’ve tried this:

$page_thumb_attr = $page->getAttribute('page_thumb');
$fid = is_object($page_thumb_attr) ? $this->getImageID() : 0;
$page_thumb = $fid > 0 ? File::getByID($fid) : null;

if (is_object($page_thumb)) {
    $page->setAttribute('page_thumb', $page_thumb);
}

That doesn’t add the thumbnail to the page. It doesn’t even add the File Manger control button to the page edit. What am I missing?

I got it! That must be a \Concrete\Core\Attribute\Key\CollectionKey::getByHandle(), not a $page->getAttribute()!

$page_thumb_attr = \Concrete\Core\Attribute\Key\CollectionKey::getByHandle('page_thumb');
$fid = is_object($page_thumb_attr) ? $this->getImageID() : 0;
$page_thumb = $fid > 0 ? File::getByID($fid) : null;

if (is_object($page_thumb)) {
    $page->setAttribute('page_thumb', $page_thumb);
}