clearCachedBundles example

    $assert_session->elementsCount('css', 'input[name$="_settings_edit"]', 1);
    $source_field_name = $media_type->getSource()
      ->getSourceFieldDefinition($media_type)
      ->getName();
    $assert_session->buttonExists("{$source_field_name}_settings_edit");
    // Ensure the source field label is configured as expected.     $assert_session->fieldValueEquals("fields[$source_field_name][label]", $source_label_visibility);

    // Bundle definitions are statically cached in the context of the test, we     // need to make sure we have updated information before proceeding with the     // actions on the UI.     \Drupal::service('entity_type.bundle.info')->clearCachedBundles();

    return $media_type;
  }

}
$this->installEntitySchema('entity_test_mul');

    ConfigurableLanguage::createFromLangcode('it')->save();
  }

  /** * Tests that modules can know whether bundles are translatable. */
  public function testHookInvocationOrder() {
    $this->contentTranslationManager->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
    $this->bundleInfo->clearCachedBundles();
    $this->bundleInfo->getAllBundleInfo();

    // Verify that the test module comes first in the module list, which would     // normally make its hook implementation to be invoked first.     /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
    $module_handler = $this->container->get('module_handler');
    $module_list = $module_handler->getModuleList();
    $expected_modules = [
      'content_translation_test',
      'content_translation',
    ];
    

  public function testEntityFormSharedElements(array $element$default_translation_affected$default_translation$translation_form$is_submitted$is_rebuilding, array $expected$display_warning) {
    $this->state->set('entity_test.translation', TRUE);
    $this->state->set('entity_test.untranslatable_fields.default_translation_affected', $default_translation_affected);
    $this->entityTypeBundleInfo->clearCachedBundles();

    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $this->entityTypeManager->getStorage($this->entityTypeId)->create();
    if (!$default_translation) {
      $entity = $entity->addTranslation($this->translationLangcode);
    }
    $entity->save();

    $form_object = $this->entityTypeManager->getFormObject($this->entityTypeId, 'default');
    $form_object->setEntity($entity);

    

  protected function setUntranslatableFieldWidgetsDisplay($display) {
    $entity_type_id = $this->storage->getEntityTypeId();
    $settings = ['untranslatable_fields_hide' => !$display];
    $this->contentTranslationManager->setBundleTranslationSettings($entity_type_id$entity_type_id$settings);
    /** @var \Drupal\Core\Entity\EntityTypeBundleInfo $bundle_info */
    $bundle_info = $this->container->get('entity_type.bundle.info');
    $bundle_info->clearCachedBundles();
  }

  /** * @return \Drupal\Core\Entity\ContentEntityInterface */
  protected function saveNewEntity() {
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = EntityTestMulRev::create([
      'uid' => 1,
      'langcode' => 'en',
      $this->fieldName => [
        
 'foo', []);

    $this->assertEquals($entity->getLoadedRevisionId()$converted->getLoadedRevisionId());
  }

  /** * Tests with a translated pending revision. */
  public function testWithTranslatedPendingRevision() {
    // Enable translation for test entities.     $this->container->get('state')->set('entity_test.translation', TRUE);
    $this->container->get('entity_type.bundle.info')->clearCachedBundles();

    // Create a new English entity.     $entity = EntityTestMulRev::create();
    $entity->save();

    // Create a translated pending revision.     $entity_type_id = 'entity_test_mulrev';
    /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
    $storage = $this->container->get('entity_type.manager')->getStorage($entity_type_id);
    /** @var \Drupal\Core\Entity\ContentEntityInterface $translated_entity */
    $translated_entity = $storage->createRevision($entity->addTranslation('de'), FALSE);
    
// Make sure the test workflow includes the default states and transitions.     $session->pageTextContains('Draft');
    $session->pageTextContains('Published');
    $session->pageTextContains('Create New Draft');
    $session->pageTextContains('Publish');

    $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/draft/delete');
    $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/published/delete');

    // Ensure after a workflow is created, the bundle information can be     // refreshed.     $entity_bundle_info->clearCachedBundles();
    $this->assertNotEmpty($entity_bundle_info->getAllBundleInfo());

    $this->clickLink('Add a new state');
    $this->submitForm([
      'label' => 'Test State',
      'id' => 'test_state',
      'type_settings[published]' => TRUE,
      'type_settings[default_revision]' => FALSE,
    ], 'Save');
    $session->pageTextContains('Created Test State state.');
    $session->linkByHrefExists('/admin/config/workflow/workflows/manage/test/state/test_state/delete');

    
// Delete the node.     $this->drupalGet('node/' . $node->id() . '/delete');
    $this->submitForm([], 'Delete');
    $this->assertSession()->pageTextContains('The Moderated content moderated content has been deleted.');

    // Disable content moderation.     $edit['bundles[moderated_content]'] = FALSE;
    $this->drupalGet('admin/config/workflow/workflows/manage/editorial/type/node');
    $this->submitForm($edit, 'Save');
    // Ensure the parent environment is up-to-date.     // @see content_moderation_workflow_insert()     \Drupal::service('entity_type.bundle.info')->clearCachedBundles();
    \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();

    // Create a new node.     $this->drupalGet('node/add/moderated_content');
    $this->submitForm(['title[0][value]' => 'non-moderated content'], 'Save');

    $node = $this->getNodeByTitle('non-moderated content');
    if (!$node) {
      $this->fail('Non-moderated test node was not saved correctly.');
    }
    $this->assertFalse($node->hasField('moderation_state'));
  }
$this->submitForm([], 'Delete');
    // Delete 'page' bundle.     $this->drupalGet('admin/structure/types/manage/page/delete');
    $this->submitForm([], 'Delete');

    // Navigate to content type administration screen     $this->drupalGet('admin/structure/types');
    $this->assertSession()->pageTextContains("No content types available. Add content type.");
    $this->assertSession()->linkExists("Add content type");
    $this->assertSession()->linkByHrefExists(Url::fromRoute('node.type_add')->toString());

    $bundle_info->clearCachedBundles();
    $this->assertCount(0, $bundle_info->getBundleInfo('node'), 'The bundle information service has 0 bundles for the Node entity type.');
  }

}
$this->installEntitySchema('entity_test_mulrev');

    $this->installConfig(['system', 'language']);
    ConfigurableLanguage::createFromLangcode('it')
      ->setWeight(1)
      ->save();
    ConfigurableLanguage::createFromLangcode('ro')
      ->setWeight(2)
      ->save();

    $this->container->get('state')->set('entity_test.translation', TRUE);
    $this->container->get('entity_type.bundle.info')->clearCachedBundles();
  }

  /** * Tests retrieving active variants. * * @covers ::getActive * @covers ::getActiveMultiple */
  public function testGetActive() {
    $en_contexts = $this->getLanguageContexts('en');

    

  public function testWorkflowChanges($view_id) {
    // First, apply the Editorial workflow to both of our content types.     $this->drupalGet('admin/config/workflow/workflows/manage/editorial/type/node');
    $this->submitForm([
      'bundles[example_a]' => TRUE,
      'bundles[example_b]' => TRUE,
    ], 'Save');
    \Drupal::service('entity_type.bundle.info')->clearCachedBundles();

    // Update the view and make the default filter not exposed anymore,     // otherwise all results will be shown when there are no more moderated     // bundles left.     $this->drupalGet("admin/structure/views/nojs/handler/{$view_id}/default/filter/moderation_state");
    $this->submitForm([], 'Hide filter');
    $this->drupalGet("admin/structure/views/view/{$view_id}");
    $this->submitForm([], 'Save');

    // Add a few nodes in various moderation states.     $this->createNode(['type' => 'example_a', 'moderation_state' => 'published']);
    
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityFieldManagerInterface $entity_field_manager, ModuleHandlerInterface $module_handler) {
    $this->entityTypeManager = $entity_type_manager;
    $this->entityTypeBundleInfo = $entity_type_bundle_info;
    $this->entityFieldManager = $entity_field_manager;
    $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} */
if ($revisionable && $translatable) {
      $entity_type->set('revision_data_table', 'entity_test_update_revision_data');
    }
    else {
      $entity_type->set('revision_data_table', NULL);
    }

    $this->state->set('entity_test_update.entity_type', $entity_type);

    $this->container->get('entity_type.manager')->clearCachedDefinitions();
    $this->container->get('entity_type.bundle.info')->clearCachedBundles();
    $this->container->get('entity_field.manager')->clearCachedFieldDefinitions();

    return $entity_type;
  }

  /** * Returns the required rev / mul field definitions for an entity type. * * @param bool $revisionable * (optional) Whether the entity type should be revisionable or not. * Defaults to FALSE. * @param bool $translatable * (optional) Whether the entity type should be translatable or not. * Defaults to FALSE. * * @return \Drupal\Core\Field\FieldStorageDefinitionInterface[] * An array of field storage definition objects. */


    $values = [
      'name' => $this->randomString(),
      'status' => 1,
    ];
    User::create($values)->save();

    // Make sure entity bundles are translatable.     $this->state->set('entity_test.translation', TRUE);
    $this->bundleInfo = \Drupal::service('entity_type.bundle.info');
    $this->bundleInfo->clearCachedBundles();
  }

  /** * Data provider for ::testDecoupledDefaultRevisions. */
  public function dataTestDecoupledPendingRevisions() {
    $sets = [];

    $sets['Intermixed languages - No initial default translation'][] = [
      ['en', TRUE],
      ['en', FALSE],
      [

  public function testClearCachedBundles() {
    $this->setUpEntityTypeDefinitions();

    $this->typedDataManager->clearCachedDefinitions()->shouldBeCalled();

    $this->cacheTagsInvalidator->invalidateTags(['entity_bundles'])->shouldBeCalled();

    $this->entityTypeBundleInfo->clearCachedBundles();
  }

  /** * Tests the getBundleInfo() method. * * @covers ::getBundleInfo * * @dataProvider providerTestGetBundleInfo */
  public function testGetBundleInfo($entity_type_id$expected) {
    $this->moduleHandler->invokeAll('entity_bundle_info')->willReturn([]);
    
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();
    }
  }

  /** * {@inheritdoc} */
  public static function postDelete(EntityStorageInterface $storage, array $entities) {
    parent::postDelete($storage$entities);

    foreach ($entities as $entity) {
      $entity->deleteDisplays();
      
Home | Imprint | This part of the site doesn't use cookies.