sites_group_overrides-1.x-dev/src/ParamConverter/EntityConverter.php
src/ParamConverter/EntityConverter.php
<?php
namespace Drupal\sites_group_overrides\ParamConverter;
use Symfony\Component\Routing\Route;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\ParamConverter\ParamConverterInterface;
class EntityConverter implements ParamConverterInterface {
public function __construct(protected ParamConverterInterface $inner) {
}
public function applies($definition, $name, Route $route) {
return $this->inner->applies($definition, $name, $route);
}
public function convert($value, $definition, $name, array $defaults) {
$entity = $this->inner->convert($value, $definition, $name, $defaults);
if ($entity && !$entity->isSyncing() && $entity instanceof ContentEntityInterface && $group_relationship = \Drupal::service('sites_group.service')->getRelationship($entity)) {
$entity = \Drupal::service('sites_group_overrides.service')->syncFieldsToEntity($group_relationship, $entity);
}
return $entity;
}
}