class DevelopmentEnvironmentController in Development Environment 8
The DevelopmentEnvironmentController class.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\development_environment\Controller\DevelopmentEnvironmentController implements DevelopmentEnvironmentControllerInterface
Expanded class hierarchy of DevelopmentEnvironmentController
File
- src/
Controller/ DevelopmentEnvironmentController.php, line 19
Namespace
Drupal\development_environment\ControllerView source
class DevelopmentEnvironmentController extends ControllerBase implements DevelopmentEnvironmentControllerInterface {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* The variable dump service.
*
* @var \Drupal\development_environment\Service\VarDumpServiceInterface
*/
protected $varDumpService;
/**
* The form builder service.
*
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
/**
* Constructs a DevelopmentEnvironmentController object.
*
* @param \Drupal\Core\Database\Connection $database
* The datagbase connection.
* @param \Drupal\Core\Datetime\DateFormatterInterface $dateFormatter
* The date formatter service.
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user.
* @param \Drupal\development_environment\Service\VarDumpServiceInterface $varDumpService
* The variable dump service.
* @param \Drupal\Core\Form\FormBuilderInterface $formBuilder
* The form builder interface.
*/
public function __construct(Connection $database, DateFormatterInterface $dateFormatter, AccountProxyInterface $currentUser, VarDumpServiceInterface $varDumpService, FormBuilderInterface $formBuilder) {
$this->database = $database;
$this->dateFormatter = $dateFormatter;
$this->currentUser = $currentUser;
$this->varDumpService = $varDumpService;
$this->formBuilder = $formBuilder;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('database'), $container
->get('date.formatter'), $container
->get('current_user'), $container
->get('development_environment.var.dump.service'), $container
->get('form_builder'));
}
/**
* {@inheritdoc}
*/
public function logListPage() {
$query = $this->database
->select('development_environment_log', 'log_data')
->extend('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender');
$query
->fields('log_data', [
'lid',
'email_data',
'timestamp',
'recipient_email',
'subject',
]);
$log_items = $query
->limit(20)
->orderBy('lid', 'DESC')
->execute();
$page = [
'form' => $this->formBuilder
->getForm('\\Drupal\\development_environment\\Form\\DevelopmentEnvironmentClearLogForm'),
'items' => [
'#theme' => 'table',
'#header' => [
'',
$this
->t('Time'),
$this
->t('Recipient'),
$this
->t('Subject'),
],
'#rows' => [],
'#empty' => $this
->t('No emails have been logged'),
],
'pager' => [
'#type' => 'pager',
],
];
foreach ($log_items as $item) {
$url = Url::fromRoute('development_environment.suppressed_email_log', [
'lid' => $item->lid,
]);
$link = Link::fromTextAndUrl($this
->t('View'), $url);
$page['items']['#rows'][] = [
$link,
$this->dateFormatter
->format($item->timestamp, 'short', '', $this->currentUser
->getTimeZone()),
$item->recipient_email,
$item->subject,
];
}
return $page;
}
/**
* {@inheritdoc}
*/
public function mailLogPage($lid) {
$mail_log = $this->database
->query('SELECT timestamp, email_data FROM {development_environment_log} WHERE lid = :lid', [
':lid' => $lid,
])
->fetch();
if (!$mail_log) {
throw new NotFoundHttpException();
}
$mail_info = unserialize($mail_log->email_data);
if (is_array($mail_info['body'])) {
$body = implode('<br/>', $mail_info['body']);
}
else {
$body = $mail_info['body'];
}
$page = [
'header' => [
'#prefix' => '<h2>',
'#suffix' => '</h2>',
'#markup' => $this
->t('The following email was not sent as this is a development environment'),
],
'email' => [
'#type' => 'details',
'#title' => $this
->t('Email data'),
'#open' => TRUE,
'time' => [
'#prefix' => '<p>',
'#suffix' => '</p>',
'#markup' => $this
->t('Time: %time', [
'%time' => $this->dateFormatter
->format($mail_log->timestamp, 'short', '', $this->currentUser
->getTimeZone()),
]),
],
'recipient' => [
'#prefix' => '<p>',
'#suffix' => '</p>',
'#markup' => $this
->t('Recipient: %recipient', [
'%recipient' => $mail_info['to'],
]),
],
'subject' => [
'#prefix' => '<p>',
'#suffix' => '</p>',
'#markup' => $this
->t('Subject: %subject', [
'%subject' => $mail_info['subject'],
]),
],
'body' => [
'#prefix' => '<div>',
'#suffix' => '</div><br/>',
'#markup' => $this
->t('Body: %body', [
'%body' => $body,
]),
],
'headers' => [
'#prefix' => '<div>',
'#suffix' => '</div>',
'#markup' => $this
->t('Headers:') . $this->varDumpService
->varDump($mail_info['headers'], TRUE, TRUE),
],
],
'raw_mail_data' => [
'#type' => 'details',
'#title' => $this
->t('Raw email data'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'data' => [
'#markup' => $this->varDumpService
->varDump($mail_info, TRUE, TRUE),
],
],
];
return $page;
}
/**
* {@inheritdoc}
*/
public function settingsPage() {
$page = [
'#prefix' => '<div id="development_environment_settings_page">',
'#suffix' => '</div>',
'form' => $this->formBuilder
->getForm('\\Drupal\\development_environment\\Form\\DevelopmentEnvironmentSettingsForm'),
];
return $page;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
DevelopmentEnvironmentController:: |
protected | property |
The current user. Overrides ControllerBase:: |
|
DevelopmentEnvironmentController:: |
protected | property | The database connection. | |
DevelopmentEnvironmentController:: |
protected | property | The date formatter service. | |
DevelopmentEnvironmentController:: |
protected | property |
The form builder service. Overrides ControllerBase:: |
|
DevelopmentEnvironmentController:: |
protected | property | The variable dump service. | |
DevelopmentEnvironmentController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
DevelopmentEnvironmentController:: |
public | function |
Creates the log page listing all email logs. Overrides DevelopmentEnvironmentControllerInterface:: |
|
DevelopmentEnvironmentController:: |
public | function |
Log page for an individual email. Overrides DevelopmentEnvironmentControllerInterface:: |
|
DevelopmentEnvironmentController:: |
public | function |
Settings page for the Development Environment module. Overrides DevelopmentEnvironmentControllerInterface:: |
|
DevelopmentEnvironmentController:: |
public | function | Constructs a DevelopmentEnvironmentController object. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |