protected function entityReferenceSearch($value, $entity) {
    if (!is_array($value) && !($value instanceof Traversable)) {
      return false;
    }
    if (!isset($entity)) {
      throw new Exceptions\InvalidParametersException();
    }
    // Get the GUID, if the passed $entity is an object.
    if (is_array($entity)) {
      foreach ($entity as &$curEntity) {
        if (is_object($curEntity)) {
          $curEntity = $curEntity->guid;
        }
      }
      unset($curEntity);
    } elseif (is_object($entity)) {
      $entity = [$entity->guid];
    } else {
      $entity = [(int) $entity];
    }
    if (isset($value[0]) && $value[0] === 'nymph_entity_reference') {
      return in_array($value[1], $entity);
    } else {
      // Search through multidimensional arrays looking for the reference.
      foreach ($value as $curValue) {
        if ($this->entityReferenceSearch($curValue, $entity)) {
          return true;
        }
      }
    }
    return false;
  }