Contact.php in Production check & Production monitor 8
File
src/Plugin/ProdCheck/Modules/Contact.php
View source
<?php
namespace Drupal\prod_check\Plugin\ProdCheck\Modules;
use Drupal\contact\Entity\ContactForm;
use Drupal\prod_check\Plugin\ProdCheck\ProdCheckBase;
class Contact extends ProdCheckBase {
public $matches;
public function init() {
$forms = \Drupal::entityTypeManager()
->getStorage('contact_form')
->getQuery()
->condition('status', 1)
->execute();
$this->matches = [];
$prod_check_sitemail = $this->configFactory
->get('prod_check.settings')
->get('site_email');
foreach ($forms as $form) {
$entity = ContactForm::load($form);
if ($entity) {
foreach ($entity
->getRecipients() as $mail) {
if (preg_match('/' . $prod_check_sitemail . '/i', $mail)) {
$this->matches[] = '"' . $entity
->label() . ': ' . $mail . '"';
}
}
}
}
}
public function state() {
return empty($this->matches);
}
public function successMessages() {
return [
'value' => $this
->t('Contact e-mail addresses are OK.'),
'description' => $this
->t('Your settings are OK for production use.'),
];
}
public function failMessages() {
return [
'value' => $this
->t('Dangerous contact e-mail addresses are %categories', [
'%categories' => implode(',', $this->matches),
]),
'description' => $this
->generateDescription($this
->title(), 'entity.contact_form.collection', 'The %link recipient e-mail addresses should not be development addresses on production sites!'),
];
}
}