ga_reports-8.x-1.0/src/Plugin/views/wizard/GaWizard.php

src/Plugin/views/wizard/GaWizard.php
<?php

namespace Drupal\ga_reports\Plugin\views\wizard;

use Drupal\views\Plugin\views\wizard\WizardPluginBase;

/**
 * Tests creating Google Analytics views with the wizard.
 *
 * @ViewsWizard(
 *   id = "ga_wizard",
 *   base_table = "ga",
 *   title = @Translation("Google Analytics")
 * )
 */
class GaWizard extends WizardPluginBase {

  /**
   * {@inheritdoc}
   */
  public function getAvailableSorts() {
    return [
      'sessions:DESC' => $this->t('Sessions'),
      'users:DESC' => $this->t('Users'),
      'pageviews:DESC' => $this->t('Pageviews'),
      'date:DESC' => $this->t('Date'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function defaultDisplayOptions() {
    $display_options = parent::defaultDisplayOptions();

    // Add permission-based access control.
    $display_options['access']['type'] = 'perm';
    $display_options['access']['options']['perm'] = 'access google analytics reports';

    // Remove the default fields, since we are customizing them here.
    unset($display_options['fields']);

    // Add the title field.
    /* Field: Page tracking: Page Title */
    $display_options['fields']['pageTitle'] = [
      'id' => 'pageTitle',
      'table' => 'ga',
      'field' => 'pageTitle',
      'label' => '',
      'element_label_colon' => FALSE,
    ];

    // Remove the default filters, since we are customizing them here.
    unset($display_options['filters']);

    /* Filter criterion: Google Analytics: Start date of report */
    $display_options['filters']['start_date'] = [
      'id' => 'start_date',
      'table' => 'ga',
      'field' => 'start_date',
      'value' => [
        'type' => 'offset',
        'value' => '-31 day',
      ],
      'group' => 1,
      'expose' => ['operator' => FALSE],
    ];
    /* Filter criterion: Google Analytics: End date of report */
    $display_options['filters']['end_date'] = [
      'id' => 'end_date',
      'table' => 'ga',
      'field' => 'end_date',
      'value' => [
        'type' => 'offset',
        'value' => '-1 day',
      ],
      'group' => 1,
      'expose' => ['operator' => FALSE],
    ];

    return $display_options;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc