当前位置: 首页>>代码示例>>PHP>>正文


PHP VocabularyInterface::label方法代码示例

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


在下文中一共展示了VocabularyInterface::label方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:37,代码来源:EntityReferenceItemTest.php

示例2: testTaxonomyTokenReplacement

 /**
  * Creates some terms and a node, then tests the tokens generated from them.
  */
 function testTaxonomyTokenReplacement()
 {
     $token_service = \Drupal::token();
     $language_interface = \Drupal::languageManager()->getCurrentLanguage();
     // Create two taxonomy terms.
     $term1 = $this->createTerm($this->vocabulary);
     $term2 = $this->createTerm($this->vocabulary);
     // Edit $term2, setting $term1 as parent.
     $edit = array();
     $edit['name[0][value]'] = '<blink>Blinking Text</blink>';
     $edit['parent[]'] = array($term1->id());
     $this->drupalPostForm('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save'));
     // Create node with term2.
     $edit = array();
     $node = $this->drupalCreateNode(array('type' => 'article'));
     $edit[$this->fieldName . '[]'] = $term2->id();
     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
     // Generate and test sanitized tokens for term1.
     $tests = array();
     $tests['[term:tid]'] = $term1->id();
     $tests['[term:name]'] = Html::escape($term1->getName());
     $tests['[term:description]'] = $term1->description->processed;
     $tests['[term:url]'] = $term1->url('canonical', array('absolute' => TRUE));
     $tests['[term:node-count]'] = 0;
     $tests['[term:parent:name]'] = '[term:parent:name]';
     $tests['[term:vocabulary:name]'] = Html::escape($this->vocabulary->label());
     $tests['[term:vocabulary]'] = Html::escape($this->vocabulary->label());
     $base_bubbleable_metadata = BubbleableMetadata::createFromObject($term1);
     $metadata_tests = array();
     $metadata_tests['[term:tid]'] = $base_bubbleable_metadata;
     $metadata_tests['[term:name]'] = $base_bubbleable_metadata;
     $metadata_tests['[term:description]'] = $base_bubbleable_metadata;
     $metadata_tests['[term:url]'] = $base_bubbleable_metadata;
     $metadata_tests['[term:node-count]'] = $base_bubbleable_metadata;
     $metadata_tests['[term:parent:name]'] = $base_bubbleable_metadata;
     $bubbleable_metadata = clone $base_bubbleable_metadata;
     $metadata_tests['[term:vocabulary:name]'] = $bubbleable_metadata->addCacheTags($this->vocabulary->getCacheTags());
     $metadata_tests['[term:vocabulary]'] = $bubbleable_metadata->addCacheTags($this->vocabulary->getCacheTags());
     foreach ($tests as $input => $expected) {
         $bubbleable_metadata = new BubbleableMetadata();
         $output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->getId()), $bubbleable_metadata);
         $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
         $this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
     }
     // Generate and test sanitized tokens for term2.
     $tests = array();
     $tests['[term:tid]'] = $term2->id();
     $tests['[term:name]'] = Html::escape($term2->getName());
     $tests['[term:description]'] = $term2->description->processed;
     $tests['[term:url]'] = $term2->url('canonical', array('absolute' => TRUE));
     $tests['[term:node-count]'] = 1;
     $tests['[term:parent:name]'] = Html::escape($term1->getName());
     $tests['[term:parent:url]'] = $term1->url('canonical', array('absolute' => TRUE));
     $tests['[term:parent:parent:name]'] = '[term:parent:parent:name]';
     $tests['[term:vocabulary:name]'] = Html::escape($this->vocabulary->label());
     // Test to make sure that we generated something for each token.
     $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
     foreach ($tests as $input => $expected) {
         $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->getId()));
         $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
     }
     // Generate and test unsanitized tokens.
     $tests['[term:name]'] = $term2->getName();
     $tests['[term:description]'] = $term2->getDescription();
     $tests['[term:parent:name]'] = $term1->getName();
     $tests['[term:vocabulary:name]'] = $this->vocabulary->label();
     foreach ($tests as $input => $expected) {
         $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
         $this->assertEqual($output, $expected, format_string('Unsanitized taxonomy term token %token replaced.', array('%token' => $input)));
     }
     // Generate and test sanitized tokens.
     $tests = array();
     $tests['[vocabulary:vid]'] = $this->vocabulary->id();
     $tests['[vocabulary:name]'] = Html::escape($this->vocabulary->label());
     $tests['[vocabulary:description]'] = Xss::filter($this->vocabulary->getDescription());
     $tests['[vocabulary:node-count]'] = 1;
     $tests['[vocabulary:term-count]'] = 2;
     // Test to make sure that we generated something for each token.
     $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
     foreach ($tests as $input => $expected) {
         $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->getId()));
         $this->assertEqual($output, $expected, format_string('Sanitized taxonomy vocabulary token %token replaced.', array('%token' => $input)));
     }
     // Generate and test unsanitized tokens.
     $tests['[vocabulary:name]'] = $this->vocabulary->label();
     $tests['[vocabulary:description]'] = $this->vocabulary->getDescription();
     foreach ($tests as $input => $expected) {
         $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
         $this->assertEqual($output, $expected, format_string('Unsanitized taxonomy vocabulary token %token replaced.', array('%token' => $input)));
     }
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:94,代码来源:TokenReplaceTest.php

示例3: vocabularyTitle

 /**
  * Route title callback.
  *
  * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary
  *   The vocabulary.
  *
  * @return string
  *   The vocabulary label as a render array.
  */
 public function vocabularyTitle(VocabularyInterface $taxonomy_vocabulary)
 {
     return ['#markup' => $taxonomy_vocabulary->label(), '#allowed_tags' => Xss::getHtmlTagList()];
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:13,代码来源:TaxonomyController.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: 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 SafeMarkup::xssFilter($taxonomy_vocabulary->label());
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:13,代码来源:TaxonomyController.php


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