loadMultiple example

$view = Views::getView('test_row_render_cache');
    $view->setDisplay();
    $view->preview();

    /** @var \Drupal\Core\Render\RenderCacheInterface $render_cache */
    $render_cache = $this->container->get('render_cache');

    /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache_plugin */
    $cache_plugin = $view->display_handler->getPlugin('cache');

    // Retrieve nodes and sort them in alphabetical order to match view results.     $nodes = Node::loadMultiple();
    usort($nodesfunction DNodeInterface $a, NodeInterface $b) {
      return strcmp($a->label()$b->label());
    });

    $index = 0;
    foreach ($nodes as $node) {
      $nid = $node->id();
      $access = $node->access('update');

      $counter = $index + 1;
      $expected = "$nid: $counter (just in case: $nid)";
      
$display_entity_type = $this->entity->getEntityTypeId();
    $entity_type = $this->entityTypeManager->getDefinition($display_entity_type);
    $config_prefix = $entity_type->getConfigPrefix();
    $ids = $this->configFactory()->listAll($config_prefix . '.' . $this->entity->getTargetEntityTypeId() . '.' . $this->entity->getTargetBundle() . '.');
    foreach ($ids as $id) {
      $config_id = str_replace($config_prefix . '.', '', $id);
      [,, $display_mode] = explode('.', $config_id);
      if ($display_mode != 'default') {
        $load_ids[] = $config_id;
      }
    }
    return $this->entityTypeManager->getStorage($display_entity_type)->loadMultiple($load_ids);
  }

  /** * Returns form or view modes statuses for the bundle used by this form. * * @return array * An array of form or view mode statuses. */
  protected function getDisplayStatuses() {
    $display_statuses = [];
    $displays = $this->getDisplays();
    
'type' => 'external_test',
      'name' => 'Test node type',
    ])->save();
  }

  /** * Tests importing and rolling back our data. */
  public function testMigrations() {
    /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
    $storage = $this->container->get('entity_type.manager')->getStorage('node');
    $this->assertCount(0, $storage->loadMultiple());

    // Run the migrations.     $migration_ids = ['external_translated_test_node', 'external_translated_test_node_translation'];
    $this->executeMigrations($migration_ids);
    $this->assertCount(3, $storage->loadMultiple());

    $node = $storage->load(1);
    $this->assertEquals('en', $node->language()->getId());
    $this->assertEquals('Cat', $node->title->value);
    $this->assertEquals('Chat', $node->getTranslation('fr')->title->value);
    $this->assertEquals('Gato', $node->getTranslation('es')->title->value);

    
$count_query->addExpression('COUNT(*)');
    $count_query->addTag('node_access');
    $count_query->addMetaData('base_table', 'forum_index');

    $query->setCountQuery($count_query);
    $result = $query->execute();
    $nids = [];
    foreach ($result as $record) {
      $nids[] = $record->nid;
    }
    if ($nids) {
      $nodes = $this->entityTypeManager->getStorage('node')->loadMultiple($nids);

      $query = $this->connection->select('node_field_data', 'n')
        ->extend(TableSortExtender::class);
      $query->fields('n', ['nid']);

      $query->join('comment_entity_statistics', 'ces', "[n].[nid] = [ces].[entity_id] AND [ces].[field_name] = 'comment_forum' AND [ces].[entity_type] = 'node'");
      $query->fields('ces', [
        'cid',
        'last_comment_uid',
        'last_comment_timestamp',
        'comment_count',
      ]);
        // getEntitiesToView(), explicitly mark the items where $item->entity         // contains a valid entity ready for display. All items are initialized         // at FALSE.         $item->_loaded = FALSE;
        if ($this->needsEntityLoad($item)) {
          $ids[] = $item->target_id;
        }
      }
    }
    if ($ids) {
      $target_type = $this->getFieldSetting('target_type');
      $target_entities = \Drupal::entityTypeManager()->getStorage($target_type)->loadMultiple($ids);
    }

    // For each item, pre-populate the loaded entity in $item->entity, and set     // the 'loaded' flag.     foreach ($entities_items as $items) {
      foreach ($items as $item) {
        if (isset($target_entities[$item->target_id])) {
          $item->entity = $target_entities[$item->target_id];
          $item->_loaded = TRUE;
        }
        elseif ($item->hasNewEntity()) {
          


  /** * Tests that views are disabled when an entity type is deleted. */
  public function testDeleteEntityType() {
    $entity_storage = $this->entityTypeManager->getStorage('view');

    // Make the test entity type revisionable.     $this->updateEntityTypeToRevisionable(TRUE);

    $views = $entity_storage->loadMultiple();

    // Ensure that all test views exists.     $this->assertTrue(isset($views['test_view_entity_test']));
    $this->assertTrue(isset($views['test_view_entity_test_revision']));
    $this->assertTrue(isset($views['test_view_entity_test_data']));
    $this->assertTrue(isset($views['test_view_entity_test_additional_base_field']));

    $event = new EntityTypeEvent($this->entityTypeManager->getDefinition('entity_test_update'));
    $this->eventDispatcher->dispatch($event, EntityTypeEvents::DELETE);

    // We expect that views which use 'entity_test_update' as base tables are
    // deletes during the same request benefit from the static cache. Using the     // factory also ensures configuration entity dependency discovery has no     // dependencies on the config entity classes. Assume data with UUID is a     // config entity. Only configuration entities can be depended on so we can     // ignore everything else.     $data = array_map(function D$config) {
      $data = $config->get();
      if (isset($data['uuid'])) {
        return $data;
      }
      return FALSE;
    }$this->configFactory->loadMultiple($this->activeStorage->listAll()));
    $dependency_manager->setData(array_filter($data));
    return $dependency_manager;
  }

  /** * {@inheritdoc} */
  public function findConfigEntityDependencies($type, array $names, ConfigDependencyManager $dependency_manager = NULL) {
    if (!$dependency_manager) {
      $dependency_manager = $this->getConfigDependencyManager();
    }
    

    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $form = parent::settingsForm($form$form_state);

    $date_formats = [];
    foreach ($this->dateFormatStorage->loadMultiple() as $machine_name => $value) {
      $date_formats[$machine_name] = $this->t('@name format: @date', ['@name' => $value->label(), '@date' => $this->dateFormatter->format(REQUEST_TIME, $machine_name)]);
    }
    $date_formats[static::CUSTOM_DATE_FORMAT] = $this->t('Custom');

    $time_diff = $this->getSetting('time_diff');

    $form['time_diff']['#tree'] = TRUE;
    $form['time_diff']['enabled'] = [
      '#type' => 'checkbox',
      '#title' => $this->t("Display as a time difference (e.g. '6 months ago')"),
      '#default_value' => $time_diff['enabled'],
    ];

  public static function loadMultipleByType($type) {
    return self::loadMultiple(\Drupal::entityQuery('workflow')->condition('type', $type)->execute());
  }

  /** * {@inheritdoc} */
  public function status() {
    // In order for a workflow to be usable it must have at least one state.     return !empty($this->status) && !empty($this->getTypePlugin()->getStates());
  }

  /** * {@inheritdoc} */
'There are 0 @entity_type_plural to delete.',
          ['@entity_type_plural' => $entity_type->getPluralLabel()]
        ),
      ];
    }
    elseif ($accessible_count > 0 && $entity_type->hasKey('label')) {
      $recent_entity_ids = $storage->getQuery()
        ->accessCheck(TRUE)
        ->sort($entity_type->getKey('id'), 'DESC')
        ->pager(10)
        ->execute();
      $recent_entities = $storage->loadMultiple($recent_entity_ids);

      $labels = [];
      foreach ($recent_entities as $entity) {
        $labels[] = $entity->label();
      }

      if ($labels) {
        $form['recent_entity_labels'] = [
          '#theme' => 'item_list',
          '#items' => $labels,
        ];
        
$options['timezone'] = ['default' => ''];

    return $options;
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {

    $date_formats = [];
    foreach ($this->dateFormatStorage->loadMultiple() as $machine_name => $value) {
      $date_formats[$machine_name] = $this->t('@name format: @date', ['@name' => $value->label(), '@date' => $this->dateFormatter->format(REQUEST_TIME, $machine_name)]);
    }

    $form['date_format'] = [
      '#type' => 'select',
      '#title' => $this->t('Date format'),
      '#options' => $date_formats + [
        'custom' => $this->t('Custom'),
        'raw time ago' => $this->t('Time ago'),
        'time ago' => $this->t('Time ago (with "ago" appended)'),
        'raw time hence' => $this->t('Time hence'),
        
/** * {@inheritdoc} */
  public function load() {
    $entity_query = $this->storage->getQuery();
    $entity_query->accessCheck(TRUE);
    $entity_query->condition('uid', 0, '<>');
    $entity_query->pager(50);
    $header = $this->buildHeader();
    $entity_query->tableSort($header);
    $uids = $entity_query->execute();
    return $this->storage->loadMultiple($uids);
  }

  /** * {@inheritdoc} */
  public function buildHeader() {
    $header = [
      'username' => [
        'data' => $this->t('Username'),
        'field' => 'name',
        'specifier' => 'name',
      ],
use BundlePermissionHandlerTrait;
  use StringTranslationTrait;

  /** * Returns an array of node type permissions. * * @return array * The node type permissions. * @see \Drupal\user\PermissionHandlerInterface::getPermissions() */
  public function nodeTypePermissions() {
    return $this->generatePermissions(NodeType::loadMultiple()[$this, 'buildPermissions']);
  }

  /** * Returns a list of node permissions for a given node type. * * @param \Drupal\node\Entity\NodeType $type * The node type. * * @return array * An associative array of permission names and descriptions. */
  
/** * Update field settings if the image style name is changed. * * @param \Drupal\image\ImageStyleInterface $style * The image style. */
  protected static function replaceImageStyle(ImageStyleInterface $style) {
    if ($style->id() != $style->getOriginalId()) {
      // Loop through all entity displays looking for formatters / widgets using       // the image style.       foreach (EntityViewDisplay::loadMultiple() as $display) {
        foreach ($display->getComponents() as $name => $options) {
          if (isset($options['type']) && $options['type'] == 'image' && $options['settings']['image_style'] == $style->getOriginalId()) {
            $options['settings']['image_style'] = $style->id();
            $display->setComponent($name$options)
              ->save();
          }
        }
      }
      foreach (EntityFormDisplay::loadMultiple() as $display) {
        foreach ($display->getComponents() as $name => $options) {
          if (isset($options['type']) && $options['type'] == 'image_image' && $options['settings']['preview_image_style'] == $style->getOriginalId()) {
            
parent::setUp();
    $this->container->get('module_handler')->loadInclude('user', 'install');
    $this->installEntitySchema('user');
    user_install();
  }

  /** * Tests that the initial users have correct values. */
  public function testUserInstall() {
    $user_ids = \Drupal::entityQuery('user')->sort('uid')->accessCheck(FALSE)->execute();
    $users = \Drupal::entityTypeManager()->getStorage('user')->loadMultiple($user_ids);
    $anon = $users[0];
    $admin = $users[1];
    $this->assertNotEmpty($anon->uuid(), 'Anon user has a UUID');
    $this->assertNotEmpty($admin->uuid(), 'Admin user has a UUID');

    // Test that the anonymous and administrators languages are equal to the     // site's default language.     $this->assertEquals('en', $anon->language()->getId());
    $this->assertEquals('en', $admin->language()->getId());

    // Test that the administrator is active.
Home | Imprint | This part of the site doesn't use cookies.