本文整理汇总了PHP中Drupal\taxonomy\VocabularyInterface::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP VocabularyInterface::delete方法的具体用法?PHP VocabularyInterface::delete怎么用?PHP VocabularyInterface::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\taxonomy\VocabularyInterface
的用法示例。
在下文中一共展示了VocabularyInterface::delete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testConfigEntityReferenceItem
/**
* Tests the entity reference field type for referencing config entities.
*/
public function testConfigEntityReferenceItem()
{
$referenced_entity_id = $this->vocabulary->id();
// Just being able to create the entity like this verifies a lot of code.
$entity = EntityTest::create();
$entity->field_test_taxonomy_vocabulary->target_id = $referenced_entity_id;
$entity->name->value = $this->randomMachineName();
$entity->save();
$entity = entity_load('entity_test', $entity->id());
$this->assertTrue($entity->field_test_taxonomy_vocabulary instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_test_taxonomy_vocabulary[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_test_taxonomy_vocabulary->target_id, $referenced_entity_id);
$this->assertEqual($entity->field_test_taxonomy_vocabulary->entity->label(), $this->vocabulary->label());
$this->assertEqual($entity->field_test_taxonomy_vocabulary->entity->id(), $referenced_entity_id);
$this->assertEqual($entity->field_test_taxonomy_vocabulary->entity->uuid(), $this->vocabulary->uuid());
// Change the name of the term via the reference.
$new_name = $this->randomMachineName();
$entity->field_test_taxonomy_vocabulary->entity->set('name', $new_name);
$entity->field_test_taxonomy_vocabulary->entity->save();
// Verify it is the correct name.
$vocabulary = Vocabulary::load($referenced_entity_id);
$this->assertEqual($vocabulary->label(), $new_name);
// Make sure the computed term reflects updates to the term id.
$vocabulary2 = $vocabulary = Vocabulary::create(['name' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
$vocabulary2->save();
$entity->field_test_taxonomy_vocabulary->target_id = $vocabulary2->id();
$this->assertEqual($entity->field_test_taxonomy_vocabulary->entity->id(), $vocabulary2->id());
$this->assertEqual($entity->field_test_taxonomy_vocabulary->entity->label(), $vocabulary2->label());
// Delete terms so we have nothing to reference and try again
$this->vocabulary->delete();
$vocabulary2->delete();
$entity = EntityTest::create(array('name' => $this->randomMachineName()));
$entity->save();
}
示例2: array
/**
* Tests term reference field and widget with multiple vocabularies.
*/
function testTaxonomyTermFieldMultipleVocabularies()
{
// Create a term in each vocabulary.
$term1 = $this->createTerm($this->vocabulary1);
$term2 = $this->createTerm($this->vocabulary2);
// Submit an entity with both terms.
$this->drupalGet('entity_test/add');
// Just check if the widget for the select is displayed, the NULL value is
// used to ignore the value check.
$this->assertFieldByName("{$this->fieldName}[]", NULL, 'Widget is displayed.');
$edit = array("{$this->fieldName}[]" => array($term1->id(), $term2->id()));
$this->drupalPostForm(NULL, $edit, t('Save'));
preg_match('|entity_test/manage/(\\d+)|', $this->url, $match);
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created.');
// Render the entity.
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->setRawContent(drupal_render($content));
$this->assertText($term1->getName(), 'Term 1 name is displayed.');
$this->assertText($term2->getName(), 'Term 2 name is displayed.');
// Delete vocabulary 2.
$this->vocabulary2->delete();
// Re-render the content.
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->setRawContent(drupal_render($content));
// Term 1 should still be displayed; term 2 should not be.
$this->assertText($term1->getName(), 'Term 1 name is displayed.');
$this->assertNoText($term2->getName(), 'Term 2 name is not displayed.');
// Verify that field storage settings and field settings are correct.
$field_storage = FieldStorageConfig::loadByName('entity_test', $this->fieldName);
$this->assertEqual(count($field_storage->getSetting('allowed_values')), 1, 'Only one vocabulary is allowed for the field.');
// The widget should still be displayed.
$this->drupalGet('entity_test/add');
// Just check if the widget for the select is displayed, the NULL value is
// used to ignore the value check.
$this->assertFieldByName("{$this->fieldName}[]", NULL, 'Widget is still displayed.');
// Term 1 should still pass validation.
$edit = array("{$this->fieldName}[]" => array($term1->id()));
$this->drupalPostForm(NULL, $edit, t('Save'));
}
示例3: testTaxonomyTermFieldWidgets
/**
* Test widgets.
*/
function testTaxonomyTermFieldWidgets()
{
// Create a term in the vocabulary.
$term = $this->createTerm($this->vocabulary);
// Display creation form.
$this->drupalGet('entity_test/add');
$this->assertFieldByName($this->fieldName, NULL, 'Widget is displayed.');
// Submit with some value.
$edit = array($this->fieldName => array($term->id()));
$this->drupalPostForm(NULL, $edit, t('Save'));
preg_match('|entity_test/manage/(\\d+)|', $this->url, $match);
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)));
// Display the object.
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->setRawContent(drupal_render($content));
$this->assertText($term->getName(), 'Term label is displayed.');
// Delete the vocabulary and verify that the widget is gone.
$this->vocabulary->delete();
$this->drupalGet('entity_test/add');
$this->assertNoFieldByName($this->fieldName, '', 'Widget is not displayed.');
}