You are here

public function EntityReferenceHelper::relationshipHandleable in Entity Share 8.3

Check if a relationship is handleable.

Filter on fields not targeting config entities or users.

Parameters

\Drupal\Core\Field\FieldItemListInterface $field: The field item list.

Return value

int One of class constants which describe this relationship field.

Overrides EntityReferenceHelperInterface::relationshipHandleable

File

modules/entity_share_client/src/Service/EntityReferenceHelper.php, line 38

Class

EntityReferenceHelper
Provides helper functions related to Entity reference fields.

Namespace

Drupal\entity_share_client\Service

Code

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;
}