code: protected function getEntities($args)
      {
          $dm             = $args->getDocumentManager();
          $resource       = $args->getDocument();
          $repositoryName = $this->getRepositoryName();
          $resourceId     = $resource->getPermissionsResourceId();
          $repository     = $dm->getRepository($repositoryName);
          
          $criteria = array(
              'permissions.assigned.' . $resourceId => array(
                  '$exists' => true
              )
          );
          
          $entities = $repository->findBy($criteria);
  
          return $entities;
      }
docs: Fetch entities from the database which permissions are assigned the referral document.
  
  @param LifecycleEventArgs $args
  
  @return Collection