You are here

public function GoogleAnalyticsQuery::buildOptionsForm in Google Analytics Reports 8.3

Provide a form to edit options for this plugin.

Overrides PluginBase::buildOptionsForm

File

src/Plugin/views/query/GoogleAnalyticsQuery.php, line 426

Class

GoogleAnalyticsQuery
Defines a Views query class for Google Analytics Reports API.

Namespace

Drupal\google_analytics_reports\Plugin\views\query

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);

  // Load profiles list.
  $profile_list = google_analytics_reports_api_profiles_list();
  $profile_info = '';
  if (isset($profile_list['current_profile'])) {
    $profile_info = parse_url($profile_list['current_profile']->websiteUrl, PHP_URL_HOST) . ' - ' . $profile_list['current_profile']->name . ' (' . $profile_list['current_profile']->id . ')';
  }
  if ($profile_list) {
    $form['reports_profile'] = [
      '#title' => $this
        ->t('Use another reports profile'),
      '#description' => $this
        ->t('This view will use another reports profile rather than system default profile: %profile.', [
        '%profile' => $profile_info,
      ]),
      '#type' => 'checkbox',
      '#default_value' => !empty($this->options['reports_profile']),
    ];
    $form['profile_id'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Reports profile'),
      '#options' => $profile_list['options'],
      '#description' => $this
        ->t('Choose your Google Analytics profile.'),
      '#default_value' => $this->options['profile_id'],
      '#dependency' => [
        'edit-query-options-reports-profile' => '1',
      ],
    ];
  }
}