Bolt\Storage\Repository::delete PHP Method

delete() public method

Deletes a single object.
public delete ( object $entity ) : boolean
$entity object The entity to delete.
return boolean
    public function delete($entity)
    {
        $event = new StorageEvent($entity);
        $this->event()->dispatch(StorageEvents::PRE_DELETE, $event);
        $qb = $this->em->createQueryBuilder()->delete($this->getTableName())->where('id = :id')->setParameter('id', $entity->getId());
        $response = $qb->execute();
        $event = new StorageEvent($entity);
        $this->event()->dispatch(StorageEvents::POST_DELETE, $event);
        return $response;
    }

Usage Example

Beispiel #1
0
 /**
  * Execute the deletion of a record.
  *
  * @param Repository $repo
  * @param Content    $entity
  *
  * @return boolean
  */
 protected function deleteRecord(Repository $repo, Content $entity)
 {
     $recordId = $entity->getId();
     $contentTypeName = (string) $entity->getContenttype();
     if (!$this->users->isAllowed("contenttype:{$contentTypeName}:delete:{$recordId}")) {
         $this->loggerFlash->error(Trans::__('general.access-denied.content-not-modified', ['%title%' => $entity->getTitle()]));
         return;
     }
     return $repo->delete($entity);
 }