AmbiguousBundleClassException example



  /** * {@inheritdoc} */
  public function getBundleFromClass(string $class_name): ?string {
    $bundle_for_class = NULL;

    foreach ($this->entityTypeBundleInfo->getBundleInfo($this->entityTypeId) as $bundle => $bundle_info) {
      if (!empty($bundle_info['class']) && $bundle_info['class'] === $class_name) {
        if ($bundle_for_class) {
          throw new AmbiguousBundleClassException($class_name);
        }
        else {
          $bundle_for_class = $bundle;
        }
      }
    }

    return $bundle_for_class;
  }

  /** * Retrieves the bundle from an array of values. * * @param array $values * An array of values to set, keyed by field name. * * @return string|null * The bundle or NULL if not set. */

    }

    // If no match was found check if it is a bundle class. This needs to be in     // a separate loop to avoid false positives, since an entity class can     // subclass another entity class.     if (!$entity_type_id) {
      foreach ($definitions as $entity_type) {
        if (is_subclass_of($class_name$entity_type->getOriginalClass()) || is_subclass_of($class_name$entity_type->getClass())) {
          $entity_type_id = $entity_type->id();
          if ($same_class++) {
            throw new AmbiguousBundleClassException($class_name);
          }
        }
      }
    }

    // Return the matching entity type ID if there is one.     if ($entity_type_id) {
      $this->classNameEntityTypeMap[$class_name] = $entity_type_id;
      return $entity_type_id;
    }

    
Home | Imprint | This part of the site doesn't use cookies.