public function setEntityAttachmentPrivacy(Entity $entity, $new_private = true, $options = []) { //check that the entity privacy can be changed if ($entity->allowsPrivacyChange()) { $f = $entity->getAttachmentDescription(); $new_f = $this->changeUploadedFilePrivacy($f, $new_private); //$new_f is almost certainly the same as $f, but maybe the key or iv have changed //in this very rare case, we may need to modify the entity $entity->attachFile($new_f); } else { //throw an error } return $entity; }