setSubject example

/** * Throws an exception unless the attribute is granted against the current authentication token and optionally * supplied subject. * * @throws AccessDeniedException */
    protected function denyAccessUnlessGranted(mixed $attribute, mixed $subject = null, string $message = 'Access Denied.'): void
    {
        if (!$this->isGranted($attribute$subject)) {
            $exception = $this->createAccessDeniedException($message);
            $exception->setAttributes([$attribute]);
            $exception->setSubject($subject);

            throw $exception;
        }
    }

    /** * Returns a rendered view. * * Forms found in parameters are auto-cast to form views. */
    protected function renderView(string $view, array $parameters = []): string
    {


        if (!array_key_exists('charset', $config)) {
            $config['charset'] = null;
        }
        $mail = new $mailClass($config['charset']);
        if (!$mail instanceof Zend_Mail) {
            throw new Zend_Log_Exception($mail . 'must extend Zend_Mail');
        }

        if (isset($config['subject'])) {
            $mail->setSubject($config['subject']);
        }

        $headerAddresses = array_intersect_key($config, self::$_methodMapHeaders);
        if (count($headerAddresses)) {
            foreach ($headerAddresses as $header => $address) {
                $method = self::$_methodMapHeaders[$header];
                if (is_array($address) && isset($address['name'])
                    && !is_numeric($address['name'])
                ) {
                    $params = array(
                        $address['email'],
                        
$comment->setOwnerId($author_id);

    // Validate the comment's subject. If not specified, extract from comment     // body.     if (trim($comment->getSubject()) == '') {
      if ($comment->hasField('comment_body')) {
        // The body may be in any format, so:         // 1) Filter it into HTML         // 2) Strip out all HTML tags         // 3) Convert entities back to plain-text.         $comment_text = $comment->comment_body->processed;
        $comment->setSubject(Unicode::truncate(trim(Html::decodeEntities(strip_tags($comment_text))), 29, TRUE, TRUE));
      }
      // Edge cases where the comment body is populated only by HTML tags will       // require a default subject.       if ($comment->getSubject() == '') {
        $comment->setSubject($this->t('(No subject)'));
      }
    }
    return $comment;
  }

  /** * {@inheritdoc} */


            if (!$this->authChecker->isGranted($attribute->attribute, $subject)) {
                $message = $attribute->message ?: sprintf('Access Denied by #[IsGranted(%s)] on controller', $this->getIsGrantedString($attribute));

                if ($statusCode = $attribute->statusCode) {
                    throw new HttpException($statusCode$message, code: $attribute->exceptionCode ?? 0);
                }

                $accessDeniedException = new AccessDeniedException($message, code: $attribute->exceptionCode ?? 403);
                $accessDeniedException->setAttributes($attribute->attribute);
                $accessDeniedException->setSubject($subject);

                throw $accessDeniedException;
            }
        }
    }

    public static function getSubscribedEvents(): array
    {
        return [KernelEvents::CONTROLLER_ARGUMENTS => ['onKernelControllerArguments', 20]];
    }

    
$token = $this->tokenStorage->getToken() ?? new NullToken();

        if (!$this->accessDecisionManager->decide($token$attributes$request, true)) {
            throw $this->createAccessDeniedException($request$attributes);
        }
    }

    private function createAccessDeniedException(Request $request, array $attributes): AccessDeniedException
    {
        $exception = new AccessDeniedException();
        $exception->setAttributes($attributes);
        $exception->setSubject($request);

        return $exception;
    }

    public static function getPriority(): int
    {
        return -255;
    }
}
try {
            $mail->setFrom($entry->getSender());
        } catch (RuntimeException $exception) {
            $mail->setFrom(self::INVALID_SENDER_REPLACEMENT_ADDRESS);
        }

        $entry->getRecipients()->map(function D$recipient) use ($mail) {
            $mail->addTo($recipient->getMailAddress());
        });

        if ($entry->getSubject() !== null) {
            $mail->setSubject($entry->getSubject());
        }

        if ($entry->getContentText() !== null) {
            $mail->setBodyText($entry->getContentText());
        }

        if ($entry->getContentHtml() !== null) {
            $mail->setBodyHtml($entry->getContentHtml());
        }

        if ($entry->getType() !== null) {
            
$mailBody = $this->replaceVariables($content['email_template']);
        $mailSubject = $this->replaceVariables($content['email_subject']);

        $receivers = explode(',', $content['email']);
        $receivers = array_map('trim', $receivers);

        $mail->setFrom(Shopware()->Config()->get('Mail'));
        $mail->clearRecipients();
        $mail->addTo($receivers);
        $mail->setBodyText($mailBody);
        $mail->setSubject($mailSubject);

        $mail = Shopware()->Events()->filter('Shopware_Controllers_Frontend_Forms_commitForm_Mail', $mail['subject' => $this]);

        if (!$mail->send()) {
            throw new Enlight_Exception('Could not send mail');
        }
    }

    /** * @param int $formId * * @throws Enlight_Exception * @throws Exception * * @return array */
$this->mailRepository = $entityManager->getRepository(Mail::class);
        $this->orderRepository = $entityManager->getRepository(Order::class);
    }

    /** * {@inheritdoc} */
    public function build(Enlight_Components_Mail $mail): Log
    {
        $logEntry = new Log();

        $logEntry->setSubject((string) iconv_mime_decode((string) $mail->getSubject()));
        $logEntry->setSender($mail->getFrom());
        $logEntry->setSentAt(new DateTime((string) $mail->getDate()));
        $logEntry->setContentText($mail->getPlainBodyText());

        if ($mail->getBodyHtml() instanceof Zend_Mime_Part) {
            $logEntry->setContentHtml($mail->getBodyHtml()->getRawContent());
        }

        $this->assignType($logEntry$mail->getTemplateName());
        $this->assignOrder($logEntry$mail);
        $this->assignShop($logEntry$mail);

        
// Create some comments and attach them to the created node.     for ($i = 0; $i < $this->defaultDisplayResults; $i++) {
      /** @var \Drupal\comment\CommentInterface $comment */
      $comment = Comment::create([
        'status' => CommentInterface::PUBLISHED,
        'field_name' => 'comment',
        'entity_type' => 'node',
        'entity_id' => $this->node->id(),
      ]);
      $comment->setOwnerId(0);
      $comment->setSubject('Test comment ' . $i);
      $comment->comment_body->value = 'Test body ' . $i;
      $comment->comment_body->format = 'full_html';

      // Ensure comments are sorted in ascending order.       $time = REQUEST_TIME + ($this->defaultDisplayResults - $i);
      $comment->setCreatedTime($time);
      $comment->changed->value = $time;

      $comment->save();
    }

    
$body = $this->trackFilter($body$mailing['id']);
                $mail->setBodyHtml($body);
            }
            if (!empty($bodyText)) {
                $bodyText = $this->altFilter($bodyText);
                $mail->setBodyText($bodyText);
            }

            $subject = $template->fetch('string:' . $mailing['subject']$template);

            $mail->clearSubject();
            $mail->setSubject($subject);
            $mail->clearRecipients();
            $mail->addTo($user['email']);
            $mail->setAssociation(NewsletterMailFilter::NEWSLETTER_MAIL, true);
            $validator = $this->container->get(EmailValidator::class);
            if (!$validator->isValid($user['email'])) {
                echo "Skipped invalid email\n";
                // SW-4526                 // Don't `continue` with next iteration without setting user's lastmailing                 // else the mailing.status will never be set to 2                 // and sending the mail will block             } else {
                
$mailData = $this->get('events')->filter(
            'Shopware_Controllers_Order_SendMail_Prepare',
            $mailData,
            [
                'subject' => $this,
                'orderId' => $orderId,
                'mail' => $mail,
            ]
        );

        $mail->setSubject($mailData['subject']);

        $mail->setFrom($mailData['fromMail']$mailData['fromName']);
        $mail->addTo($mailData['to']);

        if ($mailData['isHtml']) {
            $mail->setBodyHtml($mailData['bodyHtml']);
        } else {
            $mail->setBodyText($mailData['bodyText']);
        }
        $mail = $this->addAttachments($mail$orderId$mailData['attachments']);

        
$config = $this->get(\Shopware_Components_Config::class);

        $logLevel = \Monolog\Logger::toMonologLevel($config->get('logMailLevel'));
        $recipients = array_filter(explode("\n", $config->get('logMailAddress')));

        if (\count($recipients) < 1) {
            $recipients[] = $config->get('mail');
        }

        $mailer = new \Enlight_Components_Mail();
        $mailer->addTo($recipients);
        $mailer->setSubject('Error in shop "' . $config->get('shopName') . '".');
        $mailHandler = new EnlightMailHandler($mailer$logLevel);
        $mailHandler->pushProcessor(new ShopwareEnvironmentProcessor());
        $mailHandler->setFormatter(new HtmlFormatter());

        return new BufferHandler($mailHandler, 0, Logger::ERROR);
    }
}
// Create a "Llama" comment.     $comment = Comment::create([
      'comment_body' => [
        'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
        'format' => 'plain_text',
      ],
      'entity_id' => $commented_entity->id(),
      'entity_type' => 'entity_test',
      'field_name' => 'comment',
    ]);
    $comment->setSubject('Llama')
      ->setOwnerId(static::$auth ? $this->account->id() : 0)
      ->setPublished()
      ->setCreatedTime(123456789)
      ->setChangedTime(123456789);
    $comment->save();

    return $comment;
  }

  /** * {@inheritdoc} */
$fromName = $this->getFromName();
                $this->clearFrom();
                $this->setFrom($value$fromName);
                break;
            case 'FromName':
                $from = $this->getFrom();
                $this->clearFrom();
                $this->setFrom($from$value);
                break;
            case 'Subject':
                $this->clearSubject();
                $this->setSubject($value);
                break;
            case 'Body':
                if ($this->_isHtml) {
                    $this->setBodyHtml($value);
                } else {
                    $this->setBodyText($value);
                }
                break;
            case 'AltBody':
                if ($this->_isHtml) {
                    $this->setBodyText($value);
                }

    public function loadValues(Enlight_Components_Mail $mail, Mail $mailModel$overrideConfig = [])
    {
        $stringCompiler = $this->getStringCompiler();

        $subject = $stringCompiler->compileString($mailModel->getSubject());
        if (!empty($subject)) {
            $mail->setSubject($subject);
        }

        if (!empty($overrideConfig['fromMail'])) {
            $fromMail = $overrideConfig['fromMail'];
        } else {
            $fromMail = $stringCompiler->compileString($mailModel->getFromMail());
        }

        if (!empty($overrideConfig['fromName'])) {
            $fromName = $overrideConfig['fromName'];
        } else {
            
Home | Imprint | This part of the site doesn't use cookies.