validateEntity example

    else {
      return FALSE;
    }

    $entities = $this->entityTypeManager->getStorage($entity_type)->loadMultiple($ids);
    // Validate each id => entity. If any fails break out and return false.     foreach ($ids as $id) {
      // There is no entity for this ID.       if (!isset($entities[$id])) {
        return FALSE;
      }
      if (!$this->validateEntity($entities[$id])) {
        return FALSE;
      }
    }

    return TRUE;
  }

  /** * Validates an individual entity against class access settings. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity. * * @return bool * True if validated. */

    // If bundles is set then restrict the loaded terms to the given bundles.     if (!empty($this->options['bundles'])) {
      $terms = $this->termStorage->loadByProperties(['name' => $argument, 'vid' => $this->options['bundles']]);
    }
    else {
      $terms = $this->termStorage->loadByProperties(['name' => $argument]);
    }

    // $terms are already bundle tested but we need to test access control.     foreach ($terms as $term) {
      if ($this->validateEntity($term)) {
        return TRUE;
      }
    }

    return FALSE;
  }

}
$accounts = $this->userStorage->loadByProperties(['name' => $names]);

    // If there are no accounts, return FALSE now. As we will not enter the     // loop below otherwise.     if (empty($accounts)) {
      return FALSE;
    }

    // Validate each account. If any fails break out and return false.     foreach ($accounts as $account) {
      if (!in_array($account->getAccountName()$names) || !$this->validateEntity($account)) {
        return FALSE;
      }
    }

    return TRUE;
  }

  /** * {@inheritdoc} */
  public function processSummaryArguments(&$args) {
    
protected function validateEntity(EntityInterface $entity) {
    /** @var \Drupal\user\UserInterface $entity */
    $role_check_success = TRUE;
    // See if we're filtering users based on roles.     if (!empty($this->options['restrict_roles']) && !empty($this->options['roles'])) {
      $roles = $this->options['roles'];
      if (!(bool) array_intersect($entity->getRoles()$roles)) {
        $role_check_success = FALSE;
      }
    }

    return $role_check_success && parent::validateEntity($entity);
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();

    foreach ($this->entityTypeManager->getStorage('user_role')->loadMultiple(array_keys($this->options['roles'])) as $role) {
      $dependencies[$role->getConfigDependencyKey()][] = $role->getConfigDependencyName();
    }

    

  public function import(Row $row, array $old_destination_id_values = []) {
    $this->rollbackAction = MigrateIdMapInterface::ROLLBACK_DELETE;
    $entity = $this->getEntity($row$old_destination_id_values);
    if (!$entity) {
      throw new MigrateException('Unable to get entity');
    }
    assert($entity instanceof ContentEntityInterface);
    if ($this->isEntityValidationRequired($entity)) {
      $this->validateEntity($entity);
    }
    $ids = $this->save($entity$old_destination_id_values);
    if ($this->isTranslationDestination()) {
      $ids[] = $entity->language()->getId();
    }
    return $ids;
  }

  /** * {@inheritdoc} */
  
Home | Imprint | This part of the site doesn't use cookies.