Commit d7773787 authored by Ide Braakman's avatar Ide Braakman
Browse files

Issue #3304294: Update code to follow Drupal coding standards

parent a00c097d
Loading
Loading
Loading
Loading
+12 −29
Original line number Diff line number Diff line
@@ -2,35 +2,14 @@

namespace Drupal\piwik_pro\Form;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Configure Piwik Pro settings for this site.
 */
class PiwikProAdminSettingsForm extends ConfigFormBase {

  /**
   * The constructor method.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   */
  public function __construct(ConfigFactoryInterface $config_factory) {
    parent::__construct($config_factory);
  }

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

  /**
   * {@inheritdoc}
   */
@@ -62,14 +41,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
F.e.: <code>https://yourname.<strong>containers</strong>.piwik.pro/</code> or
<code>https://yourname.piwik.pro/<strong>containers</strong></code>. Always end with a slash (/).'),
      '#default_value' => $config->get('piwik_domain'),
      '#required' => true,
      '#required' => TRUE,
    ];
    $form['general']['site_id'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Site ID'),
      '#description' => $this->t('The ID for your site in Piwik Pro. <a href=":piwik_help_url" target="_blank">Where to find it?</a>', [':piwik_help_url' => 'https://help.piwik.pro/support/questions/find-website-id/']),
      '#default_value' => $config->get('site_id'),
      '#required' => true,
      '#required' => TRUE,
    ];
    $form['general']['sync_snippet'] = [
      '#type' => 'checkbox',
@@ -84,7 +63,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
Rename the data layer if you use other data layers to prevent interference.
<a href=":piwik_help_datalayer" target="_blank">How to check it?</a>', [':piwik_help_datalayer' => 'https://developers.piwik.pro/en/latest/tag_manager/data_layer_name.html#data-layer-name-guidelines']),
      '#default_value' => $config->get('data_layer'),
      '#required' => true,
      '#required' => TRUE,
    ];

    $form['tracking'] = [
@@ -106,7 +85,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
      '#title' => $this->t('Pages'),
      '#title_display' => 'invisible',
      '#default_value' => !empty($visibility_request_path_pages) ? $visibility_request_path_pages : '',
      '#description' => $this->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", ['%blog' => '/blog', '%blog-wildcard' => '/blog/*', '%front' => '<front>']),
      '#description' => $this->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", [
        '%blog' => '/blog',
        '%blog-wildcard' => '/blog/*',
        '%front' => '<front>',
      ]),
      '#rows' => 10,
    ];

+11 −0
Original line number Diff line number Diff line
@@ -13,21 +13,29 @@
class PiwikProSnippet {

  /**
   * The Piwiki Pro configuration object with original configuration data.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $config;

  /**
   * The alias manager service.
   *
   * @var \Drupal\path_alias\AliasManagerInterface
   */
  private $aliasManager;

  /**
   * The path matcher service.
   *
   * @var \Drupal\Core\Path\PathMatcherInterface
   */
  private $pathMatcher;

  /**
   * The current path for the current request.
   *
   * @var \Drupal\Core\Path\CurrentPathStack
   */
  private $currentPath;
@@ -41,6 +49,8 @@ class PiwikProSnippet {
   *   The alias manager service.
   * @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
   *   The path matcher service.
   * @param \Drupal\Core\Path\CurrentPathStack $current_path
   *   The current path for the current request.
   */
  public function __construct(ConfigFactoryInterface $configFactory, AliasManagerInterface $alias_manager, PathMatcherInterface $path_matcher, CurrentPathStack $current_path) {
    $this->config = $configFactory->get('piwik_pro.settings');
@@ -163,4 +173,5 @@ public function getVisibilityPages() {
    }
    return $page_match;
  }

}
+4 −3
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ class PiwikProSnippetTest extends BrowserTestBase {
  protected $defaultTheme = 'stark';

  /**
   * The Piwiki Pro configuration object with original configuration data.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $config;
@@ -99,8 +101,7 @@ public function testPiwikProHelp() {
  }

  /**
   * Test if the snippet shows with setting "Show on all pages except listed",
   * and without sync-snippet.
   * Tests setting "Show on all pages except listed" without sync-snippet.
   */
  public function testSnippetVisibility() {
    // Default should show on the homepage.
@@ -209,7 +210,7 @@ public function testSettingsForm() {

    $edit = [
      'site_id' => '0',
      'data_layer' => '0'
      'data_layer' => '0',
    ];
    $this->submitForm($edit, $this->t('Save configuration'));
    $this->assertSession()->responseContains($this->t('Invalid <code>Site ID</code> value.'));