Skip to content
Snippets Groups Projects
Commit dab25e9f authored by Adam Shepherd's avatar Adam Shepherd
Browse files

Issue #3228605 by AdamPS: Fix Drupal coding standards

parent afc27e44
Branches
Tags
No related merge requests found
Showing
with 142 additions and 47 deletions
......@@ -72,7 +72,7 @@ class MailManagerReplacement extends MailManager {
* The string translation service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
* @param \Drupal\symfony_mailer\EmailFactoryInterface $email_factory;
* @param \Drupal\symfony_mailer\EmailFactoryInterface $email_factory
* The email factory.
* @param \Drupal\symfony_mailer\MailerHelperInterface $mailer_helper
* The mailer helper.
......
......@@ -6,7 +6,6 @@ use Drupal\contact\MessageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\symfony_mailer\EmailFactoryInterface;
use Drupal\symfony_mailer\EmailInterface;
use Drupal\symfony_mailer\Processor\EmailBuilderBase;
/**
* Defines the Email Builder plug-in for contact module personal forms.
......@@ -31,9 +30,9 @@ class ContactEmailBuilder extends ContactEmailBuilderBase {
* The email to modify.
* @param \Drupal\contact\MessageInterface $message
* Submitted message entity.
* @param \Drupal\Core\Session\AccountInterface $account
* @param \Drupal\Core\Session\AccountInterface $sender
* The sender.
* @param \Drupal\Core\Session\AccountInterface $account
* @param \Drupal\Core\Session\AccountInterface $recipient
* The recipient.
*/
public function createParams(EmailInterface $email, MessageInterface $message = NULL, AccountInterface $sender = NULL, AccountInterface $recipient = NULL) {
......
......@@ -9,7 +9,6 @@ use Drupal\symfony_mailer\Processor\EmailBuilderBase;
/**
* Defines a base class for contact module email builders.
* )
*/
class ContactEmailBuilderBase extends EmailBuilderBase {
......
......@@ -36,7 +36,7 @@ class ContactPageEmailBuilder extends ContactEmailBuilderBase {
* The email to modify.
* @param \Drupal\contact\MessageInterface $message
* Submitted message entity.
* @param \Drupal\Core\Session\AccountInterface $account
* @param \Drupal\Core\Session\AccountInterface $sender
* The sender.
*/
public function createParams(EmailInterface $email, MessageInterface $message = NULL, AccountInterface $sender = NULL) {
......
......@@ -5,7 +5,6 @@ namespace Drupal\symfony_mailer_bc\Plugin\EmailBuilder;
use Drupal\Core\Mail\MailManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\symfony_mailer\EmailFactoryInterface;
use Drupal\symfony_mailer\EmailInterface;
use Drupal\symfony_mailer\Exception\SkipMailException;
use Drupal\symfony_mailer\Processor\EmailBuilderBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
......
......@@ -36,7 +36,7 @@ class SimplenewsNewsletterEmailBuilder extends SimplenewsEmailBuilderBase {
* The newsletter issue to send.
* @param \Drupal\simplenews\SubscriberInterface $subscriber
* The subscriber.
* @param bool $test
* @param bool|null $test
* (Optional) TRUE to send a test email.
*/
public function createParams(EmailInterface $email, ContentEntityInterface $issue = NULL, SubscriberInterface $subscriber = NULL, ?bool $test = FALSE) {
......
......@@ -70,7 +70,7 @@ class UpdateEmailBuilder extends EmailBuilderBase {
* {@inheritdoc}
*/
public function import() {
$mail_notification = implode(',',$this->helper()->config()->get('update.settings')->get('notification.emails'));
$mail_notification = implode(',', $this->helper()->config()->get('update.settings')->get('notification.emails'));
if ($mail_notification) {
$notification_policy = $this->helper()->policyFromAddresses($this->helper()->parseAddress($mail_notification));
......
......@@ -21,7 +21,10 @@ class UserRegistrationPasswordEmailBuilder extends UserEmailBuilder {
*/
public function build(EmailInterface $email) {
parent::build($email);
$this->tokenOptions(['callback' => 'user_registrationpassword_mail_tokens', 'clear' => TRUE]);
$this->tokenOptions([
'callback' => 'user_registrationpassword_mail_tokens',
'clear' => TRUE,
]);
}
}
......@@ -13,7 +13,7 @@
*
* @param array $message
* A message array, as described in hook_mail_alter().
* @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
* @param \Drupal\Core\Config\Entity\ConfigEntityInterface|null $entity
* (optional) Entity. @see \Drupal\symfony_mailer\EmailInterface::getEntity()
*
* @see \Drupal\Core\Mail\MailManagerInterface::mail()
......@@ -27,7 +27,7 @@ function hook_mailer_bc_alter(array &$message, ?ConfigEntityInterface $entity) {
*
* @param array $message
* A message array, as described in hook_mail_alter().
* @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
* @param \Drupal\Core\Config\Entity\ConfigEntityInterface|null $entity
* (optional) Entity. @see \Drupal\symfony_mailer\EmailInterface::getEntity()
*/
function hook_mailer_bc_MODULE_alter(array &$message, ?ConfigEntityInterface $entity) {
......
......@@ -2,8 +2,7 @@
/**
* @file
* Install, update and uninstall functions for the Symfony Mailer
* Back-compatibility module.
* Install, functions for the Symfony Mailer Back-compatibility module.
*/
/**
......
......@@ -74,7 +74,11 @@ function symfony_mailer_bc_form_alter(&$form, FormStateInterface $form_state, $f
'type' => 'simplenews',
],
'simplenews_newsletter_edit_form' => [
'remove' => ['email', 'simplenews_sender_information', 'simplenews_subject'],
'remove' => [
'email',
'simplenews_sender_information',
'simplenews_subject',
],
'entity' => 'node',
],
'update_settings' => [
......
......@@ -3,7 +3,6 @@
namespace Drupal\symfony_mailer;
use Drupal\Core\Session\AccountInterface;
use Drupal\simplenews\SubscriberInterface;
use Symfony\Component\Mime\Address as SymfonyAddress;
/**
......@@ -15,10 +14,33 @@ use Symfony\Component\Mime\Address as SymfonyAddress;
*/
class Address implements AddressInterface {
/**
* The email address.
*
* @var string
*/
protected $email;
/**
* The display name, or NULL.
*
* @var string
*/
protected $displayName;
/**
* The language code, or NULL.
*
* @var string
*/
protected $langcode;
protected $address;
/**
* The account, or NULL.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* Constructs an address object.
......@@ -29,14 +51,14 @@ class Address implements AddressInterface {
* (Optional) The display name.
* @param string $langcode
* (Optional) The language code.
* @param \Drupal\Core\Session\AccountInterface $address
* @param \Drupal\Core\Session\AccountInterface $account
* (Optional) The account.
*/
public function __construct(string $email, string $display_name = NULL, string $langcode = NULL, AccountInterface $address = NULL) {
public function __construct(string $email, string $display_name = NULL, string $langcode = NULL, AccountInterface $account = NULL) {
$this->email = $email;
$this->displayName = $display_name;
$this->langcode = $langcode;
$this->account = $address;
$this->account = $account;
}
/**
......@@ -117,4 +139,4 @@ class Address implements AddressInterface {
return $result;
}
};
}
......@@ -15,7 +15,7 @@ interface AddressInterface {
* - \Drupal\symfony_mailer\AddressInterface
* - string
* - \Drupal\Core\Session\AccountInterface
* - \Symfony\Component\Mime\Address
* - \Symfony\Component\Mime\Address.
*
* @return \Drupal\symfony_mailer\AddressInterface
* The address.
......@@ -74,4 +74,4 @@ interface AddressInterface {
*/
public static function convert($addresses);
};
}
......@@ -2,7 +2,6 @@
namespace Drupal\symfony_mailer;
use Drupal\symfony_mailer\AddressInterface;
use Symfony\Component\Mime\Header\Headers;
/**
......@@ -36,7 +35,7 @@ interface BaseEmailInterface {
* Gets the sender address.
*
* @return \Drupal\symfony_mailer\AddressInterface
* The sender address, or NULL if not set.
* The sender address, or NULL if not set.
*/
public function getSender(): ?AddressInterface;
......@@ -190,7 +189,7 @@ interface BaseEmailInterface {
* Valid: after rendering. Email builders should instead call
* EmailInterface::setBody() or related functions before rendering.
*
* @param string $body
* @param string|null $body
* (optional) The HTML body, or NULL to remove the HTML body.
*
* @return $this
......@@ -207,6 +206,7 @@ interface BaseEmailInterface {
*/
public function getHtmlBody(): ?string;
// @codingStandardsIgnoreStart
/**
* @param string $body
*
......@@ -240,6 +240,7 @@ interface BaseEmailInterface {
* @return array|DataPart[]
*/
// public function getAttachments(): array;
// @codingStandardsIgnoreEnd
/**
* Gets the headers object for getting or setting headers.
......@@ -261,4 +262,4 @@ interface BaseEmailInterface {
*/
public function addTextHeader(string $name, string $value);
};
}
......@@ -36,91 +36,149 @@ trait BaseEmailTrait {
*/
protected $sender;
/**
* {@inheritdoc}
*/
public function setSender($address) {
$this->sender = Address::create($address);
return $this;
}
/**
* {@inheritdoc}
*/
public function getSender(): ?AddressInterface {
return $this->sender;
}
/**
* {@inheritdoc}
*/
public function setAddress(string $name, $addresses) {
assert(isset($this->addresses[$name]));
$this->addresses[$name] = Address::convert($addresses);
return $this;
}
/**
* {@inheritdoc}
*/
public function setFrom($addresses) {
return $this->setAddress('From', $addresses);
}
/**
* {@inheritdoc}
*/
public function getFrom(): array {
return $this->addresses['From'];
}
/**
* {@inheritdoc}
*/
public function setReplyTo($addresses) {
return $this->setAddress('Reply-To', $addresses);
}
/**
* {@inheritdoc}
*/
public function getReplyTo(): array {
return $this->addresses['Reply-To'];
}
/**
* {@inheritdoc}
*/
public function setTo($addresses) {
$this->valid(self::PHASE_BUILD);
return $this->setAddress('To', $addresses);
}
/**
* {@inheritdoc}
*/
public function getTo(): array {
return $this->addresses['To'];
}
/**
* {@inheritdoc}
*/
public function setCc($addresses) {
return $this->setAddress('Cc', $addresses);
}
/**
* {@inheritdoc}
*/
public function getCc(): array {
return $this->addresses['Cc'];
}
/**
* {@inheritdoc}
*/
public function setBcc($addresses) {
return $this->setAddress('Bcc', $addresses);
}
/**
* {@inheritdoc}
*/
public function getBcc(): array {
return $this->addresses['Bcc'];
}
/**
* {@inheritdoc}
*/
public function setPriority(int $priority) {
$this->inner->priority($priority);
return $this;
}
/**
* {@inheritdoc}
*/
public function getPriority(): int {
return $this->inner->getPriority();
}
/**
* {@inheritdoc}
*/
public function setTextBody(string $body) {
$this->inner->text($body);
return $this;
}
/**
* {@inheritdoc}
*/
public function getTextBody(): ?string {
return $this->inner->getTextBody();
}
/**
* {@inheritdoc}
*/
public function setHtmlBody(?string $body) {
$this->valid(self::PHASE_POST_RENDER, self::PHASE_POST_RENDER);
$this->inner->html($body);
return $this;
}
/**
* {@inheritdoc}
*/
public function getHtmlBody(): ?string {
$this->valid(self::PHASE_POST_SEND, self::PHASE_POST_RENDER);
return $this->inner->getHtmlBody();
}
// @codingStandardsIgnoreStart
// public function attach(string $body, string $name = null, string $contentType = null);
// public function attachFromPath(string $path, string $name = null, string $contentType = null);
......@@ -132,11 +190,18 @@ trait BaseEmailTrait {
// public function attachPart(DataPart $part);
// public function getAttachments();
// @codingStandardsIgnoreEnd
/**
* {@inheritdoc}
*/
public function getHeaders(): Headers {
return $this->inner->getHeaders();
}
/**
* {@inheritdoc}
*/
public function addTextHeader(string $name, string $value) {
$this->getHeaders()->addTextHeader($name, $value);
return $this;
......
......@@ -31,9 +31,12 @@ class MailerCommands extends DrushCommands {
/**
* Imports legacy config.
*
* @param string $id
* EmailBuilder ID to import.
* @param array $options
* An associative array of options whose values come from cli, aliases,
* config, etc.
*
* @option skip
* Skip the import.
*
......
......@@ -132,7 +132,7 @@ class SymfonyMailerController extends ControllerBase {
/**
* Sets the transport as the default.
*
* @param \Drupal\symfony_mailer\Entity\MailerTransport $mailer_transport
* @param \Drupal\symfony_mailer\MailerTransportInterface $mailer_transport
* The mailer transport entity.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
......
......@@ -59,9 +59,9 @@ class Email implements InternalEmailInterface {
protected $subType;
/**
* @var string
* @var \Drupal\Core\Config\Entity\ConfigEntityInterface
*/
protected $entity_id;
protected $entity;
/**
* Current phase, one of the PHASE_ constants.
......@@ -145,11 +145,11 @@ class Email implements InternalEmailInterface {
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
* The theme manager.
* @param string $type
* Type. @see \Drupal\symfony_mailer\BaseEmailInterface::getType()
* Type. @see self::getType()
* @param string $sub_type
* Sub-type. @see \Drupal\symfony_mailer\BaseEmailInterface::getSubType()
* @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
* (optional) Entity. @see \Drupal\symfony_mailer\BaseEmailInterface::getEntity()
* Sub-type. @see self::getSubType()
* @param \Drupal\Core\Config\Entity\ConfigEntityInterface|null $entity
* (optional) Entity. @see self::getEntity()
*/
public function __construct(MailerInterface $mailer, RendererInterface $renderer, EntityTypeManagerInterface $entity_type_manager, ThemeManagerInterface $theme_manager, string $type, string $sub_type, ?ConfigEntityInterface $entity) {
$this->mailer = $mailer;
......@@ -170,11 +170,11 @@ class Email implements InternalEmailInterface {
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The current service container.
* @param string $type
* Type. @see \Drupal\symfony_mailer\BaseEmailInterface::getType()
* Type. @see self::getType()
* @param string $sub_type
* Sub-type. @see \Drupal\symfony_mailer\BaseEmailInterface::getSubType()
* @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
* (optional) Entity. @see \Drupal\symfony_mailer\BaseEmailInterface::getEntity()
* Sub-type. @see self::getSubType()
* @param \Drupal\Core\Config\Entity\ConfigEntityInterface|null $entity
* (optional) Entity. @see self::getEntity()
*
* @return static
* A new email object.
......@@ -521,11 +521,10 @@ class Email implements InternalEmailInterface {
/**
* Checks that a function was called in the correct phase.
*
* @param int $phase
* The correct phase, one of the PHASE_ constants.
* @param bool $exact
* If TRUE, require the exact phase, if FALSE allow earlier phases (later
* phases for post-render).
* @param int $max_phase
* Latest allowed phase, one of the PHASE_ constants.
* @param int $min_phase
* (Optional) Earliest allowed phase, one of the PHASE_ constants.
*
* @return $this
*/
......
......@@ -84,6 +84,8 @@ class EmailFactory implements EmailFactoryInterface {
*
* @param \Drupal\symfony_mailer\EmailInterface $email
* The email to initialize.
* @param mixed $params
* Parameters for building this email.
*
* @return \Drupal\symfony_mailer\EmailInterface
* The email.
......
......@@ -16,7 +16,7 @@ interface EmailFactoryInterface {
* The module name.
* @param string $sub_type
* Sub-type. @see \Drupal\symfony_mailer\EmailInterface::getSubType()
* @param ... $params
* @param mixed $params
* Parameters for building this email.
*
* @return \Drupal\symfony_mailer\EmailInterface
......@@ -31,7 +31,7 @@ interface EmailFactoryInterface {
* Entity. @see \Drupal\symfony_mailer\EmailInterface::getEntity()
* @param string $sub_type
* Sub-type. @see \Drupal\symfony_mailer\EmailInterface::getSubType()
* @param ... $params
* @param mixed $params
* Parameters for building this email.
*
* @return \Drupal\symfony_mailer\EmailInterface
......@@ -50,7 +50,7 @@ interface EmailFactoryInterface {
* The module name.
* @param string $sub_type
* Sub-type. @see \Drupal\symfony_mailer\EmailInterface::getSubType()
* @param ... $params
* @param mixed $params
* Parameters for building this email.
*
* @return \Drupal\symfony_mailer\EmailInterface
......@@ -69,7 +69,7 @@ interface EmailFactoryInterface {
* Entity. @see \Drupal\symfony_mailer\EmailInterface::getEntity()
* @param string $sub_type
* Sub-type. @see \Drupal\symfony_mailer\EmailInterface::getSubType()
* @param ... $params
* @param mixed $params
* Parameters for building this email.
*
* @return \Drupal\symfony_mailer\EmailInterface
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment