public function CommerceEntityViewsData::getViewsData in Commerce Core 8.2
Returns views data for the entity type.
Return value
array Views data in the format of hook_views_data().
Overrides EntityViewsData::getViewsData
1 call to CommerceEntityViewsData::getViewsData()
- OrderItemViewsData::getViewsData in modules/
order/ src/ OrderItemViewsData.php - Returns views data for the entity type.
1 method overrides CommerceEntityViewsData::getViewsData()
- OrderItemViewsData::getViewsData in modules/
order/ src/ OrderItemViewsData.php - Returns views data for the entity type.
File
- src/
CommerceEntityViewsData.php, line 66
Class
- CommerceEntityViewsData
- Provides improvements to core's generic views integration for entities.
Namespace
Drupal\commerceCode
public function getViewsData() {
$data = parent::getViewsData();
$this->tableMapping = $this->storage
->getTableMapping();
$entity_type_id = $this->entityType
->id();
// Workaround for core issue #3004300.
if ($this->entityType
->isRevisionable()) {
$revision_table = $this->tableMapping
->getRevisionTable();
$data[$revision_table]['table']['entity revision'] = TRUE;
}
// Add missing reverse relationships. Workaround for core issue #2706431.
$base_fields = $this->entityFieldManager
->getBaseFieldDefinitions($entity_type_id);
$entity_reference_fields = array_filter($base_fields, function (BaseFieldDefinition $field) {
return $field
->getType() === 'entity_reference' && !$field
->isComputed();
});
if (in_array($entity_type_id, [
'commerce_order',
'commerce_product',
])) {
// Product variations and order items have reference fields pointing
// to the parent entity, no need for a reverse relationship.
unset($entity_reference_fields['variations']);
unset($entity_reference_fields['order_items']);
}
$this
->addReverseRelationships($data, $entity_reference_fields);
// Add views integration for bundle plugin fields.
// Workaround for core issue #2898635.
if ($this->entityType
->hasHandlerClass('bundle_plugin')) {
$bundles = $this->entityTypeBundleInfo
->getBundleInfo($entity_type_id);
foreach (array_keys($bundles) as $bundle) {
$field_definitions = $this->entityFieldManager
->getFieldDefinitions($entity_type_id, $bundle);
foreach ($field_definitions as $field_definition) {
if ($field_definition instanceof BundleFieldDefinition) {
$this
->addBundleFieldData($data, $field_definition);
}
}
}
}
// Use custom bundle handlers which know how to handle non-config bundles.
// Workaround for core issue #3056998.
if ($bundle_key = $this->entityType
->getKey('bundle')) {
$base_table = $this
->getViewsTableForEntityType($this->entityType);
$data[$base_table][$bundle_key]['field']['id'] = 'commerce_entity_bundle';
$data[$base_table][$bundle_key]['filter']['id'] = 'commerce_entity_bundle';
}
return $data;
}