Skip to content
Snippets Groups Projects

Add bundle and delta to field label in diff interface.

3 unresolved threads
Files
2
+ 13
1
@@ -7,6 +7,7 @@ namespace Drupal\diff;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Language\LanguageInterface;
/**
@@ -16,6 +17,7 @@ class DiffEntityParser {
protected ImmutableConfig $config;
protected ImmutableConfig $pluginsConfig;
protected EntityTypeBundleInfoInterface $entityTypeBundleInfo;
/**
* Constructs a DiffEntityParser object.
@@ -23,9 +25,11 @@ class DiffEntityParser {
public function __construct(
protected DiffBuilderManager $diffBuilderManager,
ConfigFactoryInterface $config_factory,
EntityTypeBundleInfoInterface $entityTypeBundleInfo,
) {
$this->config = $config_factory->get('diff.settings');
$this->pluginsConfig = $config_factory->get('diff.plugins');
$this->entityTypeBundleInfo = $entityTypeBundleInfo;
}
/**
@@ -65,11 +69,19 @@ class DiffEntityParser {
// Create the array with the fields of the entity. Recursive if the
// field contains entities.
if ($plugin instanceof FieldReferenceInterface) {
$bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
$delta = 1;
foreach ($plugin->getEntitiesToDiff($field_items) as $reference_entity) {
foreach ($this->parseEntity($reference_entity) as $key => $build) {
$result[$key] = $build;
$result[$key]['label'] = $field_items->getFieldDefinition()->getLabel() . ' > ' . $result[$key]['label'];
$result[$key]['label'] = \sprintf('%s > %s[%d] > %s',
$field_items->getFieldDefinition()->getLabel(),
$bundle_info[$reference_entity->getEntityTypeId()][$reference_entity->bundle()]['label'] ?? $reference_entity->bundle(),
$delta,
$result[$key]['label'],
);
}
$delta++;
}
}
else {
Loading