class Piwik in Analytics 8
Analytics service type.
Plugin annotation
@AnalyticsService(
id = "piwik",
label = @Translation("Piwik"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\analytics\Plugin\ServicePluginBase implements ServicePluginInterface uses PluginDependencyTrait, StringTranslationTrait
- class \Drupal\analytics_piwik\Plugin\AnalyticsService\Piwik
- class \Drupal\analytics\Plugin\ServicePluginBase implements ServicePluginInterface uses PluginDependencyTrait, StringTranslationTrait
Expanded class hierarchy of Piwik
File
- analytics_piwik/
src/ Plugin/ AnalyticsService/ Piwik.php, line 16
Namespace
Drupal\analytics_piwik\Plugin\AnalyticsServiceView source
class Piwik extends ServicePluginBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'url' => '',
'id' => '',
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm($form, FormStateInterface $form_state) {
$form['url'] = [
'#type' => 'textfield',
'#title' => t('URL'),
'#description' => t('The URL to your Piwik base directory.'),
'#default_value' => $this->configuration['url'],
// @todo Add validation
//'#element_validate' => [$this->validateUrl],
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'number',
'#title' => t('Site ID'),
'#default_value' => $this->configuration['id'],
'#min' => 0,
'#required' => TRUE,
'#size' => 15,
];
return $form;
}
function validateUrl($element, &$form_state) {
$value = $element['#value'];
if ($value != '') {
// Make sure the URL is normalized.
$value = rtrim($value, '/') . '/';
form_set_value($element, $value, $form_state);
if (!valid_url($value, TRUE)) {
form_error($element, t('%name is not a valid URL.', [
'%name' => $element['#title'],
]));
}
else {
$request = drupal_http_request($value . '/piwik.js');
}
}
}
/**
* {@inheritdoc}
*/
public function getOutput() {
$output = [];
// This is just placeholder code.
$output['analytics_' . $this
->getServiceId()] = [
'#type' => 'html_tag',
'#tag' => 'piwik',
'#attributes' => [
'src' => $this->configuration['url'],
'site_id' => $this->configuration['id'],
],
];
return $output;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencyTrait:: |
protected | property | The object's dependencies. | |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. | |
Piwik:: |
public | function |
Form constructor. Overrides ServicePluginBase:: |
|
Piwik:: |
public | function |
Gets default configuration for this plugin. Overrides ServicePluginBase:: |
|
Piwik:: |
public | function |
Returns the output of the analytics service. Overrides ServicePluginBase:: |
|
Piwik:: |
function | |||
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginDependencyTrait:: |
protected | function | Calculates and adds dependencies of a specific plugin instance. | 1 |
PluginDependencyTrait:: |
protected | function | Calculates and returns dependencies of a specific plugin instance. | |
PluginDependencyTrait:: |
protected | function | Wraps the module handler. | 1 |
PluginDependencyTrait:: |
protected | function | Wraps the theme handler. | 1 |
ServicePluginBase:: |
protected | property | ||
ServicePluginBase:: |
protected | property | The ID of the service config entity using this plugin. | |
ServicePluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
ServicePluginBase:: |
public | function |
Determines if the current service can track the current request. Overrides ServicePluginInterface:: |
|
ServicePluginBase:: |
public | function | Build an <amp-analytics> tag for output on an amp-enabled page request. | |
ServicePluginBase:: |
public | function |
Overrides ServicePluginInterface:: |
|
ServicePluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ServicePluginBase:: |
public | function |
Returns the label of the analytics service. Overrides ServicePluginInterface:: |
|
ServicePluginBase:: |
public | function |
Gets the current service config entity ID that is using this plugin. Overrides ServicePluginInterface:: |
|
ServicePluginBase:: |
public | function | ||
ServicePluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ServicePluginBase:: |
public | function |
Sets the current service config entity ID that is using this plugin. Overrides ServicePluginInterface:: |
|
ServicePluginBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
ServicePluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
ServicePluginBase:: |
public static | function | Form element validation callback for a JSON textarea field. | |
ServicePluginBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |