• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP entity_load_multiple_by_properties函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testNodeMultipleLoad

 /**
  * Creates four nodes and ensures that they are loaded correctly.
  */
 function testNodeMultipleLoad()
 {
     $node1 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
     $node2 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
     $node3 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 0));
     $node4 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0));
     // Confirm that promoted nodes appear in the default node listing.
     $this->drupalGet('node');
     $this->assertText($node1->label(), 'Node title appears on the default listing.');
     $this->assertText($node2->label(), 'Node title appears on the default listing.');
     $this->assertNoText($node3->label(), 'Node title does not appear in the default listing.');
     $this->assertNoText($node4->label(), 'Node title does not appear in the default listing.');
     // Load nodes with only a condition. Nodes 3 and 4 will be loaded.
     $nodes = entity_load_multiple_by_properties('node', array('promote' => 0));
     $this->assertEqual($node3->label(), $nodes[$node3->id()]->label(), 'Node was loaded.');
     $this->assertEqual($node4->label(), $nodes[$node4->id()]->label(), 'Node was loaded.');
     $count = count($nodes);
     $this->assertTrue($count == 2, format_string('@count nodes loaded.', array('@count' => $count)));
     // Load nodes by nid. Nodes 1, 2 and 4 will be loaded.
     $nodes = Node::loadMultiple(array(1, 2, 4));
     $count = count($nodes);
     $this->assertTrue(count($nodes) == 3, format_string('@count nodes loaded', array('@count' => $count)));
     $this->assertTrue(isset($nodes[$node1->id()]), 'Node is correctly keyed in the array');
     $this->assertTrue(isset($nodes[$node2->id()]), 'Node is correctly keyed in the array');
     $this->assertTrue(isset($nodes[$node4->id()]), 'Node is correctly keyed in the array');
     foreach ($nodes as $node) {
         $this->assertTrue(is_object($node), 'Node is an object');
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:32,代码来源:NodeLoadMultipleTest.php


示例2: testMetatag

 /**
  * Tests adding and editing values using metatag.
  */
 public function testMetatag()
 {
     // Create a test entity.
     $edit = ['name[0][value]' => 'Barfoo', 'user_id[0][target_id]' => 'foo (' . $this->adminUser->id() . ')'];
     $this->drupalPostForm('entity_test/add', $edit, t('Save'));
     $entities = entity_load_multiple_by_properties('entity_test', ['name' => 'Barfoo']);
     $this->assertEqual(1, count($entities), 'Entity was saved');
     $entity = reset($entities);
     // Update the Global defaults and test them.
     $values = array('keywords' => 'Purple monkey dishwasher');
     $this->drupalPostForm('admin/structure/metatag_defaults/global', $values, 'Save');
     $this->assertText('Saved the Global Metatag defaults.');
     $this->drupalGet('entity_test/' . $entity->id());
     $elements = $this->cssSelect('meta[name=keywords]');
     $this->assertTrue(count($elements) === 1, 'Found keywords metatag from defaults');
     $this->assertEqual((string) $elements[0]['content'], $values['keywords'], 'Default keywords applied');
     // Tests metatags with urls work.
     $edit = ['name[0][value]' => 'UrlTags', 'user_id[0][target_id]' => 'foo (' . $this->adminUser->id() . ')', 'field_metatag[0][open_graph][og_url]' => 'http://example.com/foo.html'];
     $this->drupalPostForm('entity_test/add', $edit, t('Save'));
     $entities = entity_load_multiple_by_properties('entity_test', ['name' => 'UrlTags']);
     $this->assertEqual(1, count($entities), 'Entity was saved');
     $entity = reset($entities);
     $this->drupalGet('entity_test/' . $entity->id());
     $elements = $this->cssSelect("meta[property='og:url']");
     $this->assertTrue(count($elements) === 1, 'Found keywords metatag from defaults');
     $this->assertEqual((string) $elements[0]['content'], $edit['field_metatag[0][open_graph][og_url]']);
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:30,代码来源:MetatagFieldTest.php


示例3: loadEntityByName

 /**
  * Loads a test entity by name always resetting the storage cache.
  */
 protected function loadEntityByName($entity_type, $name)
 {
     // Always load the entity from the database to ensure that changes are
     // correctly picked up.
     $this->container->get('entity.manager')->getStorage($entity_type)->resetCache();
     return current(entity_load_multiple_by_properties($entity_type, array('name' => $name)));
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:10,代码来源:EntityFormTest.php


示例4: at_core_submit_mobile_blocks

/**
 * @file
 * Save Breadcrumb CSS to file
 */
function at_core_submit_mobile_blocks($values, $theme, $generated_files_path) {
  $mobile_blocks_css = array();
  $theme_blocks = entity_load_multiple_by_properties('block', ['theme' => $theme]);

  if (!empty($theme_blocks)) {
    foreach ($theme_blocks as $block_key => $block_values) {
      $block_id = $block_values->id();
      if (isset($values['settings_mobile_block_show_' . $block_id]) && $values['settings_mobile_block_show_' . $block_id] == 1) {
        $block_selector = '#' . Html::getUniqueId('block-' . $block_id);
        $mobile_blocks_css[] = $block_selector . ' {display:none}' . "\n";
        $mobile_blocks_css[] = '.is-mobile ' . $block_selector . ' {display:block}' . "\n";
      }
      if (isset($values['settings_mobile_block_hide_' . $block_id]) && $values['settings_mobile_block_hide_' . $block_id] == 1) {
        $block_selector = '#' . Html::getUniqueId('block-' . $block_id);
        $mobile_blocks_css[] = '.is-mobile ' . $block_selector . ' {display:none}' . "\n";
        $mobile_blocks_css[] = $block_selector . ' {display:block}' . "\n";
      }
    }
  }

  if (!empty($mobile_blocks_css)) {
    $file_name = 'mobile-blocks.css';
    $filepath = $generated_files_path . '/' . $file_name;
    file_unmanaged_save_data($mobile_blocks_css, $filepath, FILE_EXISTS_REPLACE);
  }
}
开发者ID:jno84,项目名称:drupal8,代码行数:30,代码来源:mobile_blocks_submit.php


示例5: testFeedLanguage

 /**
  * Tests creation of feeds with a language.
  */
 public function testFeedLanguage()
 {
     $admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'administer news feeds', 'access news feeds', 'create article content']);
     $this->drupalLogin($admin_user);
     // Enable language selection for feeds.
     $edit['entity_types[aggregator_feed]'] = TRUE;
     $edit['settings[aggregator_feed][aggregator_feed][settings][language][language_alterable]'] = TRUE;
     $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
     /** @var \Drupal\aggregator\FeedInterface[] $feeds */
     $feeds = array();
     // Create feeds.
     $feeds[1] = $this->createFeed(NULL, array('langcode[0][value]' => $this->langcodes[1]));
     $feeds[2] = $this->createFeed(NULL, array('langcode[0][value]' => $this->langcodes[2]));
     // Make sure that the language has been assigned.
     $this->assertEqual($feeds[1]->language()->getId(), $this->langcodes[1]);
     $this->assertEqual($feeds[2]->language()->getId(), $this->langcodes[2]);
     // Create example nodes to create feed items from and then update the feeds.
     $this->createSampleNodes();
     $this->cronRun();
     // Loop over the created feed items and verify that their language matches
     // the one from the feed.
     foreach ($feeds as $feed) {
         /** @var \Drupal\aggregator\ItemInterface[] $items */
         $items = entity_load_multiple_by_properties('aggregator_item', array('fid' => $feed->id()));
         $this->assertTrue(count($items) > 0, 'Feed items were created.');
         foreach ($items as $item) {
             $this->assertEqual($item->language()->getId(), $feed->language()->getId());
         }
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:33,代码来源:FeedLanguageTest.php


示例6: 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


示例7: testTaxonomyImageAccess

 public function testTaxonomyImageAccess()
 {
     $user = $this->drupalCreateUser(array('administer site configuration', 'administer taxonomy', 'access user profiles'));
     $this->drupalLogin($user);
     // Create a term and upload the image.
     $files = $this->drupalGetTestFiles('image');
     $image = array_pop($files);
     $edit['name[0][value]'] = $this->randomMachineName();
     $edit['files[field_test_0]'] = drupal_realpath($image->uri);
     $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
     $this->drupalPostForm(NULL, ['field_test[0][alt]' => $this->randomMachineName()], t('Save'));
     $terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $edit['name[0][value]']));
     $term = reset($terms);
     $this->assertText(t('Created new term @name.', array('@name' => $term->getName())));
     // Create a user that should have access to the file and one that doesn't.
     $access_user = $this->drupalCreateUser(array('access content'));
     $no_access_user = $this->drupalCreateUser();
     $image = File::load($term->field_test->target_id);
     $this->drupalLogin($access_user);
     $this->drupalGet(file_create_url($image->getFileUri()));
     $this->assertResponse(200, 'Private image on term is accessible with right permission');
     $this->drupalLogin($no_access_user);
     $this->drupalGet(file_create_url($image->getFileUri()));
     $this->assertResponse(403, 'Private image on term not accessible without right permission');
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:25,代码来源:TaxonomyImageTest.php


示例8: testForumUninstallWithField

 /**
  * Tests if forum module uninstallation properly deletes the field.
  */
 public function testForumUninstallWithField()
 {
     $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'administer nodes', 'administer modules', 'delete any forum content', 'administer content types']));
     // Ensure that the field exists before uninstallation.
     $field_storage = FieldStorageConfig::loadByName('node', 'taxonomy_forums');
     $this->assertNotNull($field_storage, 'The taxonomy_forums field storage exists.');
     // Create a taxonomy term.
     $term = entity_create('taxonomy_term', array('name' => t('A term'), 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(), 'description' => '', 'parent' => array(0), 'vid' => 'forums', 'forum_container' => 0));
     $term->save();
     // Create a forum node.
     $node = $this->drupalCreateNode(array('title' => 'A forum post', 'type' => 'forum', 'taxonomy_forums' => array(array('target_id' => $term->id()))));
     // Create at least one comment against the forum node.
     $comment = entity_create('comment', array('entity_id' => $node->nid->value, 'entity_type' => 'node', 'field_name' => 'comment_forum', 'pid' => 0, 'uid' => 0, 'status' => CommentInterface::PUBLISHED, 'subject' => $this->randomMachineName(), 'hostname' => '127.0.0.1'));
     $comment->save();
     // Attempt to uninstall forum.
     $this->drupalGet('admin/modules/uninstall');
     // Assert forum is required.
     $this->assertNoFieldByName('uninstall[forum]');
     $this->drupalGet('admin/modules');
     $this->assertText('To uninstall Forum first delete all Forum content');
     // Delete the node.
     $this->drupalPostForm('node/' . $node->id() . '/delete', array(), t('Delete'));
     // Attempt to uninstall forum.
     $this->drupalGet('admin/modules/uninstall');
     // Assert forum is still required.
     $this->assertNoFieldByName('uninstall[forum]');
     $this->drupalGet('admin/modules');
     $this->assertText('To uninstall Forum first delete all Forums terms');
     // Delete any forum terms.
     $vid = $this->config('forum.settings')->get('vocabulary');
     $terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vid]);
     foreach ($terms as $term) {
         $term->delete();
     }
     // Ensure that the forum node type can not be deleted.
     $this->drupalGet('admin/structure/types/manage/forum');
     $this->assertNoLink(t('Delete'));
     // Now attempt to uninstall forum.
     $this->drupalGet('admin/modules/uninstall');
     // Assert forum is no longer required.
     $this->assertFieldByName('uninstall[forum]');
     $this->drupalGet('admin/modules');
     $this->assertNoText('To uninstall Forum first delete all Forum content');
     $this->drupalPostForm('admin/modules/uninstall', array('uninstall[forum]' => 1), t('Uninstall'));
     $this->drupalPostForm(NULL, [], t('Uninstall'));
     // Check that the field is now deleted.
     $field_storage = FieldStorageConfig::loadByName('node', 'taxonomy_forums');
     $this->assertNull($field_storage, 'The taxonomy_forums field storage has been deleted.');
     // Check that a node type with a machine name of forum can be created after
     // uninstalling the forum module and the node type is not locked.
     $edit = array('name' => 'Forum', 'title_label' => 'title for forum', 'type' => 'forum');
     $this->drupalPostForm('admin/structure/types/add', $edit, t('Save content type'));
     $this->assertTrue((bool) NodeType::load('forum'), 'Node type with machine forum created.');
     $this->drupalGet('admin/structure/types/manage/forum');
     $this->clickLink(t('Delete'));
     $this->drupalPostForm(NULL, array(), t('Delete'));
     $this->assertResponse(200);
     $this->assertFalse((bool) NodeType::load('forum'), 'Node type with machine forum deleted.');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:62,代码来源:ForumUninstallTest.php


示例9: purgeFieldData

 /**
  * Purges a field data.
  */
 public static function purgeFieldData()
 {
     do {
         field_purge_batch(1000);
         $properties = array('deleted' => TRUE, 'include_deleted' => TRUE);
         $fields = entity_load_multiple_by_properties('field_config', $properties);
     } while ($fields);
 }
开发者ID:aritnath1990,项目名称:simplenewslatest,代码行数:11,代码来源:PrepareUninstallForm.php


示例10: testDelete

 /**
  * Test deleting functionality.
  */
 public function testDelete()
 {
     $feed = $this->createFeed();
     $this->updateAndDelete($feed, NULL);
     // Make sure the feed title is changed.
     $entities = entity_load_multiple_by_properties('aggregator_feed', array('description' => $feed->description->value));
     $this->assertTrue(empty($entities));
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:11,代码来源:FeedProcessorPluginTest.php


示例11: drupalGetBlockByInfo

 /**
  * Get a custom block from the database based on its title.
  *
  * @param $info
  *   A block title, usually generated by $this->randomMachineName().
  * @param $reset
  *   (optional) Whether to reset the entity cache.
  *
  * @return \Drupal\block\BlockInterface
  *   A block entity matching $info.
  */
 function drupalGetBlockByInfo($info, $reset = FALSE)
 {
     if ($reset) {
         \Drupal::entityManager()->getStorage('block_content')->resetCache();
     }
     $blocks = entity_load_multiple_by_properties('block_content', array('info' => $info));
     // Get the first block returned from the database.
     $returned_block = reset($blocks);
     return $returned_block;
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:21,代码来源:EntityReferenceRevisionsAutocompleteTest.php


示例12: testTermDelete

 /**
  * Deleting terms should also remove related vocabulary.
  * Deleting an invalid term should silently fail.
  */
 public function testTermDelete()
 {
     $vocabulary = $this->createVocabulary();
     $valid_term = $this->createTerm($vocabulary);
     // Delete a valid term.
     $valid_term->delete();
     $terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id()));
     $this->assertTrue(empty($terms), 'Vocabulary is empty after deletion');
     // Delete an invalid term. Should not throw any notices.
     entity_delete_multiple('taxonomy_term', array(42));
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:15,代码来源:TermKernelTest.php


示例13: generateFields

 /**
  * Enrich the $object that is about to be saved with arbitrary
  * information in each of its fields.
  */
 public static function generateFields(EntityInterface &$object, $entity_type, $bundle_name, $form_mode = 'default', $namespace = 'devel_generate')
 {
     $instances = entity_load_multiple_by_properties('field_instance_config', array('entity_type' => $entity_type, 'bundle' => $bundle_name));
     $field_types = \Drupal::service('plugin.manager.field.field_type')->getDefinitions();
     $skips = function_exists('drush_get_option') ? drush_get_option('skip-fields', '') : @$_REQUEST['skip-fields'];
     foreach (explode(',', $skips) as $skip) {
         unset($instances[$skip]);
     }
     foreach ($instances as $instance) {
         $field = $instance->getFieldStorageDefinition();
         $cardinality = $field->getCardinality();
         $field_name = $field->getName();
         $object_field = array();
         // If module handles own multiples, then only call its hook once.
         $form_display_options = entity_get_form_display($entity_type, $bundle_name, $form_mode)->getComponent($field_name);
         $plugin_definition = \Drupal::service('plugin.manager.field.widget')->getDefinition($form_display_options['type']);
         if (isset($plugin_definition['multiple_values']) && $plugin_definition['multiple_values'] === TRUE) {
             $max = 0;
         } else {
             switch ($cardinality) {
                 case FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED:
                     $max = rand(0, 3);
                     //just an arbitrary number for 'unlimited'
                     break;
                 default:
                     $max = $cardinality - 1;
                     break;
             }
         }
         for ($i = 0; $i <= $max; $i++) {
             $provider = $field_types[$field->type]['provider'];
             if (!in_array($provider, array('file', 'image', 'taxonomy', 'number', 'text', 'options', 'email', 'link'))) {
                 continue;
             }
             $devel_generate_field_factory = new DevelGenerateFieldFactory();
             $devel_generate_field_object = $devel_generate_field_factory->createInstance($provider, $namespace);
             if ($devel_generate_field_object instanceof DevelGenerateFieldBaseInterface) {
                 if ($result = $devel_generate_field_object->generate($object, $instance, $plugin_definition, $form_display_options)) {
                     if (isset($plugin_definition['multiple_values']) && $plugin_definition['multiple_values'] === TRUE) {
                         // Fields that handle their own multiples will add their own deltas.
                         $object_field = $result;
                     } else {
                         // When multiples are handled by the content module, add a delta for each result.
                         $object_field[$i] = $result;
                     }
                 }
             }
         }
         $object->{$field_name} = $object_field;
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:55,代码来源:DevelGenerateFieldBase.php


示例14: testMenuLanguage

 /**
  * Tests menu language settings and the defaults for menu link items.
  */
 function testMenuLanguage()
 {
     // Create a test menu to test the various language-related settings.
     // Machine name has to be lowercase.
     $menu_name = Unicode::strtolower($this->randomMachineName(16));
     $label = $this->randomString();
     $edit = array('id' => $menu_name, 'description' => '', 'label' => $label, 'langcode' => 'aa');
     $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
     language_save_default_configuration('menu_link_content', 'menu_link_content', array('langcode' => 'bb', 'language_show' => TRUE));
     // Check menu language.
     $this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The menu language was correctly selected.');
     // Test menu link language.
     $link_path = '<front>';
     // Add a menu link.
     $link_title = $this->randomString();
     $edit = array('title[0][value]' => $link_title, 'url' => $link_path);
     $this->drupalPostForm("admin/structure/menu/manage/{$menu_name}/add", $edit, t('Save'));
     // Check the link was added with the correct menu link default language.
     $menu_links = entity_load_multiple_by_properties('menu_link_content', array('title' => $link_title));
     $menu_link = reset($menu_links);
     $this->assertMenuLink($menu_link->getPluginId(), array('menu_name' => $menu_name, 'route_name' => '<front>', 'langcode' => 'bb'));
     // Edit menu link default, changing it to cc.
     language_save_default_configuration('menu_link_content', 'menu_link_content', array('langcode' => 'cc', 'language_show' => TRUE));
     // Add a menu link.
     $link_title = $this->randomString();
     $edit = array('title[0][value]' => $link_title, 'url' => $link_path);
     $this->drupalPostForm("admin/structure/menu/manage/{$menu_name}/add", $edit, t('Save'));
     // Check the link was added with the correct new menu link default language.
     $menu_links = entity_load_multiple_by_properties('menu_link_content', array('title' => $link_title));
     $menu_link = reset($menu_links);
     $this->assertMenuLink($menu_link->getPluginId(), array('menu_name' => $menu_name, 'route_name' => '<front>', 'langcode' => 'cc'));
     // Now change the language of the new link to 'bb'.
     $edit = array('langcode' => 'bb');
     $this->drupalPostForm('admin/structure/menu/item/' . $menu_link->id() . '/edit', $edit, t('Save'));
     $this->assertMenuLink($menu_link->getPluginId(), array('menu_name' => $menu_name, 'route_name' => '<front>', 'langcode' => 'bb'));
     // Saving menu link items ends up on the edit menu page. To check the menu
     // link has the correct language default on edit, go to the menu link edit
     // page first.
     $this->drupalGet('admin/structure/menu/item/' . $menu_link->id() . '/edit');
     // Check that the language selector has the correct default value.
     $this->assertOptionSelected('edit-langcode', 'bb', 'The menu link language was correctly selected.');
     // Edit menu to hide the language select on menu link item add.
     language_save_default_configuration('menu_link_content', 'menu_link_content', array('langcode' => 'cc', 'language_show' => FALSE));
     // Check that the language selector is not available on menu link add page.
     $this->drupalGet("admin/structure/menu/manage/{$menu_name}/add");
     $this->assertNoField('edit-langcode', 'The language selector field was hidden the page');
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:50,代码来源:MenuLanguageTest.php


示例15: populateFields

 /**
  * Populate the fields on a given entity with sample values.
  *
  * @param $entity
  *  The entity to be enriched with sample field values.
  */
 public function populateFields(EntityInterface $entity)
 {
     $instances = entity_load_multiple_by_properties('field_instance_config', array('entity_type' => $entity->getEntityType()->id(), 'bundle' => $entity->bundle()));
     if ($skips = function_exists('drush_get_option') ? drush_get_option('skip-fields', '') : @$_REQUEST['skip-fields']) {
         foreach (explode(',', $skips) as $skip) {
             unset($instances[$skip]);
         }
     }
     foreach ($instances as $instance) {
         /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
         $field_storage = $instance->getFieldStorageDefinition();
         $max = $cardinality = $field_storage->getCardinality();
         if ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
             // Just an arbitrary number for 'unlimited'
             $max = rand(1, 3);
         }
         $field_name = $field_storage->getName();
         $entity->{$field_name}->generateSampleItems($max);
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:26,代码来源:DevelGenerateBase.php


示例16: assertCRUD

 /**
  * Executes a test set for a defined entity type and user.
  *
  * @param string $entity_type
  *   The entity type to run the tests with.
  * @param \Drupal\user\UserInterface $user1
  *   The user to run the tests with.
  */
 protected function assertCRUD($entity_type, UserInterface $user1)
 {
     // Create some test entities.
     $entity = entity_create($entity_type, array('name' => 'test', 'user_id' => $user1->id()));
     $entity->save();
     $entity = entity_create($entity_type, array('name' => 'test2', 'user_id' => $user1->id()));
     $entity->save();
     $entity = entity_create($entity_type, array('name' => 'test', 'user_id' => NULL));
     $entity->save();
     $entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test')));
     $this->assertEqual($entities[0]->name->value, 'test', format_string('%entity_type: Created and loaded entity', array('%entity_type' => $entity_type)));
     $this->assertEqual($entities[1]->name->value, 'test', format_string('%entity_type: Created and loaded entity', array('%entity_type' => $entity_type)));
     // Test loading a single entity.
     $loaded_entity = entity_load($entity_type, $entity->id());
     $this->assertEqual($loaded_entity->id(), $entity->id(), format_string('%entity_type: Loaded a single entity by id.', array('%entity_type' => $entity_type)));
     // Test deleting an entity.
     $entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test2')));
     $entities[0]->delete();
     $entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test2')));
     $this->assertEqual($entities, array(), format_string('%entity_type: Entity deleted.', array('%entity_type' => $entity_type)));
     // Test updating an entity.
     $entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test')));
     $entities[0]->name->value = 'test3';
     $entities[0]->save();
     $entity = entity_load($entity_type, $entities[0]->id());
     $this->assertEqual($entity->name->value, 'test3', format_string('%entity_type: Entity updated.', array('%entity_type' => $entity_type)));
     // Try deleting multiple test entities by deleting all.
     $ids = array_keys(entity_load_multiple($entity_type));
     entity_delete_multiple($entity_type, $ids);
     $all = entity_load_multiple($entity_type);
     $this->assertTrue(empty($all), format_string('%entity_type: Deleted all entities.', array('%entity_type' => $entity_type)));
     // Verify that all data got deleted.
     $definition = \Drupal::entityManager()->getDefinition($entity_type);
     $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {' . $definition->getBaseTable() . '}')->fetchField(), 'Base table was emptied');
     if ($data_table = $definition->getDataTable()) {
         $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {' . $data_table . '}')->fetchField(), 'Data table was emptied');
     }
     if ($revision_table = $definition->getRevisionTable()) {
         $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {' . $revision_table . '}')->fetchField(), 'Data table was emptied');
     }
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:49,代码来源:EntityApiTest.php


示例17: testMultiple

 /**
  * This will test loading file data from the database.
  */
 function testMultiple()
 {
     // Create a new file entity.
     $file = $this->createFile('druplicon.txt', NULL, 'public');
     // Load by path.
     file_test_reset();
     $by_path_files = entity_load_multiple_by_properties('file', array('uri' => $file->getFileUri()));
     $this->assertFileHookCalled('load');
     $this->assertEqual(1, count($by_path_files), 'file_load_multiple() returned an array of the correct size.');
     $by_path_file = reset($by_path_files);
     $this->assertTrue($by_path_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.');
     $this->assertEqual($by_path_file->id(), $file->id(), 'Loading by filepath got the correct fid.', 'File');
     // Load by fid.
     file_test_reset();
     $by_fid_files = file_load_multiple(array($file->id()));
     $this->assertFileHooksCalled(array());
     $this->assertEqual(1, count($by_fid_files), 'file_load_multiple() returned an array of the correct size.');
     $by_fid_file = reset($by_fid_files);
     $this->assertTrue($by_fid_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.');
     $this->assertEqual($by_fid_file->getFileUri(), $file->getFileUri(), 'Loading by fid got the correct filepath.', 'File');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:24,代码来源:LoadTest.php


示例18: testFeedLanguage

 /**
  * Tests creation of feeds with a language.
  */
 public function testFeedLanguage()
 {
     $feeds = array();
     // Create feeds.
     $feeds[1] = $this->createFeed(NULL, array('langcode' => $this->langcodes[1]->id));
     $feeds[2] = $this->createFeed(NULL, array('langcode' => $this->langcodes[2]->id));
     // Make sure that the language has been assigned.
     $this->assertEqual($feeds[1]->language()->id, $this->langcodes[1]->id);
     $this->assertEqual($feeds[2]->language()->id, $this->langcodes[2]->id);
     // Create example nodes to create feed items from and then update the feeds.
     $this->createSampleNodes();
     $this->cronRun();
     // Loop over the created feed items and verify that their language matches
     // the one from the feed.
     foreach ($feeds as $feed) {
         $items = entity_load_multiple_by_properties('aggregator_item', array('fid' => $feed->id()));
         $this->assertTrue(count($items) > 0, 'Feed items were created.');
         foreach ($items as $item) {
             $this->assertEqual($item->language()->id, $feed->language()->id);
         }
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:25,代码来源:FeedLanguageTest.php


示例19: testMenus

 /**
  * Tests menus.
  */
 public function testMenus()
 {
     // Assert that main menu is not included in the sitemap by default.
     $this->drupalGet('/sitemap');
     $elements = $this->cssSelect(".sitemap-box h2:contains('Main navigation')");
     $this->assertEqual(count($elements), 0, 'Main menu is not included.');
     // Configure module to show main menu, with enabled menu items only.
     $edit = array('show_menus[main]' => 'main', 'show_menus_hidden' => FALSE);
     $this->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
     // Create dummy node with enabled menu item.
     $node_1_title = $this->randomString();
     $edit = array('title[0][value]' => $node_1_title, 'menu[enabled]' => TRUE, 'menu[title]' => $node_1_title, 'menu[menu_parent]' => 'main:');
     $this->drupalPostForm('node/add/article', $edit, t('Save and publish'));
     // Create dummy node with disabled menu item.
     $node_2_title = $this->randomString();
     $edit = array('title[0][value]' => $node_2_title, 'menu[enabled]' => TRUE, 'menu[title]' => $node_2_title, 'menu[menu_parent]' => 'main:');
     $this->drupalPostForm('node/add/article', $edit, t('Save and publish'));
     // Disable menu item.
     $menu_links = entity_load_multiple_by_properties('menu_link_content', array('title' => $node_2_title));
     $menu_link = reset($menu_links);
     $mlid = $menu_link->id();
     $edit = array('enabled[value]' => FALSE);
     $this->drupalPostForm("admin/structure/menu/item/{$mlid}/edit", $edit, t('Save'));
     // Assert that main menu is included in the sitemap.
     $this->drupalGet('/sitemap');
     $elements = $this->cssSelect(".sitemap-box h2:contains('Main navigation')");
     $this->assertEqual(count($elements), 1, 'Main menu is included.');
     // Assert that node 1 is listed in the sitemap, but not node 2.
     $this->assertLink($node_1_title);
     $this->assertNoLink($node_2_title);
     // Configure module to show all menu items.
     $edit = array('show_menus_hidden' => TRUE);
     $this->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
     // Assert that both node 1 and node 2 are listed in the sitemap.
     $this->drupalGet('/sitemap');
     $this->assertLink($node_1_title);
     $this->assertLink($node_2_title);
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:41,代码来源:SitemapMenuTest.php


示例20: testDeleteField

 /**
  * Test the deletion of a field.
  */
 function testDeleteField()
 {
     // TODO: Test deletion of the data stored in the field also.
     // Need to check that data for a 'deleted' field / storage doesn't get loaded
     // Need to check data marked deleted is cleaned on cron (not implemented yet...)
     // Create two fields for the same field storage so we can test that only one
     // is deleted.
     FieldConfig::create($this->fieldDefinition)->save();
     $another_field_definition = $this->fieldDefinition;
     $another_field_definition['bundle'] .= '_another_bundle';
     entity_test_create_bundle($another_field_definition['bundle']);
     FieldConfig::create($another_field_definition)->save();
     // Test that the first field is not deleted, and then delete it.
     $field = current(entity_load_multiple_by_properties('field_config', array('entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE)));
     $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.');
     $field->delete();
     // Make sure the field is marked as deleted when it is specifically loaded.
     $field = current(entity_load_multiple_by_properties('field_config', array('entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE)));
     $this->assertTrue($field->isDeleted(), 'A deleted field is marked for deletion.');
     // Try to load the field normally and make sure it does not show up.
     $field = FieldConfig::load('entity_test.' . '.' . $this->fieldDefinition['bundle'] . '.' . $this->fieldDefinition['field_name']);
     $this->assertTrue(empty($field), 'A deleted field is not loaded by default.');
     // Make sure the other field is not deleted.
     $another_field = FieldConfig::load('entity_test.' . $another_field_definition['bundle'] . '.' . $another_field_definition['field_name']);
     $this->assertTrue(!empty($another_field) && empty($another_field->deleted), 'A non-deleted field is not marked for deletion.');
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:29,代码来源:FieldCrudTest.php



注:本文中的entity_load_multiple_by_properties函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP entity_load_single函数代码示例发布时间:2022-05-15
下一篇:
PHP entity_load_multiple函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap