Elgg\EntityIconService::saveIconFromElggFile PHP Method

saveIconFromElggFile() public method

Saves icons using a file located in the data store as the source.
public saveIconFromElggFile ( ElggEntity $entity, ElggFile $file, string $type = 'icon', array $coords = [] ) : boolean
$entity ElggEntity Entity to own the icons
$file ElggFile An ElggFile instance
$type string The name of the icon. e.g., 'icon', 'cover_photo'
$coords array An array of cropping coordinates x1, y1, x2, y2
return boolean
    public function saveIconFromElggFile(ElggEntity $entity, ElggFile $file, $type = 'icon', array $coords = array())
    {
        if (!$file->exists()) {
            throw new InvalidParameterException(__METHOD__ . ' expects an instance of ElggFile with an existing file on filestore');
        }
        $tmp_filename = time() . pathinfo($file->getFilenameOnFilestore(), PATHINFO_BASENAME);
        $tmp = new ElggFile();
        $tmp->owner_guid = $entity->guid;
        $tmp->setFilename("tmp/{$tmp_filename}");
        $tmp->open('write');
        $tmp->close();
        copy($file->getFilenameOnFilestore(), $tmp->getFilenameOnFilestore());
        $tmp->mimetype = (new MimeTypeDetector())->getType($tmp->getFilenameOnFilestore(), $file->getMimeType());
        $tmp->simpletype = elgg_get_file_simple_type($tmp->mimetype);
        $result = $this->saveIcon($entity, $tmp, $type, $coords);
        $tmp->delete();
        return $result;
    }