class NewRelicConfigSubscriber in New Relic 8
Same name and namespace in other branches
- 2.x src/EventSubscriber/NewRelicConfigSubscriber.php \Drupal\new_relic_rpm\EventSubscriber\NewRelicConfigSubscriber
- 2.0.x src/EventSubscriber/NewRelicConfigSubscriber.php \Drupal\new_relic_rpm\EventSubscriber\NewRelicConfigSubscriber
Config event listener to mark deployments when a user imports configuration.
Hierarchy
- class \Drupal\new_relic_rpm\EventSubscriber\NewRelicConfigSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses StringTranslationTrait
Expanded class hierarchy of NewRelicConfigSubscriber
1 string reference to 'NewRelicConfigSubscriber'
1 service uses NewRelicConfigSubscriber
File
- src/
EventSubscriber/ NewRelicConfigSubscriber.php, line 16
Namespace
Drupal\new_relic_rpm\EventSubscriberView source
class NewRelicConfigSubscriber implements EventSubscriberInterface {
use StringTranslationTrait;
/**
* New Relic adapter.
*
* @var \Drupal\new_relic_rpm\ExtensionAdapter\NewRelicAdapterInterface
*/
protected $adapter;
/**
* The configuration for the New Relic module.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* The current user account.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Constructs a NewRelicConfigSubscriber.
*
* @param \Drupal\new_relic_rpm\ExtensionAdapter\NewRelicAdapterInterface $adapter
* The Adapter that we use to talk to the New Relic extension.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The object we use to get our settings.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The currently logged in user.
*/
public function __construct(NewRelicAdapterInterface $adapter, ConfigFactoryInterface $config_factory, AccountInterface $current_user) {
$this->adapter = $adapter;
$this->config = $config_factory
->get('new_relic_rpm.settings');
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[ConfigEvents::IMPORT][] = [
'onImport',
];
return $events;
}
/**
* Attempts to create a deployment on New Relic when a config import happens.
*
* @param \Drupal\Core\Config\ConfigImporterEvent $event
* The current config event that we are responding to.
*/
public function onImport(ConfigImporterEvent $event) {
if (!$this->config
->get('config_import')) {
return;
}
$changes = $event
->getChangelist();
$name = $this->currentUser
->getAccountName();
$description = $this
->t('A configuration import was run on the site.');
$changelog = '';
if (!empty($changes['create'])) {
$changelog .= 'Configurations created:
';
foreach ($changes['create'] as $config_key) {
$changelog .= $config_key . '
';
}
}
if (!empty($changes['update'])) {
$changelog .= 'Configurations updated:
';
foreach ($changes['update'] as $config_key) {
$changelog .= $config_key . '
';
}
}
if (!empty($changes['delete'])) {
$changelog .= 'Configurations deleted:
';
foreach ($changes['delete'] as $config_key) {
$changelog .= $config_key . '
';
}
}
if (!empty($changes['rename'])) {
$changelog .= 'Configurations renamed:
';
foreach ($changes['rename'] as $config_key) {
$changelog .= $config_key . '
';
}
}
/** @var \Drupal\new_relic_rpm\Client\NewRelicApiClient $client */
$client = \Drupal::service('new_relic_rpm.client');
$client
->createDeployment('config_import', $description, $name, $changelog);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
NewRelicConfigSubscriber:: |
protected | property | New Relic adapter. | |
NewRelicConfigSubscriber:: |
protected | property | The configuration for the New Relic module. | |
NewRelicConfigSubscriber:: |
protected | property | The current user account. | |
NewRelicConfigSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
NewRelicConfigSubscriber:: |
public | function | Attempts to create a deployment on New Relic when a config import happens. | |
NewRelicConfigSubscriber:: |
public | function | Constructs a NewRelicConfigSubscriber. | |
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. |