Newscoop\Service\Template::fetchMetadata PHP Method

fetchMetadata() public method

Fetch item metadata
public fetchMetadata ( string $key ) : object
$key string
return object
    public function fetchMetadata($key)
    {
        $item = $this->storage->getItem($key);
        $metadata = array('key' => $item->getKey(), 'name' => $item->getName(), 'type' => $item->getType(), 'realpath' => $this->storage->getRealpath($key));
        if (!$item->isDir()) {
            $metadata += array('size' => $item->getSize(), 'ctime' => $item->getChangeTime());
            if ($metadata['type'] == 'tpl') {
                $template = $this->repository->getTemplate($key, false);
                // get the resource for the template id
                $resource = $this->syncResServ->findByPathOrId(rtrim($this->theme->getPath(), "/") . "/" . ltrim($key, "/"));
                /* @var $resource Newscoop\Entity\Resource */
                $metadata += array('id' => is_object($resource) ? $resource->getId() : $template->getId(), 'ttl' => $template->getCacheLifetime());
            }
        }
        return (object) $metadata;
    }

Usage Example

 public function editImageAction()
 {
     $key = $this->getKey();
     $this->view->item = $this->service->fetchMetadata($key);
 }