onBundleCreate example



  /** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);

    $entity_type_manager = $this->entityTypeManager();
    $bundle_of = $this->getEntityType()->getBundleOf();
    if (!$update) {
      \Drupal::service('entity_bundle.listener')->onBundleCreate($this->id()$bundle_of);
    }
    else {
      // Invalidate the render cache of entities for which this entity       // is a bundle.       if ($entity_type_manager->hasHandler($bundle_of, 'view_builder')) {
        $entity_type_manager->getViewBuilder($bundle_of)->resetCache();
      }
      // Entity bundle field definitions may depend on bundle settings.       \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
      $this->entityTypeBundleInfo()->clearCachedBundles();
    }
  }
$this->moduleHandler = $module_handler;
  }

  /** * {@inheritdoc} */
  public function onBundleCreate($bundle$entity_type_id) {
    $this->entityTypeBundleInfo->clearCachedBundles();
    // Notify the entity storage.     $storage = $this->entityTypeManager->getStorage($entity_type_id);
    if ($storage instanceof EntityBundleListenerInterface) {
      $storage->onBundleCreate($bundle$entity_type_id);
    }
    // Invoke hook_entity_bundle_create() hook.     $this->moduleHandler->invokeAll('entity_bundle_create', [$entity_type_id$bundle]);
    $this->entityFieldManager->clearCachedFieldDefinitions();
  }

  /** * {@inheritdoc} */
  public function onBundleDelete($bundle$entity_type_id) {
    $this->entityTypeBundleInfo->clearCachedBundles();
    
Home | Imprint | This part of the site doesn't use cookies.