class EntityReferenceHelper in Entity Share 8.3
Provides helper functions related to Entity reference fields.
Hierarchy
- class \Drupal\entity_share_client\Service\EntityReferenceHelper implements EntityReferenceHelperInterface
Expanded class hierarchy of EntityReferenceHelper
1 file declares its use of EntityReferenceHelper
- EntityParser.php in modules/
entity_share_diff/ src/ Service/ EntityParser.php
1 string reference to 'EntityReferenceHelper'
- entity_share_client.services.yml in modules/
entity_share_client/ entity_share_client.services.yml - modules/entity_share_client/entity_share_client.services.yml
1 service uses EntityReferenceHelper
- entity_share_client.entity_reference_helper in modules/
entity_share_client/ entity_share_client.services.yml - Drupal\entity_share_client\Service\EntityReferenceHelper
File
- modules/
entity_share_client/ src/ Service/ EntityReferenceHelper.php, line 14
Namespace
Drupal\entity_share_client\ServiceView source
class EntityReferenceHelper implements EntityReferenceHelperInterface {
/**
* The entity type definitions.
*
* @var \Drupal\Core\Entity\EntityTypeInterface[]
*/
protected $entityDefinitions;
/**
* Class constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityDefinitions = $entity_type_manager
->getDefinitions();
}
/**
* {@inheritdoc}
*/
public function relationshipHandleable(FieldItemListInterface $field) {
if (!$field instanceof EntityReferenceFieldItemListInterface) {
return static::RELATIONSHIP_NOT_ENTITY_REFERENCE;
}
$relationship_handleable = FALSE;
$settings = $field
->getItemDefinition()
->getSettings();
// Entity reference and Entity reference revisions.
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;
}
/**
* Helper function to check if an entity type id is a user or a config entity.
*
* @param string $entity_type_id
* The entity type id.
*
* @return bool
* TRUE if the entity type is user or a config entity. FALSE otherwise.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityReferenceHelper:: |
protected | property | The entity type definitions. | |
EntityReferenceHelper:: |
protected | function | Helper function to check if an entity type id is a user or a config entity. | |
EntityReferenceHelper:: |
public | function |
Check if a relationship is handleable. Overrides EntityReferenceHelperInterface:: |
|
EntityReferenceHelper:: |
public | function | Class constructor. | |
EntityReferenceHelperInterface:: |
constant | Denotes the entity reference relationship which is handleable. | ||
EntityReferenceHelperInterface:: |
constant | Denotes the relationship which is not entity reference. | ||
EntityReferenceHelperInterface:: |
constant | Denotes the entity reference relationship which is not handleable. |