getEntityTypeManager example

          // is automatically deleted if all the instances are.           $this->setProcessedConfiguration($collection$op$name);
          return FALSE;
        }
        break;

      case 'create':
        if ($target_exists) {
          // If the target already exists, use the entity storage to delete it           // again, if is a simple config, delete it directly.           if ($entity_type_id = $this->configManager->getEntityTypeIdByName($name)) {
            $entity_storage = $this->configManager->getEntityTypeManager()->getStorage($entity_type_id);
            $entity_type = $this->configManager->getEntityTypeManager()->getDefinition($entity_type_id);
            $entity = $entity_storage->load($entity_storage->getIDFromConfigName($name$entity_type->getConfigPrefix()));
            $entity->delete();
            $this->logError($this->t('Deleted and replaced configuration entity "@name"', ['@name' => $name]));
          }
          else {
            $this->storageComparer->getTargetStorage($collection)->delete($name);
            $this->logError($this->t('Deleted and replaced configuration "@name"', ['@name' => $name]));
          }
          return TRUE;
        }
        
/** * Updates configuration entity in the key store. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The configuration event. */
  public function onConfigSave(ConfigCrudEvent $event) {
    $saved_config = $event->getConfig();
    $entity_type_id = $this->configManager->getEntityTypeIdByName($saved_config->getName());
    if ($entity_type_id) {
      $entity_type = $this->configManager->getEntityTypeManager()->getDefinition($entity_type_id);
      $this->updateConfigKeyStore($entity_type$saved_config);
    }
  }

  /** * Removes configuration entity from key store. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The configuration event. */
  public function onConfigDelete(ConfigCrudEvent $event) {
    

  protected function getEntityTypeDefinition($entity_type_id) {
    /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type_definition */
    // Get the entity type definition.     $entity_type_definition = $this->getEntityTypeManager()->getDefinition($entity_type_id, FALSE);

    // Don't try to create an entity without an entity type id.     if (!$entity_type_definition) {
      throw new UnexpectedValueException(sprintf('The specified entity type "%s" does not exist. A valid entity type is required for denormalization', $entity_type_id));
    }

    return $entity_type_definition;
  }

  /** * Denormalizes the bundle property so entity creation can use it. * * @param array $data * The data being denormalized. The bundle information will be removed. * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type_definition * The entity type definition. * * @throws \Symfony\Component\Serializer\Exception\UnexpectedValueException * If the bundle value is invalid or the bundle type is ineligible. * * @return array * An array containing a single $bundle_key => $bundle_value pair. */

  protected function getEntityTranslationRenderer() {
    if (!isset($this->entityTranslationRenderer)) {
      $view = $this->getView();
      $rendering_language = $view->display_handler->getOption('rendering_language');
      $langcode = NULL;
      $dynamic_renderers = [
        '***LANGUAGE_entity_translation***' => 'TranslationLanguageRenderer',
        '***LANGUAGE_entity_default***' => 'DefaultLanguageRenderer',
      ];
      $entity_type = $this->getEntityTypeManager()->getDefinition($this->getEntityTypeId());
      if (isset($dynamic_renderers[$rendering_language])) {
        // Dynamic language set based on result rows or instance defaults.         $class = '\Drupal\views\Entity\Render\\' . $dynamic_renderers[$rendering_language];
        $this->entityTranslationRenderer = new $class($view$this->getLanguageManager()$entity_type);
      }
      else {
        if (str_contains($rendering_language, '***LANGUAGE_')) {
          $langcode = PluginBase::queryLanguageSubstitutions()[$rendering_language];
        }
        else {
          // Specific langcode set.
// If we are syncing do not create configuration entities. Pluggable         // configuration entities can have dependencies on modules that are         // not yet enabled. This approach means that any code that expects         // default configuration entities to exist will be unstable after the         // module has been enabled and before the config entity has been         // imported.         if ($this->isSyncing()) {
          continue;
        }
        /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $entity_storage */
        $entity_storage = $this->configManager
          ->getEntityTypeManager()
          ->getStorage($entity_type);

        $id = $entity_storage->getIDFromConfigName($name$entity_storage->getEntityType()->getConfigPrefix());
        // It is possible that secondary writes can occur during configuration         // creation. Updates of such configuration are allowed.         if ($this->getActiveStorages($collection)->exists($name)) {
          $entity = $entity_storage->load($id);
          $entity = $entity_storage->updateFromStorageRecord($entity$new_config->get());
        }
        else {
          $entity = $entity_storage->createFromStorageRecord($new_config->get());
        }
    $active_config_storage = $this->container->get('config.storage');

    /** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
    $config_factory = $this->container->get('config.factory');

    foreach ($default_config_storage->listAll() as $config_name) {
      if ($active_config_storage->exists($config_name)) {
        // If it is a config entity re-save it. This ensures that any         // recalculation of dependencies does not cause config change.         if ($entity_type = $config_manager->getEntityTypeIdByName($config_name)) {
          $entity_storage = $config_manager
            ->getEntityTypeManager()
            ->getStorage($entity_type);
          $id = $entity_storage->getIDFromConfigName($config_name$entity_storage->getEntityType()
            ->getConfigPrefix());
          $entity_storage->load($id)->calculateDependencies()->save();
        }
        else {
          // Ensure simple configuration is re-saved so any schema sorting is           // applied.           $config_factory->getEditable($config_name)->save();
        }
        $result = $config_manager->diff($default_config_storage$active_config_storage$config_name);
        
$bundle_info = $this->prophesize(EntityTypeBundleInfoInterface::class);
    $bundle_info->getBundleInfo("test_entity_type")->willReturn([$bundle => $bundle_info_array]);
    $bundle_info->getBundleInfo("unmoderated_test_type")->willReturn([$bundle => []]);

    return $bundle_info->reveal();
  }

  /** * @covers ::isModeratedEntityType */
  public function testIsModeratedEntityType() {
    $moderation_information = new ModerationInformation($this->getEntityTypeManager()$this->setupModerationBundleInfo('test_bundle', 'workflow'));

    $moderated_entity_type = $this->prophesize(EntityTypeInterface::class);
    $moderated_entity_type->id()->willReturn('test_entity_type');

    $unmoderated_entity_type = $this->prophesize(EntityTypeInterface::class);
    $unmoderated_entity_type->id()->willReturn('unmoderated_test_type');

    $this->assertTrue($moderation_information->isModeratedEntityType($moderated_entity_type->reveal()));
    $this->assertFalse($moderation_information->isModeratedEntityType($unmoderated_entity_type->reveal()));
  }

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