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


PHP entity_load_multiple函数代码示例

本文整理汇总了PHP中entity_load_multiple函数的典型用法代码示例。如果您正苦于以下问题:PHP entity_load_multiple函数的具体用法?PHP entity_load_multiple怎么用?PHP entity_load_multiple使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了entity_load_multiple函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 = entity_load_multiple('taxonomy_term', 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 = entity_load('taxonomy_term', $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:anatalsceo,项目名称:en-classe,代码行数:38,代码来源:LoadMultipleTest.php

示例2: settingsForm

 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
 {
     $settings = $editor->getSettings();
     $medium_editors = array();
     foreach (entity_load_multiple('medium_editor') as $medium_editor) {
         $medium_editors[$medium_editor->id()] = $medium_editor->label();
     }
     // Default editor
     $form['default_editor'] = array('#type' => 'select', '#title' => $this->t('Medium Editor'), '#options' => $medium_editors, '#default_value' => $settings['default_editor'], '#description' => $this->t('Select the default editor for the authorized roles. Editors can be configured at <a href="!url">Medium admin page</a>.', array('!url' => \Drupal::url('medium.admin'))), '#empty_option' => '- ' . $this->t('Select an editor') . ' -');
     // Roles editors
     $role_ids = array();
     if ($format_form = $form_state->getCompleteForm()) {
         if (isset($format_form['roles']['#value'])) {
             $role_ids = $format_form['roles']['#value'];
         } elseif (isset($format_form['roles']['#default_value'])) {
             $role_ids = $format_form['roles']['#default_value'];
         }
     } elseif ($format = $editor->getFilterFormat()) {
         $role_ids = array_keys(filter_get_roles_by_format($format));
     }
     if (count($role_ids) > 1) {
         $form['roles_editors'] = array('#type' => 'details', '#title' => t('Role specific editors'));
         $roles = user_roles();
         foreach ($role_ids as $role_id) {
             $form['roles_editors'][$role_id] = array('#type' => 'select', '#title' => $this->t('Editor for %role', array('%role' => $roles[$role_id]->label())), '#options' => $medium_editors, '#default_value' => isset($settings['roles_editors'][$role_id]) ? $settings['roles_editors'][$role_id] : '', '#empty_option' => '- ' . $this->t('Use the default') . ' -');
         }
     }
     return $form;
 }
开发者ID:digideskio,项目名称:medium-editor-d8,代码行数:32,代码来源:MediumEditor.php

示例3: preRender

 public function preRender(&$values)
 {
     $vocabularies = entity_load_multiple('taxonomy_vocabulary');
     $this->field_alias = $this->aliases['nid'];
     $nids = array();
     foreach ($values as $result) {
         if (!empty($result->{$this->aliases['nid']})) {
             $nids[] = $result->{$this->aliases['nid']};
         }
     }
     if ($nids) {
         $vocabs = array_filter($this->options['vids']);
         if (empty($this->options['limit'])) {
             $vocabs = array();
         }
         $result = \Drupal::entityManager()->getStorage('taxonomy_term')->getNodeTerms($nids, $vocabs);
         foreach ($result as $node_nid => $data) {
             foreach ($data as $tid => $term) {
                 $this->items[$node_nid][$tid]['name'] = \Drupal::entityManager()->getTranslationFromContext($term)->label();
                 $this->items[$node_nid][$tid]['tid'] = $tid;
                 $this->items[$node_nid][$tid]['vocabulary_vid'] = $term->getVocabularyId();
                 $this->items[$node_nid][$tid]['vocabulary'] = String::checkPlain($vocabularies[$term->getVocabularyId()]->label());
                 if (!empty($this->options['link_to_taxonomy'])) {
                     $this->items[$node_nid][$tid]['make_link'] = TRUE;
                     $this->items[$node_nid][$tid]['path'] = 'taxonomy/term/' . $tid;
                 }
             }
         }
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:30,代码来源:TaxonomyIndexTid.php

示例4: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test', 'type' => 'text'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_two', 'type' => 'integer', 'cardinality' => -1))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_two', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_three', 'type' => 'decimal'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_three', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_integer_selectlist', 'type' => 'integer'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_integer_selectlist', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_exclude_unset', 'type' => 'text'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_exclude_unset', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_multivalue', 'type' => 'decimal', 'precision' => '10', 'scale' => '2', 'cardinality' => -1))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_multivalue', 'bundle' => 'test_planet'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_identical1', 'type' => 'integer'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_identical1', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_identical2', 'type' => 'integer'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_identical2', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_link', 'type' => 'link'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_link', 'bundle' => 'story'))->save();
     entity_create('field_storage_config', array('entity_type' => 'node', 'field_name' => 'field_test_filefield', 'type' => 'file'))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_filefield', 'bundle' => 'story'))->save();
     // Add some id mappings for the dependant migrations.
     $id_mappings = array('d6_field_formatter_settings' => array(array(array('page', 'default', 'node', 'field_test'), array('node', 'page', 'default', 'field_test'))), 'd6_field_instance_widget_settings' => array(array(array('page', 'field_test'), array('node', 'page', 'default', 'test'))), 'd6_node' => array(array(array(1), array(1)), array(array(2), array(2)), array(array(3), array(3))));
     $this->prepareMigrations($id_mappings);
     $migrations = entity_load_multiple('migration', array('d6_cck_field_values:*'));
     foreach ($migrations as $migration) {
         $executable = new MigrateExecutable($migration, $this);
         $executable->import();
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:35,代码来源:MigrateCckFieldValuesTest.php

示例5: prepareView

 /**
  * {@inheritdoc}
  *
  * Mark the accessible IDs a user can see. We do not unset unaccessible
  * values, as other may want to act on those values, even if they can
  * not be accessed.
  */
 public function prepareView(array $entities_items)
 {
     $target_ids = array();
     // Collect every possible entity attached to any of the entities.
     foreach ($entities_items as $items) {
         foreach ($items as $item) {
             if (!empty($item->target_id)) {
                 $target_ids[] = $item->target_id;
             }
         }
     }
     $target_type = $this->getFieldSetting('target_type');
     $target_entities = array();
     if ($target_ids) {
         $target_entities = entity_load_multiple($target_type, $target_ids);
     }
     // Iterate through the fieldable entities again to attach the loaded data.
     foreach ($entities_items as $items) {
         $rekey = FALSE;
         foreach ($items as $item) {
             if ($item->target_id !== 0 && !isset($target_entities[$item->target_id])) {
                 // The entity no longer exists, so empty the item.
                 $item->setValue(NULL);
                 $rekey = TRUE;
                 continue;
             }
             $item->originalEntity = $target_entities[$item->target_id];
         }
         // Re-key the items array if needed.
         if ($rekey) {
             $items->filterEmptyItems();
         }
     }
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:41,代码来源:EntityReferenceFormatterBase.php

示例6: testTagsField

 public function testTagsField()
 {
     $this->drupalLogin($this->admin_user);
     $this->drupalGet('node/add/page');
     $title_key = 'title[0][value]';
     $body_key = 'body[0][value]';
     // Fill in node creation form and preview node.
     $edit = array();
     $edit[$title_key] = $this->randomMachineName(8);
     $edit[$body_key] = $this->randomMachineName(16);
     $edit['tags'] = 'tag1, tag2, tag3';
     $this->drupalPostForm('node/add/page', $edit, t('Save and publish'));
     $tags = entity_load_multiple('taxonomy_term');
     foreach ($tags as $tag) {
         $this->assertSitemapLinkValues('taxonomy_term', $tag->id(), array('status' => 0, 'priority' => 0.5, 'changefreq' => 0));
         $tag->delete();
     }
     xmlsitemap_link_bundle_settings_save('taxonomy_term', 'tags', array('status' => 1, 'priority' => 0.2, 'changefreq' => XMLSITEMAP_FREQUENCY_HOURLY));
     $this->drupalPostForm('node/add/page', $edit, t('Save and publish'));
     $tags = entity_load_multiple('taxonomy_term');
     foreach ($tags as $tag) {
         $this->assertSitemapLinkValues('taxonomy_term', $tag->id(), array('status' => 1, 'priority' => 0.2, 'changefreq' => XMLSITEMAP_FREQUENCY_HOURLY));
         $tag->delete();
     }
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:25,代码来源:XmlSitemapNodeFunctionalTest.php

示例7: setUp

 protected function setUp()
 {
     parent::setUp();
     // Create a new content type
     $content_type = $this->drupalCreateContentType();
     // Add a node of the new content type.
     $node_data = array('type' => $content_type->type);
     $this->container->get('comment.manager')->addDefaultField('node', $content_type->type);
     $this->node = $this->drupalCreateNode($node_data);
     // Force a flush of the in-memory storage.
     $this->container->get('views.views_data')->clear();
     // Create some comments and attach them to the created node.
     for ($i = 0; $i < $this->masterDisplayResults; $i++) {
         /** @var \Drupal\comment\CommentInterface $comment */
         $comment = entity_create('comment', array('status' => CommentInterface::PUBLISHED, 'field_name' => 'comment', 'entity_type' => 'node', 'entity_id' => $this->node->id()));
         $comment->setOwnerId(0);
         $comment->setSubject('Test comment ' . $i);
         $comment->comment_body->value = 'Test body ' . $i;
         $comment->comment_body->format = 'full_html';
         // Ensure comments are sorted in ascending order.
         $time = REQUEST_TIME + ($this->masterDisplayResults - $i);
         $comment->setCreatedTime($time);
         $comment->changed->value = $time;
         $comment->save();
     }
     // Store all the nodes just created to access their properties on the tests.
     $this->commentsCreated = entity_load_multiple('comment');
     // Sort created comments in descending order.
     ksort($this->commentsCreated, SORT_NUMERIC);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:30,代码来源:DefaultViewRecentCommentsTest.php

示例8: setUp

 /**
  * Set up an administrative user account and testing keys.
  */
 public function setUp()
 {
     // Call parent::setUp() allowing test cases to pass further modules.
     parent::setUp();
     $this->admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer site configuration', 'administer xmlsitemap', 'access content'));
     $this->drupalLogin($this->admin_user);
     if (!$this->languageManager->getLanguage('fr')) {
         // Add a new language.
         $language = new Language(array('id' => 'fr', 'name' => 'French'));
         language_save($language);
     }
     if (!$this->languageManager->getLanguage('en')) {
         // Add a new language.
         $language = new Language(array('id' => 'en', 'name' => 'English'));
         language_save($language);
     }
     // Create the two different language-context sitemaps.
     $previous_sitemaps = entity_load_multiple('xmlsitemap');
     foreach ($previous_sitemaps as $previous_sitemap) {
         $previous_sitemap->delete();
     }
     $sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array());
     $sitemap->context = array('language' => 'en');
     xmlsitemap_sitemap_save($sitemap);
     $sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array());
     $sitemap->context = array('language' => 'fr');
     xmlsitemap_sitemap_save($sitemap);
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:31,代码来源:XmlSitemapMultilingualTestBase.php

示例9: testThemeBreakpointGroup

 /**
  * Test the breakpoints defined by the custom group.
  */
 public function testThemeBreakpointGroup()
 {
     // Verify the breakpoint group 'test' was created by breakpoint_test_theme.
     $breakpoint_group_obj = entity_create('breakpoint_group', array('label' => 'Test Theme', 'name' => 'test', 'sourceType' => Breakpoint::SOURCE_TYPE_THEME, 'source' => 'breakpoint_test_theme', 'id' => Breakpoint::SOURCE_TYPE_THEME . '.breakpoint_test_theme.test'));
     $breakpoint_group_obj->addBreakpoints(entity_load_multiple('breakpoint', array('theme.breakpoint_test_theme.mobile', 'theme.breakpoint_test_theme.narrow', 'theme.breakpoint_test_theme.wide')));
     // Verify we can load this breakpoint defined by the theme.
     $this->verifyBreakpointGroup($breakpoint_group_obj);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:11,代码来源:BreakpointThemeTest.php

示例10: getDerivativeDefinitions

 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     foreach (entity_load_multiple('taxonomy_vocabulary') as $voc) {
         $this->derivatives[$voc->vid] = $base_plugin_definition;
         $this->derivatives[$voc->vid]['admin_label'] = t('Tags in @voc', array('@voc' => $voc->name));
     }
     return $this->derivatives;
 }
开发者ID:neetumorwani,项目名称:blogging,代码行数:11,代码来源:TagcloudsTermsBlock.php

示例11: prepareView

 /**
  * {@inheritdoc}
  *
  * Mark the accessible IDs a user can see. We do not unset unaccessible
  * values, as other may want to act on those values, even if they can
  * not be accessed.
  */
 public function prepareView(array $entities_items)
 {
     $target_ids = array();
     $revision_ids = array();
     // Collect every possible entity attached to any of the entities.
     foreach ($entities_items as $items) {
         foreach ($items as $item) {
             if (!empty($item->revision_id)) {
                 $revision_ids[] = $item->revision_id;
             } elseif (!empty($item->target_id)) {
                 $target_ids[] = $item->target_id;
             }
         }
     }
     $target_type = $this->getFieldSetting('target_type');
     $target_entities = array();
     if ($target_ids) {
         $target_entities = entity_load_multiple($target_type, $target_ids);
     }
     if ($revision_ids) {
         // We need to load the revisions one by-one.
         foreach ($revision_ids as $revision_id) {
             $target_entity = entity_revision_load($target_type, $revision_id);
             // Use the revision ID in the key.
             $identifier = $target_entity->id() . ':' . $revision_id;
             $target_entities[$identifier] = $target_entity;
         }
     }
     // Iterate through the fieldable entities again to attach the loaded data.
     foreach ($entities_items as $items) {
         $rekey = FALSE;
         foreach ($items as $item) {
             // If we have a revision ID, the key uses it as well.
             $identifier = !empty($item->revision_id) ? $item->target_id . ':' . $item->revision_id : $item->target_id;
             if ($item->target_id !== 0) {
                 if (!isset($target_entities[$identifier])) {
                     // The entity no longer exists, so empty the item.
                     $item->setValue(NULL);
                     $rekey = TRUE;
                     continue;
                 }
                 $item->entity = $target_entities[$identifier];
                 if (!$item->entity->access('view')) {
                     continue;
                 }
             } else {
                 // This is an "auto_create" item, just leave the entity in place.
             }
             // Mark item as accessible.
             $item->access = TRUE;
         }
         // Rekey the items array if needed.
         if ($rekey) {
             $items->filterEmptyItems();
         }
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:64,代码来源:EntityReferenceFormatterBase.php

示例12: getDerivativeDefinitions

 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $block_contents = entity_load_multiple('block_content');
     foreach ($block_contents as $block_content) {
         $this->derivatives[$block_content->uuid()] = $base_plugin_definition;
         $this->derivatives[$block_content->uuid()]['admin_label'] = $block_content->label();
     }
     return parent::getDerivativeDefinitions($base_plugin_definition);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:12,代码来源:BlockContent.php

示例13: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     /** @var \Drupal\migrate\entity\Migration $migration */
     $migrations = entity_load_multiple('migration', array('d6_term_node:*'));
     foreach ($migrations as $migration) {
         $executable = new MigrateExecutable($migration, $this);
         $executable->import();
     }
 }
开发者ID:dev981,项目名称:gaptest,代码行数:13,代码来源:MigrateTermNodeTest.php

示例14: buildOptionsForm

 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     $vocabularies = entity_load_multiple('taxonomy_vocabulary');
     $options = array();
     foreach ($vocabularies as $voc) {
         $options[$voc->id()] = $voc->label();
     }
     $form['vids'] = array('#type' => 'checkboxes', '#title' => $this->t('Vocabularies'), '#options' => $options, '#default_value' => $this->options['vids'], '#description' => $this->t('Choose which vocabularies you wish to relate. Remember that every term found will create a new record, so this relationship is best used on just one vocabulary that has only one term per node.'));
     parent::buildOptionsForm($form, $form_state);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:10,代码来源:NodeTermData.php

示例15: preRender

 public function preRender($result)
 {
     $cids = array();
     foreach ($result as $row) {
         $cids[] = $row->cid;
     }
     $this->comments = entity_load_multiple('comment', $cids);
     foreach ($this->comments as $comment) {
         $comment->depth = count(explode('.', $comment->getThread())) - 1;
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:11,代码来源:Rss.php


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