当前位置: 首页>>代码示例>>PHP>>正文


PHP Term::loadMultiple方法代码示例

本文整理汇总了PHP中Drupal\taxonomy\Entity\Term::loadMultiple方法的典型用法代码示例。如果您正苦于以下问题:PHP Term::loadMultiple方法的具体用法?PHP Term::loadMultiple怎么用?PHP Term::loadMultiple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\taxonomy\Entity\Term的用法示例。


在下文中一共展示了Term::loadMultiple方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testTaxonomyTermMultipleLoad

 /**
  * Create a vocabulary and some taxonomy terms, ensuring they're loaded
  * correctly using entity_load_multiple().
  */
 function testTaxonomyTermMultipleLoad()
 {
     // Create a vocabulary.
     $vocabulary = $this->createVocabulary();
     // Create five terms in the vocabulary.
     $i = 0;
     while ($i < 5) {
         $i++;
         $this->createTerm($vocabulary);
     }
     // Load the terms from the vocabulary.
     $terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id()));
     $count = count($terms);
     $this->assertEqual($count, 5, format_string('Correct number of terms were loaded. @count terms.', array('@count' => $count)));
     // Load the same terms again by tid.
     $terms2 = Term::loadMultiple(array_keys($terms));
     $this->assertEqual($count, count($terms2), 'Five terms were loaded by tid.');
     $this->assertEqual($terms, $terms2, 'Both arrays contain the same terms.');
     // Remove one term from the array, then delete it.
     $deleted = array_shift($terms2);
     $deleted->delete();
     $deleted_term = Term::load($deleted->id());
     $this->assertFalse($deleted_term);
     // Load terms from the vocabulary by vid.
     $terms3 = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id()));
     $this->assertEqual(count($terms3), 4, 'Correct number of terms were loaded.');
     $this->assertFalse(isset($terms3[$deleted->id()]));
     // Create a single term and load it by name.
     $term = $this->createTerm($vocabulary);
     $loaded_terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $term->getName()));
     $this->assertEqual(count($loaded_terms), 1, 'One term was loaded.');
     $loaded_term = reset($loaded_terms);
     $this->assertEqual($term->id(), $loaded_term->id(), 'Term loaded by name successfully.');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:38,代码来源:LoadMultipleTest.php

示例2: testTaxonomyTerms

 /**
  * Tests the Drupal 6 taxonomy term to Drupal 8 migration.
  */
 public function testTaxonomyTerms()
 {
     $expected_results = array('1' => array('source_vid' => 1, 'vid' => 'vocabulary_1_i_0_', 'weight' => 0, 'parent' => array(0)), '2' => array('source_vid' => 2, 'vid' => 'vocabulary_2_i_1_', 'weight' => 3, 'parent' => array(0)), '3' => array('source_vid' => 2, 'vid' => 'vocabulary_2_i_1_', 'weight' => 4, 'parent' => array(2)), '4' => array('source_vid' => 3, 'vid' => 'vocabulary_3_i_2_', 'weight' => 6, 'parent' => array(0)), '5' => array('source_vid' => 3, 'vid' => 'vocabulary_3_i_2_', 'weight' => 7, 'parent' => array(4)), '6' => array('source_vid' => 3, 'vid' => 'vocabulary_3_i_2_', 'weight' => 8, 'parent' => array(4, 5)));
     $terms = Term::loadMultiple(array_keys($expected_results));
     // Find each term in the tree.
     $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
     $vids = array_unique(array_column($expected_results, 'vid'));
     $tree_terms = [];
     foreach ($vids as $vid) {
         foreach ($storage->loadTree($vid) as $term) {
             $tree_terms[$term->tid] = $term;
         }
     }
     foreach ($expected_results as $tid => $values) {
         /** @var Term $term */
         $term = $terms[$tid];
         $this->assertIdentical("term {$tid} of vocabulary {$values['source_vid']}", $term->name->value);
         $this->assertIdentical("description of term {$tid} of vocabulary {$values['source_vid']}", $term->description->value);
         $this->assertIdentical($values['vid'], $term->vid->target_id);
         $this->assertIdentical((string) $values['weight'], $term->weight->value);
         if ($values['parent'] === array(0)) {
             $this->assertNull($term->parent->target_id);
         } else {
             $parents = array();
             foreach (\Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($tid) as $parent) {
                 $parents[] = (int) $parent->id();
             }
             $this->assertIdentical($parents, $values['parent']);
         }
         $this->assertArrayHasKey($tid, $tree_terms, "Term {$tid} exists in vocabulary tree");
         $tree_term = $tree_terms[$tid];
         $this->assertEquals($values['parent'], $tree_term->parents, "Term {$tid} has correct parents in vocabulary tree");
     }
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:37,代码来源:MigrateTaxonomyTermTest.php

示例3: titleQuery

 public function titleQuery()
 {
     $titles = array();
     $terms = Term::loadMultiple($this->value);
     foreach ($terms as $term) {
         $titles[] = \Drupal::entityManager()->getTranslationFromContext($term)->label();
     }
     return $titles;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:9,代码来源:IndexTid.php

示例4: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $config = $this->getConfiguration();
     if (!isset($config['vocabulary']) || !$config['vocabulary']) {
         return;
     }
     $query = \Drupal::entityQuery('taxonomy_term')->condition('vid', $config['vocabulary']);
     $tids = $query->execute();
     if (!$tids) {
         return;
     }
     $terms = Term::loadMultiple($tids);
     if (!$terms) {
         return;
     }
     return array('#theme' => 'item_list', '#items' => $this->buildTermList($terms));
 }
开发者ID:freefree12,项目名称:d8-demo-modules,代码行数:20,代码来源:VocabularyTerms.php

示例5: testTaxonomyTerms

 /**
  * Tests the Drupal 6 taxonomy term to Drupal 8 migration.
  */
 public function testTaxonomyTerms()
 {
     $expected_results = array('1' => array('source_vid' => 1, 'vid' => 'vocabulary_1_i_0_', 'weight' => 0, 'parent' => array(2)), '2' => array('source_vid' => 2, 'vid' => 'vocabulary_2_i_1_', 'weight' => 3, 'parent' => array(0)), '3' => array('source_vid' => 2, 'vid' => 'vocabulary_2_i_1_', 'weight' => 4, 'parent' => array(2)), '4' => array('source_vid' => 3, 'vid' => 'vocabulary_3_i_2_', 'weight' => 6, 'parent' => array(0)), '5' => array('source_vid' => 3, 'vid' => 'vocabulary_3_i_2_', 'weight' => 7, 'parent' => array(4)), '6' => array('source_vid' => 3, 'vid' => 'vocabulary_3_i_2_', 'weight' => 8, 'parent' => array(4, 5)));
     $terms = Term::loadMultiple(array_keys($expected_results));
     foreach ($expected_results as $tid => $values) {
         /** @var Term $term */
         $term = $terms[$tid];
         $this->assertIdentical($term->name->value, "term {$tid} of vocabulary {$values['source_vid']}");
         $this->assertIdentical($term->description->value, "description of term {$tid} of vocabulary {$values['source_vid']}");
         $this->assertEqual($term->vid->target_id, $values['vid']);
         $this->assertEqual($term->weight->value, $values['weight']);
         if ($values['parent'] === array(0)) {
             $this->assertEqual($term->parent->target_id, 0);
         } else {
             $parents = array();
             foreach (taxonomy_term_load_parents($tid) as $parent) {
                 $parents[] = $parent->id();
             }
             $this->assertEqual($values['parent'], $parents);
         }
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:25,代码来源:MigrateTaxonomyTermTest.php

示例6: testTaxonomyTerms

 /**
  * Tests the Drupal 6 taxonomy term to Drupal 8 migration.
  */
 public function testTaxonomyTerms()
 {
     $expected_results = array('1' => array('source_vid' => 1, 'vid' => 'vocabulary_1_i_0_', 'weight' => 0, 'parent' => array(0)), '2' => array('source_vid' => 2, 'vid' => 'vocabulary_2_i_1_', 'weight' => 3, 'parent' => array(0)), '3' => array('source_vid' => 2, 'vid' => 'vocabulary_2_i_1_', 'weight' => 4, 'parent' => array(2)), '4' => array('source_vid' => 3, 'vid' => 'vocabulary_3_i_2_', 'weight' => 6, 'parent' => array(0)), '5' => array('source_vid' => 3, 'vid' => 'vocabulary_3_i_2_', 'weight' => 7, 'parent' => array(4)), '6' => array('source_vid' => 3, 'vid' => 'vocabulary_3_i_2_', 'weight' => 8, 'parent' => array(4, 5)));
     $terms = Term::loadMultiple(array_keys($expected_results));
     foreach ($expected_results as $tid => $values) {
         /** @var Term $term */
         $term = $terms[$tid];
         $this->assertIdentical("term {$tid} of vocabulary {$values['source_vid']}", $term->name->value);
         $this->assertIdentical("description of term {$tid} of vocabulary {$values['source_vid']}", $term->description->value);
         $this->assertIdentical($values['vid'], $term->vid->target_id);
         $this->assertIdentical((string) $values['weight'], $term->weight->value);
         if ($values['parent'] === array(0)) {
             $this->assertNull($term->parent->target_id);
         } else {
             $parents = array();
             foreach (\Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($tid) as $parent) {
                 $parents[] = (int) $parent->id();
             }
             $this->assertIdentical($parents, $values['parent']);
         }
     }
 }
开发者ID:scratch,项目名称:gai,代码行数:25,代码来源:MigrateTaxonomyTermTest.php

示例7: adminSummary

 public function adminSummary()
 {
     // set up $this->valueOptions for the parent summary
     $this->valueOptions = array();
     if ($this->value) {
         $this->value = array_filter($this->value);
         $terms = Term::loadMultiple($this->value);
         foreach ($terms as $term) {
             $this->valueOptions[$term->id()] = SafeMarkup::checkPlain(\Drupal::entityManager()->getTranslationFromContext($term)->label());
         }
     }
     return parent::adminSummary();
 }
开发者ID:jeyram,项目名称:camp-gdl,代码行数:13,代码来源:TaxonomyIndexTid.php

示例8: testInstallUninstall

 /**
  * Tests that a fixed set of modules can be installed and uninstalled.
  */
 public function testInstallUninstall()
 {
     // Get a list of modules to enable.
     $all_modules = system_rebuild_module_data();
     $all_modules = array_filter($all_modules, function ($module) {
         // Filter contrib, hidden, already enabled modules and modules in the
         // Testing package.
         if ($module->origin !== 'core' || !empty($module->info['hidden']) || $module->status == TRUE || $module->info['package'] == 'Testing') {
             return FALSE;
         }
         return TRUE;
     });
     // Install every module possible.
     \Drupal::service('module_installer')->install(array_keys($all_modules));
     $this->assertModules(array_keys($all_modules), TRUE);
     foreach ($all_modules as $module => $info) {
         $this->assertModuleConfig($module);
         $this->assertModuleTablesExist($module);
     }
     // Export active config to sync.
     $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
     system_list_reset();
     $this->resetAll();
     // Delete every field on the site so all modules can be uninstalled. For
     // example, if a comment field exists then module becomes required and can
     // not be uninstalled.
     $field_storages = \Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple();
     \Drupal::entityManager()->getStorage('field_storage_config')->delete($field_storages);
     // Purge the data.
     field_purge_batch(1000);
     // Delete all terms.
     $terms = Term::loadMultiple();
     entity_delete_multiple('taxonomy_term', array_keys($terms));
     // Delete all filter formats.
     $filters = FilterFormat::loadMultiple();
     entity_delete_multiple('filter_format', array_keys($filters));
     // Delete any shortcuts so the shortcut module can be uninstalled.
     $shortcuts = Shortcut::loadMultiple();
     entity_delete_multiple('shortcut', array_keys($shortcuts));
     system_list_reset();
     $all_modules = system_rebuild_module_data();
     // Ensure that only core required modules and the install profile can not be uninstalled.
     $validation_reasons = \Drupal::service('module_installer')->validateUninstall(array_keys($all_modules));
     $this->assertEqual(['standard', 'system', 'user'], array_keys($validation_reasons));
     $modules_to_uninstall = array_filter($all_modules, function ($module) use($validation_reasons) {
         // Filter required and not enabled modules.
         if (!empty($module->info['required']) || $module->status == FALSE) {
             return FALSE;
         }
         return TRUE;
     });
     // Can not uninstall config and use admin/config/development/configuration!
     unset($modules_to_uninstall['config']);
     $this->assertTrue(isset($modules_to_uninstall['comment']), 'The comment module will be disabled');
     $this->assertTrue(isset($modules_to_uninstall['file']), 'The File module will be disabled');
     $this->assertTrue(isset($modules_to_uninstall['editor']), 'The Editor module will be disabled');
     // Uninstall all modules that can be uninstalled.
     \Drupal::service('module_installer')->uninstall(array_keys($modules_to_uninstall));
     $this->assertModules(array_keys($modules_to_uninstall), FALSE);
     foreach ($modules_to_uninstall as $module => $info) {
         $this->assertNoModuleConfig($module);
         $this->assertModuleTablesDoNotExist($module);
     }
     // Import the configuration thereby re-installing all the modules.
     $this->drupalPostForm('admin/config/development/configuration', array(), t('Import all'));
     // Modules have been installed that have services.
     $this->rebuildContainer();
     // Check that there are no errors.
     $this->assertIdentical($this->configImporter()->getErrors(), array());
     // Check that all modules that were uninstalled are now reinstalled.
     $this->assertModules(array_keys($modules_to_uninstall), TRUE);
     foreach ($modules_to_uninstall as $module => $info) {
         $this->assertModuleConfig($module);
         $this->assertModuleTablesExist($module);
     }
     // Ensure that we have no configuration changes to import.
     $storage_comparer = new StorageComparer($this->container->get('config.storage.sync'), $this->container->get('config.storage'), $this->container->get('config.manager'));
     $this->assertIdentical($storage_comparer->createChangelist()->getChangelist(), $storage_comparer->getEmptyChangelist());
     // Now we have all configuration imported, test all of them for schema
     // conformance. Ensures all imported default configuration is valid when
     // all modules are enabled.
     $names = $this->container->get('config.storage')->listAll();
     /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */
     $typed_config = $this->container->get('config.typed');
     foreach ($names as $name) {
         $config = $this->config($name);
         $this->assertConfigSchema($typed_config, $name, $config->get());
     }
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:92,代码来源:ConfigImportAllTest.php

示例9: getTipuriCarburant

 /**
  * @return static[]
  */
 public static function getTipuriCarburant()
 {
     $tip_carburant_ids = \Drupal::entityQuery('taxonomy_term')->condition('vid', 'tip_carburant')->execute();
     $tipuri_carburant = Term::loadMultiple($tip_carburant_ids);
     return $tipuri_carburant;
 }
开发者ID:hacktm15,项目名称:lapompa,代码行数:9,代码来源:TipCarburant.php


注:本文中的Drupal\taxonomy\Entity\Term::loadMultiple方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。