getBundleFromValues example

parent::__construct($entity_type$memory_cache);
    $this->bundleKey = $this->entityType->getKey('bundle');
    $this->entityFieldManager = $entity_field_manager;
    $this->cacheBackend = $cache;
    $this->entityTypeBundleInfo = $entity_type_bundle_info;
  }

  /** * {@inheritdoc} */
  public function create(array $values = []) {
    $bundle = $this->getBundleFromValues($values);
    $entity_class = $this->getEntityClass($bundle);
    // @todo Decide what to do if preCreate() tries to change the bundle.     // @see https://www.drupal.org/project/drupal/issues/3230792     $entity_class::preCreate($this$values);

    // Assign a new UUID if there is none yet.     if ($this->uuidKey && $this->uuidService && !isset($values[$this->uuidKey])) {
      $values[$this->uuidKey] = $this->uuidService->generate();
    }

    $entity = $this->doCreate($values);
    
Home | Imprint | This part of the site doesn't use cookies.