Newscoop\Entity\Repository\TemplateRepository::delete PHP Method

delete() public method

Delete template
public delete ( string $key ) : void
$key string
return void
    public function delete($key)
    {
        $template = $this->findOneBy(array('key' => $this->formatKey($key)));
        if (!empty($template)) {
            $em = $this->getEntityManager();
            $em->remove($template);
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Delete item
  *
  * @param string $key
  * @return void
  * @throws InvalidArgumentException
  */
 public function deleteItem($key)
 {
     if ($this->repository->isUsed($key) || $this->storage->isUsed($key)) {
         throw new \InvalidArgumentException(sprintf("The template object %s is in use and can not be deleted.", $key));
     }
     try {
         $this->storage->deleteItem($key);
         $this->repository->delete($key);
     } catch (\InvalidArgumentException $e) {
         throw new \InvalidArgumentException(sprintf("Can't remove non empty directory '%s'", basename($key)), $e->getCode(), $e);
     }
 }