clearCachedDefinitions example

/** * {@inheritdoc} */
  public function getEntityTypes() {
    return $this->entityLastInstalledSchemaRepository->getLastInstalledDefinitions();
  }

  /** * {@inheritdoc} */
  public function installEntityType(EntityTypeInterface $entity_type) {
    $this->clearCachedDefinitions();
    $this->entityTypeListener->onEntityTypeCreate($entity_type);
  }

  /** * {@inheritdoc} */
  public function updateEntityType(EntityTypeInterface $entity_type) {
    $original = $this->getEntityType($entity_type->id());
    $this->clearCachedDefinitions();
    $this->entityTypeListener->onEntityTypeUpdate($entity_type$original);
  }

  
protected function setUp(): void {
    parent::setUp();
    $etm = $this->container->get('entity_type.manager');
    $this->normalizer = new FieldItemNormalizer($etm);
    $this->normalizer->setSerializer($this->container->get('jsonapi.serializer'));

    $definitions = [];
    $definitions['links'] = BaseFieldDefinition::create('link')->setLabel('Links');
    $definitions['internal_property_value'] = BaseFieldDefinition::create('single_internal_property_test')->setLabel('Internal property');
    $definitions['no_main_property_value'] = BaseFieldDefinition::create('map')->setLabel('No main property');
    $this->container->get('state')->set('entity_test.additional_base_field_definitions', $definitions);
    $etm->clearCachedDefinitions();
  }

  /** * Tests a field item that has no properties. * * @covers ::normalize */
  public function testNormalizeFieldItemWithoutProperties(): void {
    $item = $this->prophesize(FieldItemInterface::class);
    $item->getProperties(TRUE)->willReturn([]);
    $item->getValue()->willReturn('Direct call to getValue');

    
    $this->drupalGet('admin/config/people/accounts/translate');
    $this->assertSession()->statusCodeEquals(200);
  }

  /** * Tests the config_translation_info_alter() hook. */
  public function testAlterInfo() {
    $this->drupalLogin($this->adminUser);

    $this->container->get('state')->set('config_translation_test_config_translation_info_alter', TRUE);
    $this->container->get('plugin.manager.config_translation.mapper')->clearCachedDefinitions();

    // Check if the translation page does not have the altered out settings.     $this->drupalGet('admin/config/people/accounts/translate/fr/add');
    $this->assertSession()->pageTextContains('Name');
    $this->assertSession()->pageTextNotContains('Account cancellation confirmation');
    $this->assertSession()->pageTextNotContains('Password recovery');
  }

  /** * Tests the sequence data type translation. */
  


  /** * Ensures that Stable 9 overrides all relevant core library assets. */
  public function testStable9LibraryOverrides() {
    // First get the clean library definitions with no active theme.     $libraries_before = $this->getAllLibraries();
    $libraries_before = $this->removeVendorAssets($libraries_before);

    $this->themeManager->setActiveTheme($this->themeInitialization->getActiveThemeByName('stable9'));
    $this->libraryDiscovery->clearCachedDefinitions();

    // Now get the library definitions with Stable 9 as the active theme.     $libraries_after = $this->getAllLibraries();
    $libraries_after = $this->removeVendorAssets($libraries_after);

    foreach ($libraries_before as $extension => $libraries) {
      foreach ($libraries as $library_name => $library) {
        // Allow skipping libraries.         if (in_array("$extension/$library_name", $this->librariesToSkip)) {
          continue;
        }
        

  public function testPermissions() {
    $this->container->get('content_translation.manager')->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
    $this->container->get('content_translation.manager')->setEnabled('entity_test_mul_with_bundle', 'test', TRUE);
    $permissions = $this->container->get('user.permissions')->getPermissions();
    $this->assertEquals(['entity_test']$permissions['translate entity_test_mul']['dependencies']['module']);
    $this->assertEquals(['entity_test.entity_test_mul_bundle.test']$permissions['translate test entity_test_mul_with_bundle']['dependencies']['config']);

    // Ensure bundle permission granularity works for bundles not based on     // configuration.     $this->container->get('state')->set('entity_test_mul.permission_granularity', 'bundle');
    $this->container->get('entity_type.manager')->clearCachedDefinitions();
    $permissions = $this->container->get('user.permissions')->getPermissions();
    $this->assertEquals(['entity_test']$permissions['translate entity_test_mul entity_test_mul']['dependencies']['module']);
    $this->assertEquals(['entity_test.entity_test_mul_bundle.test']$permissions['translate test entity_test_mul_with_bundle']['dependencies']['config']);
  }

}
use Drupal\migrate_drupal\Plugin\MigrationWithFollowUpInterface;

/** * Migration plugin for the Drupal 7 node translations. */
class D7NodeTranslation extends Migration implements MigrationWithFollowUpInterface {

  /** * {@inheritdoc} */
  public function generateFollowUpMigrations() {
    $this->migrationPluginManager->clearCachedDefinitions();
    return $this->migrationPluginManager->createInstances('d7_entity_reference_translation');
  }

}
    // To make matters worse, decorating a service within the test only is not     // an option either, because \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition     // is a pure value object, so it uses the global container. Therefore the     // only work-around possible is to manipulate the config schema definition     // cache.     // @todo Remove this in https://www.drupal.org/project/drupal/issues/2961541.     if (isset($additional_files['config']['schema']["$module_name.schema.yml"])) {
      $cache = \Drupal::service('cache.discovery')
        ->get('typed_config_definitions');
      $typed_config_definitions = $cache->data;
      $typed_config_definitions += Yaml::parse($additional_files['config']['schema']["$module_name.schema.yml"]);
      \Drupal::service('config.typed')->clearCachedDefinitions();
      \Drupal::service('cache.discovery')->set('typed_config_definitions', $typed_config_definitions$cache->expire, $cache->tags);
    }

    return $container;
  }

  /** * @covers \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::processDefinition * @dataProvider providerTestInvalidPluginDefinitions */
  public function testInvalidPluginDefinitions(string $yaml, ?string $expected_message, array $additional_files = []): void {
    

  protected function applyEntityUpdates($entity_type_id = NULL) {
    $complete_change_list = \Drupal::entityDefinitionUpdateManager()->getChangeList();
    if ($complete_change_list) {
      // In case there are changes, explicitly invalidate caches.       \Drupal::entityTypeManager()->clearCachedDefinitions();
      \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
    }

    if ($entity_type_id) {
      $complete_change_list = array_intersect_key($complete_change_list[$entity_type_id => TRUE]);
    }

    foreach ($complete_change_list as $entity_type_id => $change_list) {
      // Process entity type definition changes before storage definitions ones       // this is necessary when you change an entity type from non-revisionable       // to revisionable and at the same time add revisionable fields to the
foreach ($this->getTopicList() as $info) {
      $name = $info['name'];
      $session->linkExists($name);
      $new_pos = strpos($page_text$name$start);
      $this->assertGreaterThan($pos$new_pos, "Order of $name is not correct on page");
      $pos = $new_pos;
    }

    // Ensure the plugin manager alter hook works as expected.     $session->linkExists('ABC Help Test module');
    \Drupal::state()->set('help_topics_test.test:top_level', FALSE);
    \Drupal::service('plugin.manager.help_topic')->clearCachedDefinitions();
    $this->drupalGet('admin/help');
    $session->linkNotExists('ABC Help Test module');
    \Drupal::state()->set('help_topics_test.test:top_level', TRUE);
    \Drupal::service('plugin.manager.help_topic')->clearCachedDefinitions();
    $this->drupalGet('admin/help');

    // Ensure all the expected links are present before uninstalling.     $session->linkExists('ABC Help Test module');
    $session->linkExists('ABC Help Test');
    $session->linkExists('XYZ Help Test theme');

    
    // - listOptions() should return an empty list of options     // - getAttachments() should return an empty #attachments array (and not     // a JS settings structure that is empty)     $this->assertSame([]$this->editorManager->listOptions(), 'When no text editor is enabled, the manager works correctly.');
    $this->assertSame([]$this->editorManager->getAttachments([]), 'No attachments when no text editor is enabled and retrieving attachments for zero text formats.');
    $this->assertSame([]$this->editorManager->getAttachments(['filtered_html', 'full_html']), 'No attachments when no text editor is enabled and retrieving attachments for multiple text formats.');

    // Enable the Text Editor Test module, which has the Unicorn Editor and     // clear the editor manager's cache so it is picked up.     $this->enableModules(['editor_test']);
    $this->editorManager = $this->container->get('plugin.manager.editor');
    $this->editorManager->clearCachedDefinitions();

    // Case 2: a text editor available.     $this->assertSame('Unicorn Editor', (string) $this->editorManager->listOptions()['unicorn'], 'When some text editor is enabled, the manager works correctly.');

    // Case 3: a text editor available & associated (but associated only with     // the 'Full HTML' text format).     $unicorn_plugin = $this->editorManager->createInstance('unicorn');
    $editor = Editor::create([
      'format' => 'full_html',
      'editor' => 'unicorn',
    ]);
    
$this->assertEquals($default_constraints$entity_type->getConstraints());

    // Enable our test module and test extending constraints.     $this->enableModules(['entity_test_constraints']);
    $this->container->get('module_handler')->resetImplementations();

    $extra_constraints = ['Test' => []];
    $this->state->set('entity_test_constraints.build', $extra_constraints);
    // Re-fetch the entity type manager from the new container built after the     // new modules were enabled.     $this->entityTypeManager = $this->container->get('entity_type.manager');
    $this->entityTypeManager->clearCachedDefinitions();
    $entity_type = $this->entityTypeManager->getDefinition('entity_test_constraints');
    $this->assertEquals($default_constraints + $extra_constraints$entity_type->getConstraints());

    // Test altering constraints.     $altered_constraints = ['Test' => ['some_setting' => TRUE]];
    $this->state->set('entity_test_constraints.alter', $altered_constraints);
    // Clear the cache in state instance in the Drupal container, so it can pick     // up the modified value.     \Drupal::state()->resetCache();
    $this->entityTypeManager->clearCachedDefinitions();
    $entity_type = $this->entityTypeManager->getDefinition('entity_test_constraints');
    
$this->installEntitySchema('user');
    $this->installSchema('system', ['sequences']);
    $this->installConfig(['filter', 'filter_test']);

    // Create user 1 so that the user created later in the test has a different     // user ID.     // @todo Remove in https://www.drupal.org/node/540008.     User::create(['uid' => 1, 'name' => 'user1'])->save();

    /** @var \Drupal\Core\Render\ElementInfoManager $manager */
    $manager = \Drupal::service('plugin.manager.element_info');
    $manager->clearCachedDefinitions();
    $manager->getDefinitions();
    /** @var \Drupal\filter\FilterFormatInterface $filter_test_format */
    $filter_test_format = FilterFormat::load('filter_test');
    $full_html_format = FilterFormat::load('full_html');
    $filtered_html_format = FilterFormat::load('filtered_html');

    /** @var \Drupal\user\RoleInterface $role */
    $role = Role::create([
      'id' => 'admin',
      'label' => 'admin',
    ]);
    
    // class.     $entity_class = $this->storage->getEntityClass('custom');
    $this->assertEquals(EntityTest::class$entity_class);
  }

  /** * Tests making use of a custom bundle class for an entity without bundles. */
  public function testEntityNoBundleSubclass() {
    $this->container->get('state')->set('entity_test_bundle_class_enable_user_class', TRUE);
    $this->container->get('kernel')->rebuildContainer();
    $this->entityTypeManager->clearCachedDefinitions();
    $this->drupalSetUpCurrentUser();
    $entity = User::load(1);
    $this->assertInstanceOf(EntityTestUserClass::class$entity);
  }

  /** * Checks exception is thrown if two bundles share the same bundle class. * * @covers Drupal\Core\Entity\ContentEntityStorageBase::create */
  public function testAmbiguousBundleClassExceptionCreate() {
    

  public function remove() {
    parent::remove();

    if ($this->entityTypeManager->hasDefinition('block')) {
      $plugin_id = 'views_block:' . $this->view->storage->id() . '-' . $this->display['id'];
      foreach ($this->entityTypeManager->getStorage('block')->loadByProperties(['plugin' => $plugin_id]) as $block) {
        $block->delete();
      }
    }
    if ($this->blockManager instanceof CachedDiscoveryInterface) {
      $this->blockManager->clearCachedDefinitions();
    }
  }

}
/** * Tests the block categories on the listing page. */
  public function testCandidateBlockList() {
    $this->drupalGet('admin/structure/block');
    $this->clickLink('Place block');
    $this->assertSession()->elementExists('xpath', '//tr[.//td/div[text()="Display message"] and .//td[text()="Block test"] and .//td//a[contains(@href, "admin/structure/block/add/test_block_instantiation/stark")]]');

    // Trigger the custom category addition in block_test_block_alter().     $this->container->get('state')->set('block_test_info_alter', TRUE);
    $this->container->get('plugin.manager.block')->clearCachedDefinitions();

    $this->drupalGet('admin/structure/block');
    $this->clickLink('Place block');
    $this->assertSession()->elementExists('xpath', '//tr[.//td/div[text()="Display message"] and .//td[text()="Custom category"] and .//td//a[contains(@href, "admin/structure/block/add/test_block_instantiation/stark")]]');
  }

  /** * Tests the behavior of unsatisfied context-aware blocks. */
  public function testContextAwareUnsatisfiedBlocks() {
    $this->drupalGet('admin/structure/block');
    
Home | Imprint | This part of the site doesn't use cookies.