Pimcore\Tool\Newsletter::confirm PHP Method

confirm() public method

public confirm ( string $token ) : boolean
$token string
return boolean
    public function confirm($token)
    {
        $object = $this->getObjectByToken($token);
        if ($object) {
            if ($version = $object->getLatestVersion()) {
                $object = $version->getData();
                $object->setPublished(true);
            }
            $object->setNewsletterConfirmed(true);
            $object->save();
            $this->addNoteOnObject($object, "confirm");
            return true;
        }
        return false;
    }

Usage Example

 public function confirmAction()
 {
     $this->enableLayout();
     $this->view->success = false;
     $newsletter = new Newsletter("person");
     // replace "crm" with the class name you have used for your class above (mailing list)
     if ($newsletter->confirm($this->getParam("token"))) {
         $this->view->success = true;
     }
 }