load example

'entity_type' => 'entity_test',
      'type' => $type,
    ]);
    $this->fieldStorage->save();
    $this->field = FieldConfig::create([
      'field_storage' => $this->fieldStorage,
      'bundle' => 'entity_test',
      'required' => TRUE,
    ]);
    $this->field->save();

    EntityFormDisplay::load('entity_test.entity_test.default')
      ->setComponent($field_name['type' => $widget_type])
      ->save();

    $this->displayOptions = [
      'type' => $formatter_type,
      'label' => 'hidden',
    ];

    EntityViewDisplay::create([
      'targetEntityType' => $this->field->getTargetEntityTypeId(),
      'bundle' => $this->field->getTargetBundle(),
      
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Loader\MoFileLoader;

class MoFileLoaderTest extends TestCase
{
    public function testLoad()
    {
        $loader = new MoFileLoader();
        $resource = __DIR__.'/../fixtures/resources.mo';
        $catalogue = $loader->load($resource, 'en', 'domain1');

        $this->assertEquals(['foo' => 'bar']$catalogue->all('domain1'));
        $this->assertEquals('en', $catalogue->getLocale());
        $this->assertEquals([new FileResource($resource)]$catalogue->getResources());
    }

    public function testLoadPlurals()
    {
        $loader = new MoFileLoader();
        $resource = __DIR__.'/../fixtures/plurals.mo';
        $catalogue = $loader->load($resource, 'en', 'domain1');

        

class MediaCreationTest extends MediaKernelTestBase {

  /** * Tests creating a media type programmatically. */
  public function testMediaTypeCreation() {
    $media_type_storage = $this->container->get('entity_type.manager')->getStorage('media_type');

    $this->assertInstanceOf(MediaTypeInterface::class, MediaType::load($this->testMediaType->id()));

    // Test a media type created from default configuration.     $this->container->get('module_installer')->install(['media_test_type']);
    $test_media_type = $media_type_storage->load('test');
    $this->assertInstanceOf(MediaTypeInterface::class$test_media_type);
    $this->assertSame('Test type', $test_media_type->get('label'), 'Could not assure the correct type name.');
    $this->assertSame('Test type.', $test_media_type->get('description'), 'Could not assure the correct type description.');
    $this->assertSame('test', $test_media_type->get('source'), 'Could not assure the correct media source.');
    // Source field is not set on the media source, but it should never     // be created automatically when a config is being imported.     $this->assertSame(['source_field' => '', 'test_config_value' => 'Kakec']$test_media_type->get('source_configuration'), 'Could not assure the correct media source configuration.');
    

  public function __construct(AccountInterface $account, EntityTypeManagerInterface $entity_type_manager) {
    $this->account = $account;
    $this->userStorage = $entity_type_manager->getStorage('user');
  }

  /** * {@inheritdoc} */
  public function getRuntimeContexts(array $unqualified_context_ids) {
    $current_user = $this->userStorage->load($this->account->id());

    if ($current_user) {
      // @todo Do not validate protected fields to avoid bug in TypedData,       // remove this in https://www.drupal.org/project/drupal/issues/2934192.       $current_user->_skipProtectedUserFieldConstraint = TRUE;

      $context = EntityContext::fromEntity($current_user$this->t('Current user'));
    }
    else {
      // If not user is available, provide an empty context object.       $context = EntityContext::fromEntityTypeId('user', $this->t('Current user'));
    }

  protected function assertTranslations(int $id, string $default, array $others = []): void {
    $entity = $this->storage->load($id);
    $this->assertNotEmpty($entity, "Entity exists");
    $this->assertEquals($default$entity->language()->getId(), "Entity default translation");
    $translations = array_keys($entity->getTranslationLanguages(FALSE));
    sort($others);
    sort($translations);
    $this->assertEquals($others$translations, "Entity translations");
  }

  /** * Create the destination plugin to test. * * @param array $configuration * The plugin configuration. */
/** * Tests path aliases with workspaces. */
  public function testPathAliases() {
    // Create a published node in Live, without an alias.     $node = $this->drupalCreateNode([
      'type' => 'article',
      'status' => TRUE,
    ]);

    // Switch to Stage and create an alias for the node.     $stage = Workspace::load('stage');
    $this->switchToWorkspace($stage);

    $edit = [
      'path[0][alias]' => '/' . $this->randomMachineName(),
    ];
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->submitForm($edit, 'Save');

    // Check that the node can be accessed in Stage with the given alias.     $path = $edit['path[0][alias]'];
    $this->assertAccessiblePaths([$path]);

    


    /** * @throws AddressNotFoundException * @throws CategoryNotFoundException * @throws InconsistentCriteriaIdsException * @throws InvalidUuidException * @throws RoutingException */
    public function load(Request $request, SalesChannelContext $salesChannelContext): CheckoutRegisterPage
    {
        $page = $this->genericLoader->load($request$salesChannelContext);

        $page = CheckoutRegisterPage::createFrom($page);

        if ($page->getMetaInformation()) {
            $page->getMetaInformation()->setRobots('noindex,follow');
        }

        $page->setCountries($this->getCountries($salesChannelContext));
        $page->setCart($this->cartService->getCart($salesChannelContext->getToken()$salesChannelContext));
        $page->setSalutations($this->getSalutations($salesChannelContext));

        
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);
        // ::assertConfigDiff will throw an exception if the configuration is         // different.         $this->assertNull($this->assertConfigDiff($result$config_namestatic::$skippedConfig));
      }
      
assert($stream_wrapper_manager instanceof StreamWrapperManagerInterface);
    $this->assertEquals('public', $stream_wrapper_manager::getScheme($result->getFileUri()), "File was placed in Drupal's files directory.");
    $this->assertEquals($filename, \Drupal::service('file_system')->basename($result->getFileUri()), 'File was named correctly.');
    $this->assertEquals($contentsfile_get_contents($result->getFileUri()), 'Contents of the file are correct.');
    $this->assertEquals('text/plain', $result->getMimeType(), 'A MIME type was set.');
    $this->assertTrue($result->isPermanent(), "The file's status was set to permanent.");

    // Check that the correct hooks were called.     $this->assertFileHooksCalled(['insert']);

    // Verify that what was returned is what's in the database.     $this->assertFileUnchanged($result, File::load($result->id()));
  }

  /** * Tests writeData() when renaming around an existing file. * * @covers ::writeData */
  public function testExistingRename() {
    // Setup a file to overwrite.     $existing = $this->createFile();
    $contents = $this->randomMachineName();

    
2, 'book', 'en', 'Book page'],
      [4, 'page', 'en', 'Test page'],
      [8, 'test_content_type', 'en', 'Test title'],
    ];
    foreach ($expected_node_data as $node_data) {
      $id = $node_data[0];
      $type = $node_data[1];
      $langcode = $node_data[2];
      $title = $node_data[3];

      // Make sure our English nodes still exist.       $node = Node::load($id);
      $this->assertEquals($langcode$node->language()->getId());
      $this->assertEquals($type$node->getType());
      $this->assertEquals($title$node->getTitle());
      // Assert that nodes are all published.       $this->assertTrue($node->isPublished());
      $this->drupalGet('node/' . $id);
      $this->assertSession()->pageTextContains($title);
    }

    // Make sure the translated node still exists.     $translation = Node::load(8)->getTranslation('es');
    

  public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatterInterface $date_formatter, LanguageManagerInterface $language_manager, EntityStorageInterface $image_style_storage) {
    parent::__construct($entity_type$storage);

    $this->dateFormatter = $date_formatter;
    $this->languageManager = $language_manager;
    $this->thumbnailStyleExists = !empty($image_style_storage->load('thumbnail'));
  }

  /** * {@inheritdoc} */
  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
    $entity_type_manager = $container->get('entity_type.manager');
    return new static(
      $entity_type,
      $entity_type_manager->getStorage($entity_type->id()),
      $container->get('date.formatter'),
      
#[Package('core')] class ElasticsearchExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container): void
    {
        $config = $this->processConfiguration($this->getConfiguration($configs$container)$configs);
        $this->addConfig($container$this->getAlias()$config);

        $loader = new XmlFileLoader($containernew FileLocator(__DIR__ . '/../Resources/config'));

        $loader->load('services.xml');
    }

    public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface
    {
        return new Configuration();
    }

    private function addConfig(ContainerBuilder $container, string $alias, array $options): void
    {
        foreach ($options as $key => $option) {
            $container->setParameter($alias . '.' . $key$option);

            
$this->executeMigrations([
      'user_picture_field',
      'user_picture_field_instance',
      'user_picture_entity_display',
    ]);
  }

  /** * Tests the Drupal 7 user picture to Drupal 8 entity display migration. */
  public function testUserPictureEntityDisplay() {
    $component = EntityViewDisplay::load('user.user.default')->getComponent('user_picture');
    $this->assertSame('image', $component['type']);
    $this->assertSame('', $component['settings']['image_style']);
    $this->assertSame('content', $component['settings']['image_link']);
  }

}

    public function __construct(private readonly ProductConfiguratorLoader $loader)
    {
    }

    /** * @throws InconsistentCriteriaIdsException */
    public function load(SalesChannelProductEntity $product, SalesChannelContext $context): PropertyGroupCollection
    {
        return $this->loader->load($product$context);
    }
}
// Test with an entity type that doesn't implement EntityPublishedInterface.     $entity_test = EntityTestRev::create();
    $entity_test->save();

    \Drupal::service('module_installer')->install(['content_moderation'], TRUE);
    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example');
    $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev');
    $workflow->save();

    $loaded_unpublished_node = Node::load($unpublished_node->id());
    $loaded_published_node = Node::load($published_node->id());
    $loaded_entity_test = EntityTestRev::load($entity_test->id());
    $this->assertEquals('draft', $loaded_unpublished_node->moderation_state->value);
    $this->assertEquals('published', $loaded_published_node->moderation_state->value);
    $this->assertEquals('draft', $loaded_entity_test->moderation_state->value);

    $presave_node = Node::create([
      'type' => 'example',
      'title' => 'Presave node',
    ]);
    $this->assertEquals('draft', $presave_node->moderation_state->value);
  }
Home | Imprint | This part of the site doesn't use cookies.