當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Vocabulary::id方法代碼示例

本文整理匯總了PHP中Drupal\taxonomy\Entity\Vocabulary::id方法的典型用法代碼示例。如果您正苦於以下問題:PHP Vocabulary::id方法的具體用法?PHP Vocabulary::id怎麽用?PHP Vocabulary::id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\taxonomy\Entity\Vocabulary的用法示例。


在下文中一共展示了Vocabulary::id方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('system_breadcrumb_block');
     $this->drupalPlaceBlock('local_tasks_block');
     // Create a test user.
     $this->adminUser = $this->drupalCreateUser(array('access content', 'admin classes', 'admin display suite', 'admin fields', 'administer nodes', 'view all revisions', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer taxonomy', 'administer taxonomy_term fields', 'administer taxonomy_term display', 'administer users', 'administer permissions', 'administer account settings', 'administer user display', 'administer software updates', 'access site in maintenance mode', 'administer site configuration', 'bypass node access', 'ds switch view mode'));
     $this->drupalLogin($this->adminUser);
     // Create random field name.
     $this->fieldLabel = $this->randomMachineName(8);
     $this->fieldNameInput = strtolower($this->randomMachineName(8));
     $this->fieldName = 'field_' . $this->fieldNameInput;
     // Create Article node type.
     $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article', 'revision' => TRUE));
     $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Page', 'revision' => TRUE));
     // Create a vocabulary named "Tags".
     $this->vocabulary = Vocabulary::create(array('name' => 'Tags', 'vid' => 'tags', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $this->vocabulary->save();
     $term1 = Term::create(array('name' => 'Tag 1', 'vid' => 'tags', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $term1->save();
     $term2 = Term::create(array('name' => 'Tag 2', 'vid' => 'tags', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $term2->save();
     $handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'article', 'field_' . $this->vocabulary->id(), 'Tags', 'taxonomy_term', 'default', $handler_settings, 10);
     entity_get_form_display('node', 'article', 'default')->setComponent('field_' . $this->vocabulary->id())->save();
 }
開發者ID:darrylri,項目名稱:protovbmwmo,代碼行數:29,代碼來源:FastTestBase.php

示例2: createTerm

 /**
  * Returns a new term with random properties in vocabulary $vid.
  *
  * @param \Drupal\taxonomy\Entity\Vocabulary $vocabulary
  *   The vocabulary object.
  * @param array $values
  *   (optional) An array of values to set, keyed by property name. If the
  *   entity type has bundles, the bundle key has to be specified.
  *
  * @return \Drupal\taxonomy\Entity\Term
  *   The new taxonomy term object.
  */
 function createTerm(Vocabulary $vocabulary, $values = array())
 {
     $filter_formats = filter_formats();
     $format = array_pop($filter_formats);
     $term = entity_create('taxonomy_term', $values + array('name' => $this->randomMachineName(), 'description' => array('value' => $this->randomMachineName(), 'format' => $format->id()), 'vid' => $vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $term->save();
     return $term;
 }
開發者ID:sarahwillem,項目名稱:OD8,代碼行數:20,代碼來源:TaxonomyTestTrait.php

示例3: createTerm

 /**
  * Returns a new term with random properties in vocabulary $vid.
  *
  * @param \Drupal\taxonomy\Entity\Vocabulary $vocabulary
  *   The vocabulary object.
  * @param array $values
  *   (optional) An array of values to set, keyed by property name. If the
  *   entity type has bundles, the bundle key has to be specified.
  *
  * @return \Drupal\taxonomy\Entity\Term
  *   The new taxonomy term object.
  */
 function createTerm(Vocabulary $vocabulary, $values = array())
 {
     $filter_formats = filter_formats();
     $format = array_pop($filter_formats);
     $term = Term::create($values + ['name' => $this->randomMachineName(), 'description' => ['value' => $this->randomMachineName(), 'format' => $format->id()], 'vid' => $vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
     $term->save();
     return $term;
 }
開發者ID:318io,項目名稱:318-io,代碼行數:20,代碼來源:TaxonomyTestTrait.php

示例4: testConfigTargetBundleDeletion

 /**
  * Tests that config bundle deletions are mirrored in field config settings.
  */
 public function testConfigTargetBundleDeletion()
 {
     // Attach an entity reference field to $this->nodeType.
     $name = Unicode::strtolower($this->randomMachineName());
     $label = $this->randomString();
     $vid = $this->vocabulary->id();
     $handler_settings = ['target_bundles' => [$vid => $vid]];
     $this->createEntityReferenceField('node', $this->nodeType->id(), $name, $label, 'taxonomy_term', 'default', $handler_settings);
     // Check that the 'target_bundle' setting contains the vocabulary.
     $field_config = FieldConfig::loadByName('node', $this->nodeType->id(), $name);
     $actual_handler_settings = $field_config->getSetting('handler_settings');
     $this->assertEqual($handler_settings, $actual_handler_settings);
     // Delete the vocabulary.
     $this->vocabulary->delete();
     // Check that the deleted vocabulary is no longer present in the
     // 'target_bundles' field setting.
     $field_config = FieldConfig::loadByName('node', $this->nodeType->id(), $name);
     $handler_settings = $field_config->getSetting('handler_settings');
     $this->assertTrue(empty($handler_settings['target_bundles']));
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:23,代碼來源:EntityReferenceSettingsTest.php

示例5: createTerm

  /**
   * Creates and saves a new term with in vocabulary $vid.
   *
   * @param \Drupal\taxonomy\Entity\Vocabulary $vocabulary
   *   The vocabulary object.
   * @param array $values
   *   (optional) An array of values to set, keyed by property name. If the
   *   entity type has bundles, the bundle key has to be specified.
   *
   * @return \Drupal\taxonomy\Entity\Term
   *   The new taxonomy term object.
   */
  private function createTerm(Vocabulary $vocabulary, $values = array()) {
    $filter_formats = filter_formats();
    $format = array_pop($filter_formats);

    $termStorage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
    $term = $termStorage->create($values + array(
        'name' => $this->randomMachineName(),
        'description' => array(
          'value' => $this->randomMachineName(),
          // Use the first available text format.
          'format' => $format->id(),
        ),
        'vid' => $vocabulary->id(),
        'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
      ));
    $term->save();
    return $term;
  }
開發者ID:eloiv,項目名稱:botafoc.cat,代碼行數:30,代碼來源:TermMatcherTest.php

示例6: testTranslateLinkVocabularyAdminPage

 /**
  * Tests translate link on vocabulary term list.
  */
 function testTranslateLinkVocabularyAdminPage()
 {
     $this->admin_user = $this->drupalCreateUser(array_merge(parent::getTranslatorPermissions(), array('access administration pages', 'administer taxonomy')));
     $this->drupalLogin($this->admin_user);
     $values = array('name' => $this->randomName());
     $translatable_tid = $this->createEntity($values, $this->langcodes[0], $this->vocabulary->id());
     // Create an untranslatable vocabulary.
     $untranslatable_vocabulary = entity_create('taxonomy_vocabulary', array('name' => 'untranslatable_voc', 'description' => $this->randomName(), 'vid' => 'untranslatable_voc', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'weight' => mt_rand(0, 10)));
     $untranslatable_vocabulary->save();
     $values = array('name' => $this->randomName());
     $untranslatable_tid = $this->createEntity($values, $this->langcodes[0], $untranslatable_vocabulary->id());
     // Verify translation links.
     $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
     $this->assertResponse(200, 'The translatable vocabulary page was found.');
     $this->assertLinkByHref('term/' . $translatable_tid . '/translations', 0, 'The translations link exists for a translatable vocabulary.');
     $this->assertLinkByHref('term/' . $translatable_tid . '/edit', 0, 'The edit link exists for a translatable vocabulary.');
     $this->drupalGet('admin/structure/taxonomy/manage/' . $untranslatable_vocabulary->id() . '/overview');
     $this->assertResponse(200);
     $this->assertLinkByHref('term/' . $untranslatable_tid . '/edit');
     $this->assertNoLinkByHref('term/' . $untranslatable_tid . '/translations');
 }
開發者ID:alnutile,項目名稱:drunatra,代碼行數:24,代碼來源:TermTranslationUITest.php

示例7: createTaxonomyTermReferenceField

 /**
  * Create the taxonomy term reference field for testing.
  *
  * @param string $field_name
  *   The name of the field to create.
  * @param \Drupal\taxonomy\Entity\Vocabulary $vocabulary
  *   The vocabulary that the field should use.
  *
  * @todo Move this to TaxonomyTestBase, like the other field modules.
  */
 protected function createTaxonomyTermReferenceField($field_name, $vocabulary)
 {
     entity_create('field_storage_config', array('name' => $field_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $vocabulary->id(), 'parent' => '0')))))->save();
     entity_create('field_instance_config', array('field_name' => $field_name, 'entity_type' => 'node', 'bundle' => 'article'))->save();
     entity_get_form_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'options_select'))->save();
     entity_get_display('node', 'article', 'full')->setComponent($field_name, array('type' => 'taxonomy_term_reference_link'))->save();
 }
開發者ID:anatalsceo,項目名稱:en-classe,代碼行數:17,代碼來源:TaxonomyTermFieldAttributesTest.php

示例8: setUp

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    // Create a vocabulary.
    $this->vocabulary = $this->createVocabulary();

    // Create 11 terms, which have some sub-string in common, in a
    // non-alphabetical order, so that we will have more than 10 matches later
    // when we test the correct number of results is returned, and we can test
    // the order of the results. The location of the sub-string to match varies
    // also, since it should not be necessary to start with the sub-string to
    // match it. Save term IDs to reuse later.
    $termNames = [
      'aaa 20 bbb',
      'aaa 70 bbb',
      'aaa 10 bbb',
      'aaa 12 bbb',
      'aaa 40 bbb',
      'aaa 11 bbb',
      'aaa 30 bbb',
      'aaa 50 bbb',
      'aaa 80',
      'aaa 90',
      'bbb 60 aaa',
    ];
    foreach ($termNames as $termName) {
      $term = $this->createTerm($this->vocabulary, ['name' => $termName]);
      $this->termIds[$termName] = $term->id();
    }

    // Create a taxonomy_term_reference field on the article Content Type that
    // uses a taxonomy_autocomplete widget.
    $this->fieldName = Unicode::strtolower($this->randomMachineName());
    FieldStorageConfig::create([
      'field_name' => $this->fieldName,
      'entity_type' => 'node',
      'type' => 'entity_reference',
      'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
      'settings' => [
        'target_type' => 'taxonomy_term',
      ],
    ])->save();
    FieldConfig::create([
      'field_name' => $this->fieldName,
      'bundle' => 'article',
      'entity_type' => 'node',
      'settings' => [
        'handler' => 'default',
        'handler_settings' => [
          // Restrict selection of terms to a single vocabulary.
          'target_bundles' => [
            $this->vocabulary->id() => $this->vocabulary->id(),
          ],
        ],
      ],
    ])->save();
    EntityFormDisplay::load('node.article.default')
      ->setComponent($this->fieldName, [
        'type' => 'entity_reference_autocomplete',
      ])
      ->save();
    EntityViewDisplay::load('node.article.default')
      ->setComponent($this->fieldName, [
        'type' => 'entity_reference_label',
      ])
      ->save();

    // Create a user and then login.
    $this->adminUser = $this->drupalCreateUser(['create article content']);
    $this->drupalLogin($this->adminUser);

    // Retrieve the autocomplete url.
    $this->drupalGet('node/add/article');
    $result = $this->xpath('//input[@name="' . $this->fieldName . '[0][target_id]"]');
    $this->autocompleteUrl = $this->getAbsoluteUrl($result[0]['data-autocomplete-path']);
  }
開發者ID:Greg-Boggs,項目名稱:electric-dev,代碼行數:79,代碼來源:TermAutocompleteTest.php


注:本文中的Drupal\taxonomy\Entity\Vocabulary::id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。