本文整理汇总了PHP中Drupal\taxonomy\VocabularyInterface::id方法的典型用法代码示例。如果您正苦于以下问题:PHP VocabularyInterface::id方法的具体用法?PHP VocabularyInterface::id怎么用?PHP VocabularyInterface::id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\taxonomy\VocabularyInterface
的用法示例。
在下文中一共展示了VocabularyInterface::id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTaxonomyEfq
/**
* Tests that a basic taxonomy entity query works.
*/
function testTaxonomyEfq()
{
$terms = array();
for ($i = 0; $i < 5; $i++) {
$term = $this->createTerm($this->vocabulary);
$terms[$term->id()] = $term;
}
$result = \Drupal::entityQuery('taxonomy_term')->execute();
sort($result);
$this->assertEqual(array_keys($terms), $result, 'Taxonomy terms were retrieved by entity query.');
$tid = reset($result);
$ids = (object) array('entity_type' => 'taxonomy_term', 'entity_id' => $tid, 'bundle' => $this->vocabulary->id());
$term = _field_create_entity_from_ids($ids);
$this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.');
// Create a second vocabulary and five more terms.
$vocabulary2 = $this->createVocabulary();
$terms2 = array();
for ($i = 0; $i < 5; $i++) {
$term = $this->createTerm($vocabulary2);
$terms2[$term->id()] = $term;
}
$result = \Drupal::entityQuery('taxonomy_term')->condition('vid', $vocabulary2->id())->execute();
sort($result);
$this->assertEqual(array_keys($terms2), $result, format_string('Taxonomy terms from the %name vocabulary were retrieved by entity query.', array('%name' => $vocabulary2->label())));
$tid = reset($result);
$ids = (object) array('entity_type' => 'taxonomy_term', 'entity_id' => $tid, 'bundle' => $vocabulary2->id());
$term = _field_create_entity_from_ids($ids);
$this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.');
}
示例2: setUp
protected function setUp()
{
parent::setUp();
$this->vocabulary = $this->createVocabulary();
// RDF mapping - term bundle.
rdf_get_mapping('taxonomy_term', $this->vocabulary->id())->setBundleMapping(array('types' => array('skos:Concept')))->setFieldMapping('name', array('properties' => array('rdfs:label', 'skos:prefLabel')))->save();
}
示例3: 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');
}
示例4: testDevelGenerate
/**
* Tests generate commands
*/
public function testDevelGenerate()
{
// Creating users.
$edit = array('num' => 4);
$this->drupalPostForm('admin/config/development/generate/user', $edit, t('Generate'));
$this->assertText(t('4 users created.'));
$this->assertText(t('Generate process complete.'));
// Creating content.
// First we create a node in order to test the Delete content checkbox.
$this->drupalCreateNode(array('type' => 'article'));
$edit = array('num' => 4, 'kill' => TRUE, 'node_types[article]' => TRUE, 'time_range' => 604800, 'max_comments' => 3, 'title_length' => 4);
$this->drupalPostForm('admin/config/development/generate/content', $edit, t('Generate'));
$this->assertText(t('Deleted 1 nodes.'));
$this->assertText(t('Finished creating 4 nodes'));
$this->assertText(t('Generate process complete.'));
// Creating terms.
$edit = array('vids[]' => $this->vocabulary->id(), 'num' => 5, 'title_length' => 12);
$this->drupalPostForm('admin/config/development/generate/term', $edit, t('Generate'));
$this->assertText(t('Created the following new terms: '));
$this->assertText(t('Generate process complete.'));
// Creating vocabularies.
$edit = array('num' => 5, 'title_length' => 12, 'kill' => TRUE);
$this->drupalPostForm('admin/config/development/generate/vocabs', $edit, t('Generate'));
$this->assertText(t('Created the following new vocabularies: '));
$this->assertText(t('Generate process complete.'));
// Creating menus.
$edit = array('num_menus' => 5, 'num_links' => 7, 'title_length' => 12, 'link_types[node]' => 1, 'link_types[front]' => 1, 'link_types[external]' => 1, 'max_depth' => 4, 'max_width' => 6, 'kill' => 1);
$this->drupalPostForm('admin/config/development/generate/menu', $edit, t('Generate'));
$this->assertText(t('Created the following new menus: '));
$this->assertText(t('Created 7 new menu links'));
$this->assertText(t('Generate process complete.'));
}
示例5: addForm
/**
* Returns a rendered edit form to create a new term associated to the given vocabulary.
*
* @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary
* The vocabulary this term will be added to.
*
* @return array
* The taxonomy term add form.
*/
public function addForm(VocabularyInterface $taxonomy_vocabulary)
{
$term = $this->entityManager()->getStorage('taxonomy_term')->create(array('vid' => $taxonomy_vocabulary->id()));
if ($this->moduleHandler()->moduleExists('language')) {
$term->langcode = language_get_default_langcode('taxonomy_term', $taxonomy_vocabulary->id());
}
return $this->entityFormBuilder()->getForm($term);
}
示例6: setUp
protected function setUp()
{
parent::setUp();
$web_user = $this->drupalCreateUser(array('bypass node access', 'administer taxonomy'));
$this->drupalLogin($web_user);
$this->vocabulary = $this->createVocabulary();
// Create the field.
$this->fieldName = 'field_taxonomy_test';
$this->createTaxonomyTermReferenceField($this->fieldName, $this->vocabulary);
// Set the RDF mapping for the new field.
rdf_get_mapping('node', 'article')->setFieldMapping($this->fieldName, array('properties' => array('dc:subject'), 'mapping_type' => 'rel'))->save();
rdf_get_mapping('taxonomy_term', $this->vocabulary->id())->setBundleMapping(array('types' => array('skos:Concept')))->setFieldMapping('name', array('properties' => array('rdfs:label')))->save();
}
示例7: setUp
protected function setUp()
{
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['view test entity', 'administer entity_test content', 'administer taxonomy']));
$this->vocabulary1 = $this->createVocabulary();
$this->vocabulary2 = $this->createVocabulary();
// Set up a field storage and a field.
$this->fieldName = Unicode::strtolower($this->randomMachineName());
entity_create('field_storage_config', array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $this->vocabulary1->id(), 'parent' => '0'), array('vocabulary' => $this->vocabulary2->id(), 'parent' => '0')))))->save();
entity_create('field_config', array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'bundle' => 'entity_test'))->save();
entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($this->fieldName, array('type' => 'options_select'))->save();
entity_get_display('entity_test', 'entity_test', 'full')->setComponent($this->fieldName, array('type' => 'taxonomy_term_reference_link'))->save();
}
示例8: testTaggedWithByNodeType
/**
* Tests that the "tagged with" form element only shows for node types that support it.
*/
function testTaggedWithByNodeType()
{
// The tagging field is associated with one of our node types only. So the
// "tagged with" form element on the view wizard should appear on the form
// by default (when the wizard is configured to display all content) and
// also when the node type that has the tagging field is selected, but not
// when the node type that doesn't have the tagging field is selected.
$tags_xpath = '//input[@name="show[tagged_with]"]';
$this->drupalGet('admin/structure/views/add');
$this->assertFieldByXpath($tags_xpath);
$view['show[type]'] = $this->nodeTypeWithTags->id();
$this->drupalPostForm('admin/structure/views/add', $view, t('Update "of type" choice'));
$this->assertFieldByXpath($tags_xpath);
$view['show[type]'] = $this->nodeTypeWithoutTags->id();
$this->drupalPostForm(NULL, $view, t('Update "of type" choice'));
$this->assertNoFieldByXpath($tags_xpath);
// If we add an instance of the tagging field to the second node type, the
// "tagged with" form element should not appear for it too.
entity_create('field_config', array('field_name' => $this->tagFieldName, 'entity_type' => 'node', 'bundle' => $this->nodeTypeWithoutTags->id(), 'settings' => array('handler' => 'default', 'handler_settings' => array('target_bundles' => array($this->tagVocabulary->id() => $this->tagVocabulary->id()), 'auto_create' => TRUE))))->save();
entity_get_form_display('node', $this->nodeTypeWithoutTags->id(), 'default')->setComponent($this->tagFieldName, array('type' => 'entity_reference_autocomplete_tags'))->save();
$view['show[type]'] = $this->nodeTypeWithTags->id();
$this->drupalPostForm('admin/structure/views/add', $view, t('Update "of type" choice'));
$this->assertFieldByXpath($tags_xpath);
$view['show[type]'] = $this->nodeTypeWithoutTags->id();
$this->drupalPostForm(NULL, $view, t('Update "of type" choice'));
$this->assertFieldByXpath($tags_xpath);
}
示例9: 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();
}
示例10: addTerm
function addTerm(VocabularyInterface $vocabulary, array $term = array())
{
$term += array('name' => Unicode::strtolower($this->randomMachineName(5)), 'vid' => $vocabulary->id());
$term = entity_create('taxonomy_term', $term);
$term->save();
return $term;
}
示例11: setUp
protected function setUp()
{
parent::setUp();
$web_user = $this->drupalCreateUser(array('bypass node access', 'administer taxonomy'));
$this->drupalLogin($web_user);
$this->vocabulary = $this->createVocabulary();
// Create the field.
$this->fieldName = 'field_taxonomy_test';
$handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
$this->createEntityReferenceField('node', 'article', $this->fieldName, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')->setComponent($this->fieldName, array('type' => 'options_select'))->save();
entity_get_display('node', 'article', 'full')->setComponent($this->fieldName, array('type' => 'entity_reference_label'))->save();
// Set the RDF mapping for the new field.
rdf_get_mapping('node', 'article')->setFieldMapping($this->fieldName, array('properties' => array('dc:subject'), 'mapping_type' => 'rel'))->save();
rdf_get_mapping('taxonomy_term', $this->vocabulary->id())->setBundleMapping(array('types' => array('skos:Concept')))->setFieldMapping('name', array('properties' => array('rdfs:label')))->save();
}
示例12: createTerm
/**
* Returns a new term with random name and description in $this->vocabulary.
*
* @return \Drupal\taxonomy\TermInterface
* The created taxonomy term.
*/
protected function createTerm()
{
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$term = Term::create(['name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'format' => $format->id(), 'vid' => $this->vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
$term->save();
return $term;
}
示例13: setUp
protected function setUp()
{
parent::setUp();
// Create an administrative user.
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access']));
// Create a vocabulary and add two term reference fields to article nodes.
$this->vocabulary = $this->createVocabulary();
$this->fieldName1 = Unicode::strtolower($this->randomMachineName());
$handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
$this->createEntityReferenceField('node', 'article', $this->fieldName1, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')->setComponent($this->fieldName1, array('type' => 'options_select'))->save();
entity_get_display('node', 'article', 'default')->setComponent($this->fieldName1, array('type' => 'entity_reference_label'))->save();
$this->fieldName2 = Unicode::strtolower($this->randomMachineName());
$this->createEntityReferenceField('node', 'article', $this->fieldName2, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')->setComponent($this->fieldName2, array('type' => 'options_select'))->save();
entity_get_display('node', 'article', 'default')->setComponent($this->fieldName2, array('type' => 'entity_reference_label'))->save();
}
示例14: createTerm
/**
* Returns a new term with random name and description in $this->vocabulary.
*
* @return \Drupal\taxonomy\TermInterface
* The created taxonomy term.
*/
protected function createTerm()
{
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$term = entity_create('taxonomy_term', array('name' => $this->randomName(), 'description' => $this->randomName(), 'format' => $format->format, 'vid' => $this->vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
$term->save();
return $term;
}
示例15: testTaxonomyRss
/**
* Tests that terms added to nodes are displayed in core RSS feed.
*
* Create a node and assert that taxonomy terms appear in rss.xml.
*/
function testTaxonomyRss()
{
// Create two taxonomy terms.
$term1 = $this->createTerm($this->vocabulary);
// RSS display must be added manually.
$this->drupalGet("admin/structure/types/manage/article/display");
$edit = array("display_modes_custom[rss]" => '1');
$this->drupalPostForm(NULL, $edit, t('Save'));
// Change the format to 'RSS category'.
$this->drupalGet("admin/structure/types/manage/article/display/rss");
$edit = array("fields[taxonomy_" . $this->vocabulary->id() . "][type]" => 'entity_reference_rss_category');
$this->drupalPostForm(NULL, $edit, t('Save'));
// Post an article.
$edit = array();
$edit['title[0][value]'] = $this->randomMachineName();
$edit[$this->fieldName . '[]'] = $term1->id();
$this->drupalPostForm('node/add/article', $edit, t('Save'));
// Check that the term is displayed when the RSS feed is viewed.
$this->drupalGet('rss.xml');
$test_element = sprintf('<category %s>%s</category>', 'domain="' . $term1->url('canonical', array('absolute' => TRUE)) . '"', $term1->getName());
$this->assertRaw($test_element, 'Term is displayed when viewing the rss feed.');
// Test that the feed icon exists for the term.
$this->drupalGet("taxonomy/term/{$term1->id()}");
$this->assertLinkByHref("taxonomy/term/{$term1->id()}/feed");
// Test that the feed page exists for the term.
$this->drupalGet("taxonomy/term/{$term1->id()}/feed");
$this->assertRaw('<rss version="2.0"', "Feed page is RSS.");
// Check that the "Exception value" is disabled by default.
$this->drupalGet('taxonomy/term/all/feed');
$this->assertResponse(404);
// Set the exception value to 'all'.
$view = Views::getView('taxonomy_term');
$arguments = $view->getDisplay()->getOption('arguments');
$arguments['tid']['exception']['value'] = 'all';
$view->getDisplay()->overrideOption('arguments', $arguments);
$view->storage->save();
// Check the article is shown in the feed.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$raw_xml = '<title>' . $node->label() . '</title>';
$this->drupalGet('taxonomy/term/all/feed');
$this->assertRaw($raw_xml, "Raw text '{$raw_xml}' is found.");
// Unpublish the article and check that it is not shown in the feed.
$node->setPublished(FALSE)->save();
$this->drupalGet('taxonomy/term/all/feed');
$this->assertNoRaw($raw_xml);
}