abstract class ReportTypeBase in Commerce Reporting 8
Provides the base order report type class.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\commerce_reports\Plugin\Commerce\ReportType\ReportTypeBase implements ReportTypeInterface, ContainerFactoryPluginInterface
Expanded class hierarchy of ReportTypeBase
File
- src/
Plugin/ Commerce/ ReportType/ ReportTypeBase.php, line 14
Namespace
Drupal\commerce_reports\Plugin\Commerce\ReportTypeView source
abstract class ReportTypeBase extends PluginBase implements ReportTypeInterface, ContainerFactoryPluginInterface {
/**
* The order report storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $orderReportStorage;
/**
* Constructs a new ReportTypeBase object.
*
* @param array $configuration
* The plugin configuration, i.e. an array with configuration values keyed
* by configuration option name.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->orderReportStorage = $entity_type_manager
->getStorage('commerce_order_report');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function getLabel() {
return $this->pluginDefinition['label'];
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->pluginDefinition['description'];
}
/**
* {@inheritdoc}
*/
public function buildReportTable(array $results) {
$build = [
'#type' => 'table',
'#header' => $this
->doBuildReportTableHeaders(),
'#rows' => [],
'#empty' => t('No reports yet'),
];
foreach ($results as $result) {
$row = $this
->doBuildReportTableRow($result);
$build['#rows'][] = $row;
}
return $build;
}
/**
* {@inheritdoc}
*/
public function createFromOrder(OrderInterface $order, array $values = []) {
$values += [
'type' => $this
->getPluginId(),
'order_id' => $order
->id(),
'created' => $order
->getPlacedTime(),
];
$order_report = $this->orderReportStorage
->create($values);
$order_report
->save();
}
/**
* Builds the report table headers.
*
* @return array
* The report table headers.
*/
protected abstract function doBuildReportTableHeaders();
/**
* Build the report table row.
*
* @param array $result
* The result row.
*
* @return array
* The table row data.
*/
protected abstract function doBuildReportTableRow(array $result);
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BundlePluginInterface:: |
public | function | Builds the field definitions for entities of this bundle. | 2 |
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. | |
ReportTypeBase:: |
protected | property | The order report storage. | |
ReportTypeBase:: |
public | function |
Build a report table from query results. Overrides ReportTypeInterface:: |
|
ReportTypeBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
2 |
ReportTypeBase:: |
public | function |
Creates a new order report using the given order and values. Overrides ReportTypeInterface:: |
|
ReportTypeBase:: |
abstract protected | function | Builds the report table headers. | 4 |
ReportTypeBase:: |
abstract protected | function | Build the report table row. | 4 |
ReportTypeBase:: |
public | function |
Gets the order report type description. Overrides ReportTypeInterface:: |
|
ReportTypeBase:: |
public | function |
Gets the order report type label. Overrides ReportTypeInterface:: |
|
ReportTypeBase:: |
public | function |
Constructs a new ReportTypeBase object. Overrides PluginBase:: |
2 |
ReportTypeInterface:: |
public | function | Builds the aggregate query. | 4 |
ReportTypeInterface:: |
public | function | Generates order reports for an order. | 4 |