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

PHP Entity\Vocabulary类代码示例

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

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



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


示例16: assertEntity

 /**
  * Validate a migrated vocabulary contains the expected values.
  *
  * @param $id
  *   Entity ID to load and check.
  * @param $expected_label
  *   The label the migrated entity should have.
  * @param $expected_description
  *   The description the migrated entity should have.
  * @param $expected_hierarchy
  *   The hierarchy setting the migrated entity should have.
  * @param $expected_weight
  *   The weight the migrated entity should have.
  */
 protected function assertEntity($id, $expected_label, $expected_description, $expected_hierarchy, $expected_weight) {
   /** @var \Drupal\taxonomy\VocabularyInterface $entity */
   $entity = Vocabulary::load($id);
   $this->assertTrue($entity instanceof VocabularyInterface);
   $this->assertIdentical($expected_label, $entity->label());
   $this->assertIdentical($expected_description, $entity->getDescription());
   $this->assertIdentical($expected_hierarchy, $entity->getHierarchy());
   $this->assertIdentical($expected_weight, $entity->get('weight'));
 }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:23,代码来源:MigrateTaxonomyVocabularyTest.php


示例17: createEntity

 /**
  * {@inheritdoc}
  */
 protected function createEntity()
 {
     // Create a "Camelids" vocabulary.
     $vocabulary = Vocabulary::create(['name' => 'Camelids', 'vid' => 'camelids']);
     $vocabulary->save();
     // Create a "Llama" taxonomy term.
     $term = Term::create(['name' => 'Llama', 'vid' => $vocabulary->id()]);
     $term->save();
     return $term;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:13,代码来源:TermCacheTagsTest.php


示例18: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('taxonomy_vocabulary');
     $this->installEntitySchema('taxonomy_term');
     $this->installConfig(['taxonomy']);
     // Set up two vocabularies (taxonomy bundles).
     Vocabulary::create(['vid' => 'tags', 'name' => 'Tags']);
     Vocabulary::create(['vid' => 'categories', 'name' => 'Categories']);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:13,代码来源:MigrateBundleTest.php


示例19: buildOptionsForm

 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $form['title_field'] = array('#type' => 'select', '#title' => $this->t('Title field'), '#options' => $this->displayHandler->getFieldLabels(TRUE), '#required' => TRUE, '#default_value' => $this->options['title_field'], '#description' => $this->t('Select the field that will be used as the title.'));
     $form['accordion_filter'] = array('#type' => 'select', '#title' => t('Use Filter'), '#options' => array(0 => t('No'), 1 => t('Yes')), '#description' => t('Filter items by taxonomy term'), '#default_value' => $this->options['accordion_filter'], '#attributes' => array('class' => array('accordion-filter-option')));
     $categories = array();
     $categories['select'] = t('Select');
     foreach (Vocabulary::loadMultiple() as $vocabulary) {
         $categories[$vocabulary->id()] = $vocabulary->get('name');
     }
     $form['accordion_filter_vocabulary'] = array('#type' => 'select', '#title' => t('Filter Vocabulary'), '#options' => $categories, '#description' => t('Which taxonomy vocabulary do you want to use for the filter'), '#default_value' => $this->options['accordion_filter_vocabulary'], '#states' => array('visible' => array('.accordion-filter-option' => array('value' => 1))));
 }
开发者ID:nearlyheadlessarvie,项目名称:bloomingline,代码行数:15,代码来源:InvAccordionStyle.php


示例20: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
     Vocabulary::create(['vid' => 'tags', 'name' => 'Tags'])->save();
     FieldStorageConfig::create(['field_name' => 'field_tags', 'entity_type' => 'node', 'type' => 'entity_reference', 'settings' => ['target_type' => 'taxonomy_term'], 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED])->save();
     FieldConfig::create(['label' => 'Tags', 'description' => '', 'field_name' => 'field_tags', 'entity_type' => 'node', 'bundle' => 'article', 'settings' => ['handler_settings' => ['target_bundles' => ['tags' => 'tags']]]])->save();
     $web_user = $this->drupalCreateUser(['administer feeds', 'bypass node access']);
     $this->drupalLogin($web_user);
     $this->type = entity_create('feeds_feed_type', ['id' => Unicode::strtolower($this->randomMachineName()), 'mappings' => [['target' => 'title', 'map' => ['value' => 'title']], ['target' => 'body', 'map' => ['value' => 'description']], ['target' => 'feeds_item', 'map' => ['guid' => 'guid', 'url' => 'url'], 'unique' => ['guid' => TRUE]], ['target' => 'created', 'map' => ['value' => 'timestamp']], ['target' => 'field_tags', 'map' => ['target_id' => 'tags'], 'settings' => ['autocreate' => TRUE]]], 'processor' => 'entity:node', 'processor_configuration' => ['values' => ['type' => 'article']], 'import_period' => FeedTypeInterface::SCHEDULE_NEVER]);
     $this->type->save();
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:12,代码来源:RssNodeImport.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP Tests\TaxonomyTestBase类代码示例发布时间:2022-05-23
下一篇:
PHP Entity\Term类代码示例发布时间: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