本文整理汇总了PHP中entity_delete_multiple函数的典型用法代码示例。如果您正苦于以下问题:PHP entity_delete_multiple函数的具体用法?PHP entity_delete_multiple怎么用?PHP entity_delete_multiple使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了entity_delete_multiple函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCandidates
/**
* Tests language fallback candidates.
*/
public function testCandidates()
{
$language_list = $this->languageManager->getLanguages();
$expected = array_keys($language_list + array(LanguageInterface::LANGCODE_NOT_SPECIFIED => NULL));
// Check that language fallback candidates by default are all the available
// languages sorted by weight.
$candidates = $this->languageManager->getFallbackCandidates();
$this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are properly returned.');
// Check that candidates are alterable.
$this->state->set('language_test.fallback_alter.candidates', TRUE);
$expected = array_slice($expected, 0, count($expected) - 1);
$candidates = $this->languageManager->getFallbackCandidates();
$this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are alterable.');
// Check that candidates are alterable for specific operations.
$this->state->set('language_test.fallback_alter.candidates', FALSE);
$this->state->set('language_test.fallback_operation_alter.candidates', TRUE);
$expected[] = LanguageInterface::LANGCODE_NOT_SPECIFIED;
$expected[] = LanguageInterface::LANGCODE_NOT_APPLICABLE;
$candidates = $this->languageManager->getFallbackCandidates(array('operation' => 'test'));
$this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are alterable for specific operations.');
// Check that when the site is monolingual no language fallback is applied.
$langcodes_to_delete = array();
foreach ($language_list as $langcode => $language) {
if (!$language->isDefault()) {
$langcodes_to_delete[] = $langcode;
}
}
entity_delete_multiple('configurable_language', $langcodes_to_delete);
$candidates = $this->languageManager->getFallbackCandidates();
$this->assertEqual(array_values($candidates), array(LanguageInterface::LANGCODE_DEFAULT), 'Language fallback is not applied when the Language module is not enabled.');
}
示例2: generateRefreshToken
/**
* Create a refresh token for the current user
*
* It will delete all the existing refresh tokens for that same user as well.
*
* @param int $uid
* The user ID.
*
* @return \RestfulTokenAuth
* The token entity.
*/
private function generateRefreshToken($uid) {
// Check if there are other refresh tokens for the user.
$query = new \EntityFieldQuery();
$results = $query
->entityCondition('entity_type', 'restful_token_auth')
->entityCondition('bundle', 'refresh_token')
->propertyCondition('uid', $uid)
->execute();
if (!empty($results['restful_token_auth'])) {
// Delete the tokens.
entity_delete_multiple('restful_token_auth', array_keys($results['restful_token_auth']));
}
// Create a new refresh token.
$values = array(
'uid' => $uid,
'type' => 'refresh_token',
'created' => REQUEST_TIME,
'name' => t('Refresh token for: @uid', array(
'@uid' => $uid,
)),
'token' => drupal_random_key(),
);
$refresh_token = $this->create($values);
$this->save($refresh_token);
return $refresh_token;
}
示例3: NodeGalleryRelationshipCrud
/**
* Create, update or delete Node Gallery relationships based on field values.
*/
public function NodeGalleryRelationshipCrud($entity_type, $entity, $field, $instance, $langcode, &$items)
{
$diff = $this->galleriesGetDiff($entity_type, $entity, $field, $instance, $langcode, $items);
if (!$diff) {
return;
}
$diff += array('insert' => array(), 'delete' => array());
// Delete first, so we don't trigger cardinality errors.
if ($diff['delete']) {
entity_delete_multiple('node_gallery_relationship', array_keys($diff['delete']));
foreach (array_values($diff['delete']) as $ngid) {
if (node_gallery_api_get_cover_nid($ngid) == $entity->nid) {
node_gallery_api_reset_cover_item($ngid);
}
node_gallery_api_clear_gallery_caches($ngid);
node_gallery_api_update_image_counts($ngid);
}
}
if (!empty($diff['insert'])) {
$relationship_type = node_gallery_api_get_relationship_type(NULL, $entity->type);
if (!empty($relationship_type)) {
foreach ($diff['insert'] as $ngid) {
$r = new NodeGalleryRelationship();
$r->relationship_type = $relationship_type->id;
$r->nid = $entity->nid;
$r->ngid = $ngid;
$r->weight = NODE_GALLERY_DEFAULT_WEIGHT;
$r->save();
}
}
}
}
示例4: deleteVocabularyTerms
/**
* Deletes all terms of a vocabulary.
*
* @param $vid
* int a vocabulary vid.
*/
protected function deleteVocabularyTerms($vid)
{
$tids = array();
foreach (taxonomy_get_tree($vid) as $term) {
$tids[] = $term->tid;
}
entity_delete_multiple('taxonomy_term', $tids);
}
示例5: 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));
}
示例6: resetNodes
/**
* Removes any nodes created after the last node id remembered.
*
* @AfterScenario @reset-nodes
*/
public function resetNodes()
{
if (!isset($this->maxNodeId)) {
return;
}
$all_nodes_after_query = (new \EntityFieldQuery())->entityCondition('entity_type', 'node')->propertyCondition('nid', $this->maxNodeId, '>');
$all_nodes_after = $all_nodes_after_query->execute();
$all_nodes_after = reset($all_nodes_after);
if (is_array($all_nodes_after)) {
entity_delete_multiple('node', array_keys($all_nodes_after));
}
unset($this->maxNodeId);
}
示例7: testCommentLinks
/**
* Tests that comment links are output and can be hidden.
*/
public function testCommentLinks()
{
// Bartik theme alters comment links, so use a different theme.
\Drupal::service('theme_handler')->install(array('stark'));
\Drupal::config('system.theme')->set('default', 'stark')->save();
// Remove additional user permissions from $this->web_user added by setUp(),
// since this test is limited to anonymous and authenticated roles only.
$roles = $this->web_user->getRoles();
entity_delete_multiple('user_role', array(reset($roles)));
// Create a comment via CRUD API functionality, since
// $this->postComment() relies on actual user permissions.
$comment = entity_create('comment', array('cid' => NULL, 'entity_id' => $this->node->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'pid' => 0, 'uid' => 0, 'status' => CommentInterface::PUBLISHED, 'subject' => $this->randomMachineName(), 'hostname' => '127.0.0.1', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'comment_body' => array(LanguageInterface::LANGCODE_NOT_SPECIFIED => array($this->randomMachineName()))));
$comment->save();
$this->comment = $comment;
// Change comment settings.
$this->setCommentSettings('form_location', CommentItemInterface::FORM_BELOW, 'Set comment form location');
$this->setCommentAnonymous(TRUE);
$this->node->comment = CommentItemInterface::OPEN;
$this->node->save();
// Change user permissions.
$perms = array('access comments' => 1, 'post comments' => 1, 'skip comment approval' => 1, 'edit own comments' => 1);
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, $perms);
$nid = $this->node->id();
// Assert basic link is output, actual functionality is unit-tested in
// \Drupal\comment\Tests\CommentLinkBuilderTest.
foreach (array('node', "node/{$nid}") as $path) {
$this->drupalGet($path);
// In teaser view, a link containing the comment count is always
// expected.
if ($path == 'node') {
$this->assertLink(t('1 comment'));
}
$this->assertLink('Add new comment');
}
// Make sure we can hide node links.
entity_get_display('node', $this->node->bundle(), 'default')->removeComponent('links')->save();
$this->drupalGet($this->node->url());
$this->assertNoLink('1 comment');
$this->assertNoLink('Add new comment');
// Visit the full node, make sure there are links for the comment.
$this->drupalGet('node/' . $this->node->id());
$this->assertText($comment->getSubject());
$this->assertLink('Reply');
// Make sure we can hide comment links.
entity_get_display('comment', 'comment', 'default')->removeComponent('links')->save();
$this->drupalGet('node/' . $this->node->id());
$this->assertText($comment->getSubject());
$this->assertNoLink('Reply');
}
示例8: testNodeDeletion
/**
* Tests that comments are deleted with the node.
*/
function testNodeDeletion()
{
$this->drupalLogin($this->webUser);
$comment = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName());
$this->assertTrue($comment->id(), 'The comment could be loaded.');
$this->node->delete();
$this->assertFalse(Comment::load($comment->id()), 'The comment could not be loaded after the node was deleted.');
// Make sure the comment field storage and all its fields are deleted when
// the node type is deleted.
$this->assertNotNull(FieldStorageConfig::load('node.comment'), 'Comment field storage exists');
$this->assertNotNull(FieldConfig::load('node.article.comment'), 'Comment field exists');
// Delete the node type.
entity_delete_multiple('node_type', array($this->node->bundle()));
$this->assertNull(FieldStorageConfig::load('node.comment'), 'Comment field storage deleted');
$this->assertNull(FieldConfig::load('node.article.comment'), 'Comment field deleted');
}
示例9: testNodeDeletion
/**
* Tests that comments are deleted with the node.
*/
function testNodeDeletion()
{
$this->drupalLogin($this->web_user);
$comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
$this->assertTrue($comment->id(), 'The comment could be loaded.');
$this->node->delete();
$this->assertFalse(Comment::load($comment->id()), 'The comment could not be loaded after the node was deleted.');
// Make sure the comment field and all its instances are deleted when node
// type is deleted.
$this->assertNotNull(entity_load('field_storage_config', 'node.comment'), 'Comment field exists');
$this->assertNotNull(entity_load('field_instance_config', 'node.article.comment'), 'Comment instance exists');
// Delete the node type.
entity_delete_multiple('node_type', array($this->node->bundle()));
$this->assertNull(entity_load('field_storage_config', 'node.comment'), 'Comment field deleted');
$this->assertNull(entity_load('field_instance_config', 'node.article.comment'), 'Comment instance deleted');
}
示例10: 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');
}
}
示例11: testDependencyInjectedNewDefaultLanguage
/**
* Test dependency injected Language object against a new default language
* object.
*
* @see \Drupal\Core\Language\Language
*/
function testDependencyInjectedNewDefaultLanguage()
{
$default_language = ConfigurableLanguage::load(\Drupal::languageManager()->getDefaultLanguage()->getId());
// Change the language default object to different values.
ConfigurableLanguage::createFromLangcode('fr')->save();
$this->config('system.site')->set('default_langcode', 'fr')->save();
// The language system creates a Language object which contains the
// same properties as the new default language object.
$result = \Drupal::languageManager()->getCurrentLanguage();
$this->assertIdentical($result->getId(), 'fr');
// Delete the language to check that we fallback to the default.
try {
entity_delete_multiple('configurable_language', array('fr'));
$this->fail('Expected DeleteDefaultLanguageException thrown.');
} catch (DeleteDefaultLanguageException $e) {
$this->pass('Expected DeleteDefaultLanguageException thrown.');
}
// Re-save the previous default language and the delete should work.
$this->config('system.site')->set('default_langcode', $default_language->getId())->save();
entity_delete_multiple('configurable_language', array('fr'));
$result = \Drupal::languageManager()->getCurrentLanguage();
$this->assertIdentical($result->getId(), $default_language->getId());
}
示例12: postDelete
/**
* {@inheritdoc}
*/
public static function postDelete(EntityStorageInterface $storage, array $entities)
{
parent::postDelete($storage, $entities);
// See if any of the term's children are about to be become orphans.
$orphans = array();
foreach (array_keys($entities) as $tid) {
if ($children = taxonomy_term_load_children($tid)) {
foreach ($children as $child) {
// If the term has multiple parents, we don't delete it.
$parents = taxonomy_term_load_parents($child->id());
if (empty($parents)) {
$orphans[] = $child->id();
}
}
}
}
// Delete term hierarchy information after looking up orphans but before
// deleting them so that their children/parent information is consistent.
$storage->deleteTermHierarchy(array_keys($entities));
if (!empty($orphans)) {
entity_delete_multiple('taxonomy_term', $orphans);
}
}
示例13: testAddOrphanTopic
/**
* Tests that forum nodes can't be added without a parent.
*
* Verifies that forum nodes are not created without choosing "forum" from the
* select list.
*/
function testAddOrphanTopic()
{
// Must remove forum topics to test creating orphan topics.
$vid = $this->config('forum.settings')->get('vocabulary');
$tids = \Drupal::entityQuery('taxonomy_term')->condition('vid', $vid)->execute();
entity_delete_multiple('taxonomy_term', $tids);
// Create an orphan forum item.
$edit = array();
$edit['title[0][value]'] = $this->randomMachineName(10);
$edit['body[0][value]'] = $this->randomMachineName(120);
$this->drupalLogin($this->adminUser);
$this->drupalPostForm('node/add/forum', $edit, t('Save'));
$nid_count = db_query('SELECT COUNT(nid) FROM {node}')->fetchField();
$this->assertEqual(0, $nid_count, 'A forum node was not created when missing a forum vocabulary.');
// Reset the defaults for future tests.
\Drupal::service('module_installer')->install(array('forum'));
}
示例14: 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 = $this->container->get('entity_type.manager')->getStorage($entity_type)->create(array('name' => 'test', 'user_id' => $user1->id()));
$entity->save();
$entity = $this->container->get('entity_type.manager')->getStorage($entity_type)->create(array('name' => 'test2', 'user_id' => $user1->id()));
$entity->save();
$entity = $this->container->get('entity_type.manager')->getStorage($entity_type)->create(array('name' => 'test', 'user_id' => NULL));
$entity->save();
/** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
$storage = $this->container->get('entity_type.manager')->getStorage($entity_type);
$entities = array_values($storage->loadByProperties(['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 = $storage->load($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($storage->loadByProperties(['name' => 'test2']));
$entities[0]->delete();
$entities = array_values($storage->loadByProperties(['name' => 'test2']));
$this->assertEqual($entities, array(), format_string('%entity_type: Entity deleted.', array('%entity_type' => $entity_type)));
// Test updating an entity.
$entities = array_values($storage->loadByProperties(['name' => 'test']));
$entities[0]->name->value = 'test3';
$entities[0]->save();
$entity = $storage->load($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($storage->loadMultiple());
entity_delete_multiple($entity_type, $ids);
$all = $storage->loadMultiple();
$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');
}
// Test deleting a list of entities not indexed by entity id.
$entities = array();
$entity = entity_create($entity_type, array('name' => 'test', 'user_id' => $user1->id()));
$entity->save();
$entities['test'] = $entity;
$entity = entity_create($entity_type, array('name' => 'test2', 'user_id' => $user1->id()));
$entity->save();
$entities['test2'] = $entity;
$controller = \Drupal::entityManager()->getStorage($entity_type);
$controller->delete($entities);
// Verify that entities got deleted.
$all = $storage->loadMultiple();
$this->assertTrue(empty($all), format_string('%entity_type: Deleted all entities.', array('%entity_type' => $entity_type)));
// Verify that all data got deleted from the tables.
$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');
}
}
示例15: deleteMenus
/**
* Deletes custom generated menus
*/
protected function deleteMenus()
{
if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
foreach (menu_ui_get_menus(FALSE) as $menu => $menu_title) {
if (strpos($menu, 'devel-') === 0) {
Menu::load($menu)->delete();
}
}
}
// Delete menu links generated by devel.
$result = db_select('menu_link_content_data', 'm')->fields('m', array('id'))->condition('m.menu_name', 'devel', '<>')->condition('m.link__options', '%' . db_like('s:5:"devel";b:1') . '%', 'LIKE')->execute()->fetchCol();
if ($result) {
entity_delete_multiple('menu_link_content', $result);
}
}