You are here

class NewRelicRpmSettings in New Relic 8

Same name and namespace in other branches
  1. 2.x src/Form/NewRelicRpmSettings.php \Drupal\new_relic_rpm\Form\NewRelicRpmSettings
  2. 2.0.x src/Form/NewRelicRpmSettings.php \Drupal\new_relic_rpm\Form\NewRelicRpmSettings

Provides a settings form to configure the New Relic RPM module.

Hierarchy

Expanded class hierarchy of NewRelicRpmSettings

1 string reference to 'NewRelicRpmSettings'
new_relic_rpm.routing.yml in ./new_relic_rpm.routing.yml
new_relic_rpm.routing.yml

File

src/Form/NewRelicRpmSettings.php, line 12

Namespace

Drupal\new_relic_rpm\Form
View source
class NewRelicRpmSettings extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'new_relic_rpm_settings';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'new_relic_rpm.settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form = [];
    $form['api_key'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('API Key'),
      '#description' => $this
        ->t('Enter your New Relic API key if you wish to view reports and analysis within Drupal.'),
      '#default_value' => $this
        ->config('new_relic_rpm.settings')
        ->get('api_key'),
    ];
    $form['transactions'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Transactions'),
      '#open' => TRUE,
    ];
    $form['transactions']['track_drush'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Drush transactions'),
      '#description' => $this
        ->t('How do you wish New Relic to track drush commands?'),
      '#options' => [
        'ignore' => $this
          ->t('Ignore completely'),
        'bg' => $this
          ->t('Track as background tasks'),
        'norm' => $this
          ->t('Track normally'),
      ],
      '#default_value' => $this
        ->config('new_relic_rpm.settings')
        ->get('track_drush'),
    ];
    $form['transactions']['track_cron'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Cron transactions'),
      '#description' => $this
        ->t('How do you wish New Relic to track cron tasks?'),
      '#options' => [
        'ignore' => $this
          ->t('Ignore completely'),
        'bg' => $this
          ->t('Track as background tasks'),
        'norm' => $this
          ->t('Track normally'),
      ],
      '#default_value' => $this
        ->config('new_relic_rpm.settings')
        ->get('track_cron'),
    ];
    $roles = user_role_names();
    $form['transactions']['ignore_roles'] = [
      '#type' => 'select',
      '#multiple' => TRUE,
      '#title' => $this
        ->t('Ignore roles'),
      '#description' => $this
        ->t('Select roles that you wish to be ignored on the New Relic dashboards. Any user with at least one of the selected roles will be ignored.'),
      '#options' => $roles,
      '#default_value' => $this
        ->config('new_relic_rpm.settings')
        ->get('ignore_roles'),
    ];
    $form['transactions']['ignore_urls'] = [
      '#type' => 'textarea',
      '#wysiwyg' => FALSE,
      '#title' => $this
        ->t('Ignore URLs'),
      '#description' => $this
        ->t('Enter URLs you wish New Relic to ignore. Enter one URL per line.'),
      '#default_value' => $this
        ->config('new_relic_rpm.settings')
        ->get('ignore_urls'),
    ];
    $form['transactions']['bg_urls'] = [
      '#type' => 'textarea',
      '#wysiwyg' => FALSE,
      '#title' => $this
        ->t('Background URLs'),
      '#description' => $this
        ->t('Enter URLs you wish to have tracked as background tasks. Enter one URL per line.'),
      '#default_value' => $this
        ->config('new_relic_rpm.settings')
        ->get('bg_urls'),
    ];
    $form['transactions']['exclusive_urls'] = [
      '#type' => 'textarea',
      '#wysiwyg' => FALSE,
      '#title' => $this
        ->t('Exclusive URLs'),
      '#description' => $this
        ->t('Enter URLs you wish to exclusively track. This is useful for debugging specific issues. **NOTE** Entering URLs here effectively marks all other URLs as ignored. Leave blank to disable.'),
      '#default_value' => $this
        ->config('new_relic_rpm.settings')
        ->get('exclusive_urls'),
    ];
    $form['error'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Error analytics'),
      '#open' => TRUE,
    ];
    $form['error']['watchdog_severities'] = [
      '#type' => 'select',
      '#multiple' => TRUE,
      '#title' => $this
        ->t('Forward watchdog messages'),
      '#description' => $this
        ->t('Select which watchdog severities should be forwarded to New Relic API as errors.'),
      '#options' => RfcLogLevel::getLevels(),
      '#default_value' => $this
        ->config('new_relic_rpm.settings')
        ->get('watchdog_severities'),
    ];
    $form['error']['override_exception_handler'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Override exception handler'),
      '#description' => $this
        ->t('Check to override default Drupal exception handler and to have exceptions passed to New Relic.'),
      '#default_value' => $this
        ->config('new_relic_rpm.settings')
        ->get('override_exception_handler'),
    ];
    $form['deployment'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Deployments'),
      '#open' => TRUE,
    ];
    $form['deployment']['module_deployment'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Track module activation as deployment'),
      '#description' => $this
        ->t('Turning this on will create a "deployment" on the New Relic dashboard each time a module is installed or uninstalled. This will help you track before and after statistics.'),
      '#options' => [
        1 => $this
          ->t('Enable'),
        0 => $this
          ->t('Disable'),
      ],
      '#default_value' => (int) $this
        ->config('new_relic_rpm.settings')
        ->get('module_deployment'),
    ];
    $form['deployment']['config_import'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Track configuration imports as deployment'),
      '#description' => $this
        ->t('Turning this on will create a "deployment" on the New Relic dashboard each time a set of configuration is imported. This will help you track before and after statistics.'),
      '#options' => [
        1 => $this
          ->t('Enable'),
        0 => $this
          ->t('Disable'),
      ],
      '#default_value' => (int) $this
        ->config('new_relic_rpm.settings')
        ->get('config_import'),
    ];
    $form['browser'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Browser'),
      '#open' => TRUE,
    ];
    $form['browser']['disable_autorum'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Disable AutoRUM'),
      '#description' => $this
        ->t('Check to disable the automatic real user monitoring inserted by a New Relic transaction.'),
      '#default_value' => $this
        ->config('new_relic_rpm.settings')
        ->get('disable_autorum'),
    ];
    $form['insights'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Insights'),
      '#open' => TRUE,
    ];
    $form['insights']['views_log_slow'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Track slow views'),
      '#description' => $this
        ->t('Check if you want to log slow views in New Relic as custom events.'),
      '#default_value' => $this
        ->config('new_relic_rpm.settings')
        ->get('views_log_slow'),
    ];
    $form['insights']['views_log_threshold'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Slow view threshold'),
      '#field_suffix' => 'ms',
      '#description' => $this
        ->t('The amount of time in milliseconds before a slow view event is logged in New Relic.'),
      '#default_value' => $this
        ->config('new_relic_rpm.settings')
        ->get('views_log_threshold'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = $this
      ->config('new_relic_rpm.settings');
    $variables = [
      'api_key',
      'track_drush',
      'track_cron',
      'ignore_roles',
      'ignore_urls',
      'bg_urls',
      'exclusive_urls',
      'watchdog_severities',
      'override_exception_handler',
      'module_deployment',
      'config_import',
      'views_log_slow',
      'views_log_threshold',
      'disable_autorum',
    ];
    foreach ($variables as $variable) {
      $config
        ->set($variable, $form_state
        ->getValue($variable));
    }
    $config
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 11
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
NewRelicRpmSettings::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
NewRelicRpmSettings::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
NewRelicRpmSettings::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
NewRelicRpmSettings::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.