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

PHP taxonomy\VocabularyInterface类代码示例

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

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



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

示例1: 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;
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:7,代码来源:EntityTest.php


示例2: buildForm

 /**
  * Form constructor.
  *
  * Display a tree of all the terms in a vocabulary, with options to edit
  * each one. The form implements the Taxonomy Manager intefrace.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param VocabularyInterface $taxonomy_vocabulary
  *   The vocabulary being with worked with
  *
  * @return array
  *   The form structure.
  */
 public function buildForm(array $form, FormStateInterface $form_state, VocabularyInterface $taxonomy_vocabulary = NULL)
 {
     $form['voc'] = array('#type' => 'value', "#value" => $taxonomy_vocabulary);
     $form['#attached']['library'][] = 'taxonomy_manager/form';
     if (TaxonomyManagerHelper::_taxonomy_manager_voc_is_empty($taxonomy_vocabulary->id())) {
         $form['text'] = array('#markup' => $this->t('No terms available'));
         $form[] = \Drupal::formBuilder()->getForm('Drupal\\taxonomy_manager\\Form\\AddTermsToVocabularyForm', $taxonomy_vocabulary);
         return $form;
     }
     $form['toolbar'] = array('#type' => 'fieldset', '#title' => $this->t('Toolbar'));
     $form['toolbar']['add'] = array('#type' => 'submit', '#name' => 'add', '#value' => $this->t('Add'), '#ajax' => array('callback' => '::addFormCallback'));
     $form['toolbar']['delete'] = array('#type' => 'submit', '#name' => 'delete', '#value' => $this->t('Delete'), '#ajax' => array('callback' => '::deleteFormCallback'));
     $form['toolbar']['move'] = array('#type' => 'submit', '#name' => 'move', '#value' => $this->t('Move'), '#ajax' => array('callback' => '::moveFormCallback'));
     $form['toolbar']['export'] = array('#type' => 'submit', '#name' => 'export', '#value' => $this->t('Export'), '#ajax' => array('callback' => '::exportFormCallback'));
     /* Taxonomy manager. */
     $form['taxonomy']['#tree'] = TRUE;
     $form['taxonomy']['manager'] = array('#type' => 'fieldset', '#title' => HTML::escape($taxonomy_vocabulary->label()), '#tree' => TRUE);
     $form['taxonomy']['manager']['top'] = array('#markup' => '', '#prefix' => '<div class="taxonomy-manager-tree-top">', '#suffix' => '</div>');
     /*$grippie_image = array(
           '#theme' => 'image',
           '#uri' => drupal_get_path('module', 'taxonomy_manager') . "/images/grippie.png",
           '#alt' => $this->t("Resize tree"),
           '#title' => $this->t("Resize tree"),
           '#attributes' => array('class' => array('div-grippie')),
         );
     
         $form['taxonomy']['manager']['top']['size'] = array(
           '#markup' =>
             '<div class="taxonomy-manager-tree-size">'
             . \Drupal::service('renderer')->render($grippie_image, true)
             . '</div>'
         );*/
     $form['taxonomy']['manager']['tree'] = array('#type' => 'taxonomy_manager_tree', '#vocabulary' => $taxonomy_vocabulary->id(), '#pager_size' => \Drupal::config('taxonomy_manager.settings')->get('taxonomy_manager_pager_tree_page_size'));
     $form['taxonomy']['manager']['pager'] = array('#type' => 'pager');
     // Add placeholder for term data form, the load-term-data field has AJAX
     // events attached and will trigger the load of the term data form. The
     // field is hidden via CSS and the value gets set in termData.js.
     $form['term-data']['#prefix'] = '<div id="taxonomy-term-data-form">';
     $form['term-data']['#suffix'] = '</div>';
     $form['load-term-data'] = array('#type' => 'textfield', '#ajax' => array('callback' => '::termDataCallback', 'event' => 'change'));
     return $form;
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:58,代码来源:TaxonomyManagerForm.php


示例3: autocompletePerVid

 /**
  * Retrieves suggestions for taxonomy term autocompletion by vocabulary ID.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary
  *   The vocabulary to filter by.
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  *   A JSON response containing the autocomplete suggestions for taxonomy
  *   terms.
  */
 public function autocompletePerVid(Request $request, VocabularyInterface $taxonomy_vocabulary)
 {
     // A comma-separated list of term names entered in the autocomplete form
     // element. Only the last term is used for autocompletion.
     $tags_typed = $request->query->get('q');
     $tags_typed = Tags::explode($tags_typed);
     $tag_last = Unicode::strtolower(array_pop($tags_typed));
     $matches = array();
     if ($tag_last != '') {
         $vids = array($taxonomy_vocabulary->id());
         $matches = $this->getMatchingTerms($tags_typed, $vids, $tag_last);
     }
     return new JsonResponse($matches);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:26,代码来源:TermAutocompleteController.php


示例4: vocabularyTitle

 /**
  * Route title callback.
  *
  * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary
  *   The taxonomy term.
  *
  * @return string
  *   The term label.
  */
 public function vocabularyTitle(VocabularyInterface $taxonomy_vocabulary)
 {
     return Xss::filter($taxonomy_vocabulary->label());
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:13,代码来源:TaxonomyController.php


示例5: 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.');
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:32,代码来源:EfqTest.php


示例6: 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.'));
 }
开发者ID:AllieRays,项目名称:debugging-drupal-8,代码行数:35,代码来源:DevelGenerateTest.php


示例7: 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();
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:7,代码来源:TaxonomyAttributesTest.php


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


示例9: testTermIndentation

 /**
  * Tests term indentation.
  */
 function testTermIndentation()
 {
     // Create three taxonomy terms.
     $term1 = $this->createTerm($this->vocabulary);
     $term2 = $this->createTerm($this->vocabulary);
     $term3 = $this->createTerm($this->vocabulary);
     // Get the taxonomy storage.
     $taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
     // Indent the second term under the first one.
     $edit = array('terms[tid:' . $term2->id() . ':0][term][tid]' => 2, 'terms[tid:' . $term2->id() . ':0][term][parent]' => 1, 'terms[tid:' . $term2->id() . ':0][term][depth]' => 1, 'terms[tid:' . $term2->id() . ':0][weight]' => 1);
     // Submit the edited form and check for HTML indentation element presence.
     $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview', $edit, t('Save'));
     $this->assertPattern('|<div class="js-indentation indentation">&nbsp;</div>|');
     // Check explicitly that term 2's parent is term 1.
     $parents = $taxonomy_storage->loadParents($term2->id());
     $this->assertEqual(key($parents), 1, 'Term 1 is the term 2\'s parent');
     // Move the second term back out to the root level.
     $edit = array('terms[tid:' . $term2->id() . ':0][term][tid]' => 2, 'terms[tid:' . $term2->id() . ':0][term][parent]' => 0, 'terms[tid:' . $term2->id() . ':0][term][depth]' => 0, 'terms[tid:' . $term2->id() . ':0][weight]' => 1);
     $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview', $edit, t('Save'));
     // All terms back at the root level, no indentation should be present.
     $this->assertNoPattern('|<div class="js-indentation indentation">&nbsp;</div>|');
     // Check explicitly that term 2 has no parents.
     \Drupal::entityManager()->getStorage('taxonomy_term')->resetCache();
     $parents = $taxonomy_storage->loadParents($term2->id());
     $this->assertTrue(empty($parents), 'Term 2 has no parents now');
 }
开发者ID:neetumorwani,项目名称:blogging,代码行数:29,代码来源:TaxonomyTermIndentationTest.php


示例10: 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();
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:13,代码来源:TaxonomyTermFieldAttributesTest.php


示例11: 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);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:30,代码来源:TaggedWithTest.php


示例12: 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();
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:37,代码来源:EntityReferenceItemTest.php


示例13: 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();
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:16,代码来源:EntityReferenceFieldAttributesTest.php


示例14: 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);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:51,代码来源:RssTest.php


示例15: 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;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:14,代码来源:QuickEditAutocompleteTermTest.php


示例16: 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;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:14,代码来源:QuickEditAutocompleteTermTest.php


示例17: 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();
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:17,代码来源:TermIndexTest.php


示例18: 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());
     entity_create('field_storage_config', array('field_name' => $this->fieldName1, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $this->vocabulary->id(), 'parent' => 0)))))->save();
     entity_create('field_config', array('field_name' => $this->fieldName1, 'bundle' => 'article', 'entity_type' => 'node'))->save();
     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' => 'taxonomy_term_reference_link'))->save();
     $this->fieldName2 = Unicode::strtolower($this->randomMachineName());
     entity_create('field_storage_config', array('field_name' => $this->fieldName2, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $this->vocabulary->id(), 'parent' => 0)))))->save();
     entity_create('field_config', array('field_name' => $this->fieldName2, 'bundle' => 'article', 'entity_type' => 'node'))->save();
     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' => 'taxonomy_term_reference_link'))->save();
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:18,代码来源:TermIndexTest.php


示例19: 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'));
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:47,代码来源:TermFieldMultipleVocabularyTest.php


示例20: createTermWithProperties

 /**
  * Creates a taxonomy term with specified name and other properties.
  *
  * @param array $properties
  *   Array of properties and field values to set.
  *
  * @return \Drupal\taxonomy\TermInterface
  *   The created taxonomy term.
  */
 protected function createTermWithProperties($properties)
 {
     // Use the first available text format.
     $filter_formats = filter_formats();
     $format = array_pop($filter_formats);
     $properties += array('name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'field_foo' => $this->randomMachineName());
     $term = Term::create(['name' => $properties['name'], 'description' => $properties['description'], 'format' => $format->id(), 'vid' => $this->vocabulary->id(), 'langcode' => $properties['langcode']]);
     $term->field_foo->value = $properties['field_foo'];
     $term->save();
     return $term;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:20,代码来源:TaxonomyFieldFilterTest.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP Entity\Term类代码示例发布时间:2022-05-23
下一篇:
PHP Entity\EntityUnitTestBase类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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