You are here

public function ContentHubEntityLinkFieldHandler::getDependentEntityInfo in Acquia Content Hub 8

Get Dependent entity type id and UUID from the field value item.

Parameters

string $item: The field value item.

Return value

string|null If it matches pattern, returns dependent entity type and UUID; or NULL.

1 call to ContentHubEntityLinkFieldHandler::getDependentEntityInfo()
ContentHubEntityLinkFieldHandler::denormalizeItem in src/ContentHubEntityLinkFieldHandler.php
Converts Entity UUIDs into IDs in a field value item.

File

src/ContentHubEntityLinkFieldHandler.php, line 177

Class

ContentHubEntityLinkFieldHandler
Content Hub Entity Link Field.

Namespace

Drupal\acquia_contenthub

Code

public function getDependentEntityInfo($item) {
  if (!isset($item['uri'])) {
    return NULL;
  }
  $uri_array = explode(':', $item['uri']);
  $allowed_types = [
    'entity',
    'internal',
  ];
  if (!in_array($uri_array[0], $allowed_types)) {
    return NULL;
  }
  $entity_array = explode('/', $uri_array[1]);
  $uuid = array_pop($entity_array);
  if (!Uuid::isValid($uuid)) {
    return NULL;
  }
  $entity_type = implode('_', $entity_array);
  return [
    $entity_type,
    $uuid,
  ];
}