You are here

class ConfigForm in Devel 8

Same name and namespace in other branches
  1. 8.3 webprofiler/src/Form/ConfigForm.php \Drupal\webprofiler\Form\ConfigForm
  2. 8.2 webprofiler/src/Form/ConfigForm.php \Drupal\webprofiler\Form\ConfigForm
  3. 4.x webprofiler/src/Form/ConfigForm.php \Drupal\webprofiler\Form\ConfigForm

Class ConfigForm

Hierarchy

Expanded class hierarchy of ConfigForm

1 string reference to 'ConfigForm'
webprofiler.routing.yml in webprofiler/webprofiler.routing.yml
webprofiler/webprofiler.routing.yml

File

webprofiler/src/Form/ConfigForm.php, line 15

Namespace

Drupal\webprofiler\Form
View source
class ConfigForm extends ConfigFormBase {

  /**
   * @var \Symfony\Component\HttpKernel\Profiler\Profiler
   */
  private $profiler;

  /**
   * @var array
   */
  private $templates;

  /**
   * @var \Drupal\webprofiler\Profiler\ProfilerStorageManager
   */
  private $storageManager;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.factory'), $container
      ->get('profiler'), $container
      ->get('profiler.storage_manager'), $container
      ->getParameter('data_collector.templates'));
  }

  /**
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   * @param Profiler $profiler
   * @param \Drupal\webprofiler\Profiler\ProfilerStorageManager $storageManager
   * @param array $templates
   */
  public function __construct(ConfigFactoryInterface $config_factory, Profiler $profiler, ProfilerStorageManager $storageManager, $templates) {
    parent::__construct($config_factory);
    $this->profiler = $profiler;
    $this->templates = $templates;
    $this->storageManager = $storageManager;
  }

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('webprofiler.config');
    $form['purge_on_cache_clear'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Purge on cache clear'),
      '#description' => $this
        ->t('Deletes all profiler files during cache clear.'),
      '#default_value' => $config
        ->get('purge_on_cache_clear'),
    ];
    $storages = $this->storageManager
      ->getStorages();
    $form['storage'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Storage backend'),
      '#description' => $this
        ->t('Choose were to store profiler data.'),
      '#options' => $storages,
      '#default_value' => $config
        ->get('storage'),
    ];
    $form['exclude'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Exclude'),
      '#default_value' => $config
        ->get('exclude'),
      '#description' => $this
        ->t('Paths to exclude for profiling. One path per line.'),
    ];
    $form['active_toolbar_items'] = [
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Active toolbar items'),
      '#options' => $this
        ->getCollectors(),
      '#description' => $this
        ->t('Choose which items to show into the toolbar.'),
      '#default_value' => $config
        ->get('active_toolbar_items'),
    ];
    $form['ide_settings'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('IDE settings'),
      '#open' => FALSE,
    ];
    $form['ide_settings']['ide_link'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('IDE link'),
      '#description' => $this
        ->t('IDE link for open files.'),
      '#default_value' => $config
        ->get('ide_link'),
    ];
    $form['ide_settings']['ide_link_remote'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('IDE link remote path'),
      '#description' => $this
        ->t('The path of the remote docroot. Leave blank if the docroot is on the same machine of the IDE. No trailing slash.'),
      '#default_value' => $config
        ->get('ide_link_remote'),
    ];
    $form['ide_settings']['ide_link_local'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('IDE link local path'),
      '#description' => $this
        ->t('The path of the local docroot. Leave blank if the docroot is on the same machine of IDE. No trailing slash.'),
      '#default_value' => $config
        ->get('ide_link_local'),
    ];
    $form['database'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Database settings'),
      '#open' => FALSE,
      '#states' => array(
        'visible' => array(
          array(
            'input[name="active_toolbar_items[database]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      ),
    ];
    $form['database']['query_sort'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Sort query log'),
      '#options' => [
        'source' => 'by source',
        'duration' => 'by duration',
      ],
      '#description' => $this
        ->t('The query table can be sorted in the order that the queries were executed or by descending duration.'),
      '#default_value' => $config
        ->get('query_sort'),
    ];
    $form['database']['query_highlight'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Slow query highlighting'),
      '#description' => $this
        ->t('Enter an integer in milliseconds. Any query which takes longer than this many milliseconds will be highlighted in the query log. This indicates a possibly inefficient query, or a candidate for caching.'),
      '#default_value' => $config
        ->get('query_highlight'),
      '#min' => 0,
    ];
    $storageId = $this
      ->config('webprofiler.config')
      ->get('storage');
    $storage = $this->storageManager
      ->getStorage($storageId);
    $form['purge'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Purge profiles'),
      '#open' => FALSE,
    ];
    $form['purge']['actions'] = [
      '#type' => 'actions',
    ];
    $form['purge']['actions']['purge'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Purge'),
      '#submit' => [
        [
          $this,
          'purge',
        ],
      ],
    ];
    $form['purge']['purge-help'] = [
      '#type' => 'inline_template',
      '#template' => '<div class="form-item">{{ message }}</div>',
      '#context' => [
        'message' => $this
          ->t('Purge %storage profiles.', [
          '%storage' => $storage['title'],
        ]),
      ],
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this
      ->config('webprofiler.config')
      ->set('purge_on_cache_clear', $form_state
      ->getValue('purge_on_cache_clear'))
      ->set('storage', $form_state
      ->getValue('storage'))
      ->set('exclude', $form_state
      ->getValue('exclude'))
      ->set('active_toolbar_items', $form_state
      ->getValue('active_toolbar_items'))
      ->set('ide_link', $form_state
      ->getValue('ide_link'))
      ->set('ide_link_remote', $form_state
      ->getValue('ide_link_remote'))
      ->set('ide_link_local', $form_state
      ->getValue('ide_link_local'))
      ->set('query_sort', $form_state
      ->getValue('query_sort'))
      ->set('query_highlight', $form_state
      ->getValue('query_highlight'))
      ->save();
    parent::submitForm($form, $form_state);
  }

  /**
   * Purges profiles.
   */
  public function purge(array &$form, FormStateInterface $form_state) {
    $this->profiler
      ->purge();
    drupal_set_message($this
      ->t('Profiles purged'));
  }

  /**
   * @return array
   */
  private function getCollectors() {
    $options = [];
    foreach ($this->templates as $template) {

      // drupal collector should not be disabled
      if ($template[0] != 'drupal') {
        $options[$template[0]] = $template[2];
      }
    }
    asort($options);
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  public function getEditableConfigNames() {
    return [
      'webprofiler.config',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigForm::$profiler private property
ConfigForm::$storageManager private property
ConfigForm::$templates private property
ConfigForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
ConfigForm::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
ConfigForm::getCollectors private function
ConfigForm::getEditableConfigNames public function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
ConfigForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
ConfigForm::purge public function Purges profiles.
ConfigForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
ConfigForm::__construct public function Overrides ConfigFormBase::__construct
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.
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.