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


PHP Entity\Vocabulary类代码示例

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


在下文中一共展示了Vocabulary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('uc_catalog.settings');
     $view = Views::getView('uc_catalog');
     $view->initDisplay();
     $displays = array();
     foreach ($view->displayHandlers as $display) {
         if ($display->getPluginId() == 'page') {
             $displays[$display->display['id']] = $display->display['display_title'];
         }
     }
     $form['uc_catalog_display'] = array('#type' => 'select', '#title' => $this->t('Catalog display'), '#default_value' => $config->get('display'), '#options' => $displays);
     $vid = $config->get('vocabulary');
     if ($vid) {
         $catalog = Vocabulary::load($vid);
         $form['catalog_vid'] = array('#markup' => '<p>' . $this->t('The taxonomy vocabulary <a href=":edit-url">%name</a> is set as the product catalog.', [':edit-url' => Url::fromRoute('entity.taxonomy_vocabulary.edit_form', ['taxonomy_vocabulary' => $catalog->id()])->toString(), '%name' => $catalog->label()]) . '</p>');
     }
     $vocabs = array();
     $vocabularies = Vocabulary::loadMultiple();
     foreach ($vocabularies as $vid => $vocabulary) {
         $vocabs[$vid] = $vocabulary->label();
     }
     $form['uc_catalog_vid'] = array('#type' => 'select', '#title' => $this->t('Catalog vocabulary'), '#default_value' => $config->get('vocabulary'), '#options' => $vocabs);
     $form['uc_catalog_breadcrumb'] = array('#type' => 'checkbox', '#title' => $this->t('Display the catalog breadcrumb'), '#default_value' => $config->get('breadcrumb'));
     return parent::buildForm($form, $form_state);
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:29,代码来源:CatalogSettingsForm.php

示例5: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $faq_settings = $this->config('faq.settings');
     // Set up a hidden variable.
     $form['faq_display'] = array('#type' => 'hidden', '#value' => $faq_settings->get('display'));
     $form['faq_use_categories'] = array('#type' => 'checkbox', '#title' => $this->t('Categorize questions'), '#description' => $this->t('This allows the user to display the questions according to the categories configured on the add/edit FAQ page.  Use of sub-categories is only recommended for large lists of questions.  The Taxonomy module must be enabled.'), '#default_value' => $faq_settings->get('use_categories'));
     $category_options['none'] = t("Don't display");
     $category_options['categories_inline'] = $this->t('Categories inline');
     $category_options['hide_qa'] = $this->t('Clicking on category opens/hides questions and answers under category');
     $category_options['new_page'] = $this->t('Clicking on category opens the questions/answers in a new page');
     $form['faq_category_display'] = array('#type' => 'radios', '#options' => $category_options, '#title' => $this->t('Categories layout'), '#description' => $this->t('This controls how the categories are displayed on the page and what happens when someone clicks on the category.'), '#default_value' => $faq_settings->get('category_display'));
     $form['faq_category_misc'] = array('#type' => 'details', '#title' => $this->t('Miscellaneous layout settings'), '#open' => TRUE);
     $form['faq_category_misc']['faq_category_listing'] = array('#type' => 'select', '#options' => array('ol' => $this->t('Ordered list'), 'ul' => $this->t('Unordered list')), '#title' => $this->t('Categories listing style'), '#description' => t("This allows to select how the categories listing is presented.  It only applies to the 'Clicking on category opens the questions/answers in a new page' layout.  An ordered listing would number the categories, whereas an unordered list will have a bullet to the left of each category."), '#default_value' => $faq_settings->get('category_listing'));
     $form['faq_category_misc']['faq_category_hide_qa_accordion'] = array('#type' => 'checkbox', '#title' => $this->t('Use accordion effect for "opens/hides questions and answers under category" layout'), '#description' => $this->t('This enables an "accordion" style effect where when a category is clicked, the questions appears beneath, and is then hidden when another category is opened.'), '#default_value' => $faq_settings->get('category_hide_qa_accordion'));
     $form['faq_category_misc']['faq_count'] = array('#type' => 'checkbox', '#title' => $this->t('Show FAQ count'), '#description' => $this->t('This displays the number of questions in a category after the category name.'), '#default_value' => $faq_settings->get('count'));
     $form['faq_category_misc']['faq_answer_category_name'] = array('#type' => 'checkbox', '#title' => $this->t('Display category name for answers'), '#description' => t("This allows the user to toggle the visibility of the category name above each answer section for the 'Clicking on question takes user to answer further down the page' question/answer display."), '#default_value' => $faq_settings->get('answer_category_name'));
     $form['faq_category_misc']['faq_group_questions_top'] = array('#type' => 'checkbox', '#title' => t("Group questions and answers for 'Categories inline'"), '#description' => t("This controls how categories are implemented with the 'Clicking on question takes user to answer further down the page' question/answer display."), '#default_value' => $faq_settings->get('group_questions_top'));
     $form['faq_category_misc']['faq_hide_child_terms'] = array('#type' => 'checkbox', '#title' => $this->t('Only show sub-categories when parent category is selected'), '#description' => t("This allows the user more control over how and when sub-categories are displayed.  It does not affect the 'Categories inline' display."), '#default_value' => $faq_settings->get('hide_child_terms'));
     $form['faq_category_misc']['faq_show_term_page_children'] = array('#type' => 'checkbox', '#title' => $this->t('Show sub-categories on FAQ category pages'), '#description' => t("Sub-categories with 'faq' nodes will be displayed on the per category FAQ page.  This will also happen if 'Only show sub-categories when parent category is selected' is set."), '#default_value' => $faq_settings->get('show_term_page_children'));
     $moduleHandler = \Drupal::moduleHandler();
     if ($moduleHandler->moduleExists('taxonomy')) {
         $form['faq_category_advanced'] = array('#type' => 'details', '#title' => $this->t('Advanced category settings'), '#open' => FALSE);
         $vocab_options = array();
         $vocabularies = Vocabulary::loadMultiple();
         foreach ($vocabularies as $vid => $vobj) {
             $vocab_options[$vid] = $vobj->name;
         }
         if (!empty($vocab_options)) {
             $form['faq_category_advanced']['faq_omit_vocabulary'] = array('#type' => 'checkboxes', '#title' => $this->t('Omit vocabulary'), '#description' => $this->t('Terms from these vocabularies will be <em>excluded</em> from the FAQ pages.'), '#default_value' => $faq_settings->get('omit_vocabulary'), '#options' => $vocab_options, '#multiple' => TRUE);
         }
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:36,代码来源:CategoriesForm.php

示例6: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('page_title_block');
     // Create Basic page node type.
     $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
     $vocabulary = Vocabulary::create(['name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'help' => '', 'nodes' => array('page' => 'page'), 'weight' => mt_rand(0, 10)]);
     $vocabulary->save();
     // Create a field.
     $field_name = Unicode::strtolower($this->randomMachineName());
     $handler_settings = array('target_bundles' => array($vocabulary->id() => $vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'page', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     // Create a time in the past for the archive.
     $time = REQUEST_TIME - 3600;
     $this->addDefaultCommentField('node', 'page');
     for ($i = 0; $i <= 10; $i++) {
         $user = $this->drupalCreateUser();
         $term = $this->createTerm($vocabulary);
         $values = array('created' => $time, 'type' => 'page');
         $values[$field_name][]['target_id'] = $term->id();
         // Make every other node promoted.
         if ($i % 2) {
             $values['promote'] = TRUE;
         }
         $values['body'][]['value'] = \Drupal::l('Node ' . 1, new Url('entity.node.canonical', ['node' => 1]));
         $node = $this->drupalCreateNode($values);
         $comment = array('uid' => $user->id(), 'status' => CommentInterface::PUBLISHED, 'entity_id' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment');
         Comment::create($comment)->save();
     }
     // Some views, such as the "Who's Online" view, only return results if at
     // least one user is logged in.
     $account = $this->drupalCreateUser(array());
     $this->drupalLogin($account);
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:34,代码来源:DefaultViewsTest.php

示例7: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->addDefaultCommentField('node', 'page');
     $web_user = $this->drupalCreateUser(array('edit own page content', 'create page content'));
     $this->drupalLogin($web_user);
     // Add a vocabulary so we can test different view modes.
     $vocabulary = Vocabulary::create(['name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => $this->randomMachineName(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'help' => '']);
     $vocabulary->save();
     $this->vocabulary = $vocabulary;
     // Add a term to the vocabulary.
     $term = Term::create(['name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => $this->vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
     $term->save();
     $this->term = $term;
     // Create an image field.
     FieldStorageConfig::create(['field_name' => 'field_image', 'entity_type' => 'node', 'type' => 'image', 'settings' => [], 'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED])->save();
     $field_config = FieldConfig::create(['field_name' => 'field_image', 'label' => 'Images', 'entity_type' => 'node', 'bundle' => 'page', 'required' => FALSE, 'settings' => []]);
     $field_config->save();
     // Create a field.
     $this->fieldName = Unicode::strtolower($this->randomMachineName());
     $handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'page', $this->fieldName, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     entity_get_form_display('node', 'page', 'default')->setComponent($this->fieldName, array('type' => 'entity_reference_autocomplete_tags'))->save();
     // Show on default display and teaser.
     entity_get_display('node', 'page', 'default')->setComponent($this->fieldName, array('type' => 'entity_reference_label'))->save();
     entity_get_display('node', 'page', 'teaser')->setComponent($this->fieldName, array('type' => 'entity_reference_label'))->save();
     entity_get_form_display('node', 'page', 'default')->setComponent('field_image', array('type' => 'image_image', 'settings' => []))->save();
     entity_get_display('node', 'page', 'default')->setComponent('field_image')->save();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:29,代码来源:PagePreviewTest.php

示例8: setUp

 function setUp()
 {
     parent::setUp();
     // Add two new languages.
     ConfigurableLanguage::createFromLangcode('fr')->save();
     ConfigurableLanguage::createFromLangcode('es')->save();
     // Set up term names.
     $this->termNames = array('en' => 'Food in Paris', 'es' => 'Comida en Paris', 'fr' => 'Nouriture en Paris');
     // Create a vocabulary.
     $this->vocabulary = Vocabulary::create(['name' => 'Views testing tags', 'vid' => 'views_testing_tags']);
     $this->vocabulary->save();
     // Add a translatable field to the vocabulary.
     $field = FieldStorageConfig::create(array('field_name' => 'field_foo', 'entity_type' => 'taxonomy_term', 'type' => 'text'));
     $field->save();
     FieldConfig::create(['field_name' => 'field_foo', 'entity_type' => 'taxonomy_term', 'label' => 'Foo', 'bundle' => 'views_testing_tags'])->save();
     // Create term with translations.
     $taxonomy = $this->createTermWithProperties(array('name' => $this->termNames['en'], 'langcode' => 'en', 'description' => $this->termNames['en'], 'field_foo' => $this->termNames['en']));
     foreach (array('es', 'fr') as $langcode) {
         $translation = $taxonomy->addTranslation($langcode, array('name' => $this->termNames[$langcode]));
         $translation->description->value = $this->termNames[$langcode];
         $translation->field_foo->value = $this->termNames[$langcode];
     }
     $taxonomy->save();
     Views::viewsData()->clear();
     ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
     $this->container->get('router.builder')->rebuild();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:27,代码来源:TaxonomyFieldFilterTest.php

示例9: build

 /**
  * Implements \Drupal\block\BlockBase::blockBuild().
  */
 public function build()
 {
     static $vocabularies, $terms;
     $items = array();
     $faq_settings = \Drupal::config('faq.settings');
     if (!$faq_settings->get('use_categories')) {
         return;
     }
     $moduleHandler = \Drupal::moduleHandler();
     if ($moduleHandler->moduleExists('taxonomy')) {
         if (!isset($terms)) {
             $terms = array();
             $vocabularies = Vocabulary::loadMultiple();
             $vocab_omit = array_flip($faq_settings->get('omit_vocabulary'));
             $vocabularies = array_diff_key($vocabularies, $vocab_omit);
             foreach ($vocabularies as $vocab) {
                 foreach (taxonomy_get_tree($vocab->vid) as $term) {
                     if (FaqHelper::taxonomyTermCountNodes($term->tid)) {
                         $terms[$term->name] = $term->tid;
                     }
                 }
             }
         }
         if (count($terms) > 0) {
             foreach ($terms as $name => $tid) {
                 $items[] = l($name, 'faq-page/' . $tid);
             }
         }
     }
     return array('#theme' => 'item_list', '#items' => $items, '#list_type' => $faq_settings->get('category_listing'));
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:34,代码来源:FaqCategoriesBlock.php

示例10: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('system_breadcrumb_block');
     $this->drupalPlaceBlock('local_actions_block');
     $this->drupalPlaceBlock('local_tasks_block');
     $this->drupalPlaceBlock('page_title_block');
     // Create a test user.
     $admin_user = $this->drupalCreateUser(array('access content', '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 account settings', 'administer user display', 'bypass node access'));
     $this->drupalLogin($admin_user);
     // Create content type, with underscores.
     $type_name = strtolower($this->randomMachineName(8)) . '_test';
     $type = $this->drupalCreateContentType(array('name' => $type_name, 'type' => $type_name));
     $this->contentType = $type->id();
     // Create random field name with markup to test escaping.
     $this->fieldLabel = '<em>' . $this->randomMachineName(8) . '</em>';
     $this->fieldNameInput = strtolower($this->randomMachineName(8));
     $this->fieldName = 'field_' . $this->fieldNameInput;
     // Create Basic page and Article node types.
     $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
     $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
     // Create a vocabulary named "Tags".
     $vocabulary = Vocabulary::create(array('name' => 'Tags', 'vid' => 'tags', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $vocabulary->save();
     $handler_settings = array('target_bundles' => array($vocabulary->id() => $vocabulary->id()));
     $this->createEntityReferenceField('node', 'article', 'field_' . $vocabulary->id(), 'Tags', 'taxonomy_term', 'default', $handler_settings);
     entity_get_form_display('node', 'article', 'default')->setComponent('field_' . $vocabulary->id())->save();
 }
开发者ID:komejo,项目名称:article-test,代码行数:31,代码来源:ManageFieldsTest.php

示例11: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('taxonomy_term');
     // We want an entity reference field. It needs a vocabulary, terms, a field
     // storage and a field. First, create the vocabulary.
     $vocabulary = Vocabulary::create(['vid' => Unicode::strtolower($this->randomMachineName())]);
     $vocabulary->save();
     // Second, create the field.
     entity_test_create_bundle('test_bundle');
     $this->fieldName = strtolower($this->randomMachineName());
     $handler_settings = array('target_bundles' => array($vocabulary->id() => $vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('entity_test', 'test_bundle', $this->fieldName, NULL, 'taxonomy_term', 'default', $handler_settings);
     // Create two terms and also two accounts.
     for ($i = 0; $i <= 1; $i++) {
         $term = Term::create(['name' => $this->randomMachineName(), 'vid' => $vocabulary->id()]);
         $term->save();
         $this->terms[] = $term;
         $this->accounts[] = $this->createUser();
     }
     // Create three entity_test entities, the 0th entity will point to the
     // 0th account and 0th term, the 1st and 2nd entity will point to the
     // 1st account and 1st term.
     for ($i = 0; $i <= 2; $i++) {
         $entity = EntityTest::create(array('type' => 'test_bundle'));
         $entity->name->value = $this->randomMachineName();
         $index = $i ? 1 : 0;
         $entity->user_id->target_id = $this->accounts[$index]->id();
         $entity->{$this->fieldName}->target_id = $this->terms[$index]->id();
         $entity->save();
         $this->entities[] = $entity;
     }
     $this->factory = \Drupal::service('entity.query');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:34,代码来源:EntityQueryRelationshipTest.php

示例12: testTaxonomyTermHierarchy

 /**
  * Test terms in a single and multiple hierarchy.
  */
 function testTaxonomyTermHierarchy()
 {
     // Create two taxonomy terms.
     $term1 = $this->createTerm($this->vocabulary);
     $term2 = $this->createTerm($this->vocabulary);
     // Check that hierarchy is flat.
     $vocabulary = Vocabulary::load($this->vocabulary->id());
     $this->assertEqual(0, $vocabulary->getHierarchy(), 'Vocabulary is flat.');
     // Edit $term2, setting $term1 as parent.
     $edit = array();
     $edit['parent[]'] = array($term1->id());
     $this->drupalPostForm('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save'));
     // Check the hierarchy.
     $children = taxonomy_term_load_children($term1->id());
     $parents = taxonomy_term_load_parents($term2->id());
     $this->assertTrue(isset($children[$term2->id()]), 'Child found correctly.');
     $this->assertTrue(isset($parents[$term1->id()]), 'Parent found correctly.');
     // Load and save a term, confirming that parents are still set.
     $term = Term::load($term2->id());
     $term->save();
     $parents = taxonomy_term_load_parents($term2->id());
     $this->assertTrue(isset($parents[$term1->id()]), 'Parent found correctly.');
     // Create a third term and save this as a parent of term2.
     $term3 = $this->createTerm($this->vocabulary);
     $term2->parent = array($term1->id(), $term3->id());
     $term2->save();
     $parents = taxonomy_term_load_parents($term2->id());
     $this->assertTrue(isset($parents[$term1->id()]) && isset($parents[$term3->id()]), 'Both parents found successfully.');
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:32,代码来源:TermTest.php

示例13: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('node');
     $this->installEntitySchema('comment');
     $this->installEntitySchema('taxonomy_term');
     CommentType::create(['id' => 'comment_node_page', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_article', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_blog', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_book', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_forum', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_test_content_type', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'page', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'article', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'blog', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'book', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'forum', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'test_content_type', 'label' => $this->randomMachineName()])->save();
     Vocabulary::create(['vid' => 'test_vocabulary'])->save();
     // Give one unfortunate field instance invalid display settings to ensure
     // that the migration provides an empty array as a default (thus avoiding
     // an "unsupported operand types" fatal).
     Database::getConnection('default', 'migrate')->update('field_config_instance')->fields(array('data' => serialize(array('label' => 'Body', 'widget' => array('type' => 'text_textarea_with_summary', 'settings' => array('rows' => 20, 'summary_rows' => 5), 'weight' => -4, 'module' => 'text'), 'settings' => array('display_summary' => TRUE, 'text_processing' => 1, 'user_register_form' => FALSE), 'display' => array('default' => array('label' => 'hidden', 'type' => 'text_default', 'settings' => array(), 'module' => 'text', 'weight' => 0), 'teaser' => array('label' => 'hidden', 'type' => 'text_summary_or_trimmed', 'settings' => NULL, 'module' => 'text', 'weight' => 0)), 'required' => FALSE, 'description' => ''))))->condition('entity_type', 'node')->condition('bundle', 'article')->condition('field_name', 'body')->execute();
     $this->executeMigrations(['d7_field', 'd7_field_instance', 'd7_view_modes', 'd7_field_formatter_settings']);
 }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:28,代码来源:MigrateFieldFormatterSettingsTest.php

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

示例15: setUp

 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('taxonomy_term');
     // Create the default tags vocabulary.
     $vocabulary = Vocabulary::create(['name' => 'Tags', 'vid' => 'tags']);
     $vocabulary->save();
     $this->vocab = $vocabulary;
 }
开发者ID:dev981,项目名称:gaptest,代码行数:12,代码来源:TokenTaxonomyTest.php


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