public function EntityTypeCount::getValue in Open Social 10.1.x
Same name and namespace in other branches
- 8.9 modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/ShareUsageDataPlugin/EntityTypeCount.php \Drupal\social_lets_connect_usage\Plugin\ShareUsageDataPlugin\EntityTypeCount::getValue()
- 8.5 modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/ShareUsageDataPlugin/EntityTypeCount.php \Drupal\social_lets_connect_usage\Plugin\ShareUsageDataPlugin\EntityTypeCount::getValue()
- 8.6 modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/ShareUsageDataPlugin/EntityTypeCount.php \Drupal\social_lets_connect_usage\Plugin\ShareUsageDataPlugin\EntityTypeCount::getValue()
- 8.7 modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/ShareUsageDataPlugin/EntityTypeCount.php \Drupal\social_lets_connect_usage\Plugin\ShareUsageDataPlugin\EntityTypeCount::getValue()
- 8.8 modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/ShareUsageDataPlugin/EntityTypeCount.php \Drupal\social_lets_connect_usage\Plugin\ShareUsageDataPlugin\EntityTypeCount::getValue()
- 10.3.x modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/ShareUsageDataPlugin/EntityTypeCount.php \Drupal\social_lets_connect_usage\Plugin\ShareUsageDataPlugin\EntityTypeCount::getValue()
- 10.0.x modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/ShareUsageDataPlugin/EntityTypeCount.php \Drupal\social_lets_connect_usage\Plugin\ShareUsageDataPlugin\EntityTypeCount::getValue()
- 10.2.x modules/custom/social_lets_connect/modules/social_lets_connect_usage/src/Plugin/ShareUsageDataPlugin/EntityTypeCount.php \Drupal\social_lets_connect_usage\Plugin\ShareUsageDataPlugin\EntityTypeCount::getValue()
Get the value.
Return value
array $json array.
Overrides ShareUsageDataPluginBase::getValue
File
- modules/
custom/ social_lets_connect/ modules/ social_lets_connect_usage/ src/ Plugin/ ShareUsageDataPlugin/ EntityTypeCount.php, line 26
Class
- EntityTypeCount
- Provides a 'EntityTypeCount' share usage data plugin.
Namespace
Drupal\social_lets_connect_usage\Plugin\ShareUsageDataPluginCode
public function getValue() {
$value = [];
$definitions = $this->entityTypeManager
->getDefinitions();
foreach ($definitions as $definition) {
$entity_type_id = $definition
->id();
// We don't need to add config entities.
if ($definition instanceof ConfigEntityType) {
continue;
}
$entity_bundle_info = \Drupal::service('entity_type.bundle.info');
$bundle_info = $entity_bundle_info
->getBundleInfo($entity_type_id);
$bundles = [];
if (count($bundle_info) > 1) {
foreach ($bundle_info as $bundle_id => $bundle_data) {
// Suppress warning about unused variable.
unset($bundle_data);
$keys = $definition
->getKeys();
$bundle_key = $keys['bundle'] === NULL ? 'bundle' : $keys['bundle'];
$query = \Drupal::entityQuery($entity_type_id);
$query
->condition($bundle_key, $bundle_id);
$query
->count();
$count = $query
->execute();
$row = [
'bundle' => $bundle_id,
'count' => $count,
];
$bundles[] = $row;
}
}
$storage = $this->entityTypeManager
->getStorage($entity_type_id);
$query = $storage
->getAggregateQuery();
$query
->count();
$count = $query
->execute();
$entity = [
'entity_type' => $entity_type_id,
'count' => $count,
'bundles' => $bundles,
];
$value[$entity_type_id] = $entity;
}
return $value;
}