You are here

protected function DefaultUserReferenceHandler::loadReferencedEntity in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Plugin/cms_content_sync/field_handler/DefaultUserReferenceHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultUserReferenceHandler::loadReferencedEntity()
  2. 2.0.x src/Plugin/cms_content_sync/field_handler/DefaultUserReferenceHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultUserReferenceHandler::loadReferencedEntity()

Load the entity that is either referenced or embedded by $definition.

Parameters

$definition:

Return value

\Drupal\Core\Entity\EntityInterface

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

\Drupal\cms_content_sync\Exception\SyncException

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

Overrides EntityReferenceHandlerBase::loadReferencedEntity

File

src/Plugin/cms_content_sync/field_handler/DefaultUserReferenceHandler.php, line 70

Class

DefaultUserReferenceHandler
Providing a minimalistic implementation for any field type.

Namespace

Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler

Code

protected function loadReferencedEntity(PullIntent $intent, $definition) {
  $property = $this->settings['handler_settings']['identification'];
  if (self::IDENTIFICATION_SYNC_USER == $property) {
    $uid = \Drupal::service('keyvalue.database')
      ->get('cms_content_sync_user')
      ->get('uid');
    return User::load($uid);
  }
  if (empty($definition[$property])) {
    return null;
  }

  /**
   * @var \Drupal\user\Entity\User[] $entities
   */
  $entities = \Drupal::entityTypeManager()
    ->getStorage('user')
    ->loadByProperties([
    $property => $definition[$property],
  ]);
  return reset($entities);
}