EntityReferenceHelper.php in Entity Share 8.3
File
modules/entity_share_client/src/Service/EntityReferenceHelper.php
View source
<?php
declare (strict_types=1);
namespace Drupal\entity_share_client\Service;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
use Drupal\Core\Field\FieldItemListInterface;
class EntityReferenceHelper implements EntityReferenceHelperInterface {
protected $entityDefinitions;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityDefinitions = $entity_type_manager
->getDefinitions();
}
public function relationshipHandleable(FieldItemListInterface $field) {
if (!$field instanceof EntityReferenceFieldItemListInterface) {
return static::RELATIONSHIP_NOT_ENTITY_REFERENCE;
}
$relationship_handleable = FALSE;
$settings = $field
->getItemDefinition()
->getSettings();
if (isset($settings['target_type'])) {
$relationship_handleable = !$this
->isUserOrConfigEntity($settings['target_type']);
}
elseif (isset($settings['entity_type_ids'])) {
foreach ($settings['entity_type_ids'] as $entity_type_id) {
$relationship_handleable = !$this
->isUserOrConfigEntity($entity_type_id);
if (!$relationship_handleable) {
break;
}
}
}
return $relationship_handleable ? static::RELATIONSHIP_HANDLEABLE : static::RELATIONSHIP_NOT_HANDLEABLE;
}
protected function isUserOrConfigEntity($entity_type_id) {
if ($entity_type_id == 'user') {
return TRUE;
}
elseif ($this->entityDefinitions[$entity_type_id]
->getGroup() == 'configuration') {
return TRUE;
}
return FALSE;
}
}