コード例 #1
0
ファイル: FastTestBase.php プロジェクト: darrylri/protovbmwmo
 /**
  * {@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();
 }
コード例 #2
0
ファイル: TaxonomyTestTrait.php プロジェクト: sarahwillem/OD8
 /**
  * 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;
 }
コード例 #3
0
ファイル: TaxonomyTestTrait.php プロジェクト: 318io/318-io
 /**
  * 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;
 }
コード例 #4
0
 /**
  * {@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);
 }
コード例 #5
0
ファイル: CategoriesForm.php プロジェクト: anyforsoft/csua_d8
 /**
  * {@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);
 }
コード例 #6
0
 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);
 }
コード例 #7
0
 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();
 }
コード例 #8
0
 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();
 }
コード例 #9
0
 /**
  * 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'));
 }
コード例 #10
0
 /**
  * {@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();
 }
コード例 #11
0
 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');
 }
コード例 #12
0
ファイル: TermTest.php プロジェクト: Nikola-xiii/d8intranet
 /**
  * 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.');
 }
コード例 #13
0
 /**
  * {@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']);
 }
コード例 #14
0
ファイル: TermMatcherTest.php プロジェクト: eloiv/botafoc.cat
  /**
   * 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;
  }
コード例 #15
0
ファイル: TokenTaxonomyTest.php プロジェクト: dev981/gaptest
 /**
  * {@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;
 }
コード例 #16
0
 /**
  * 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'));
 }
コード例 #17
0
ファイル: TermCacheTagsTest.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@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;
 }
コード例 #18
0
 /**
  * {@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']);
 }
コード例 #19
0
 /**
  * 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']));
 }
コード例 #20
0
 /**
  * {@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))));
 }
コード例 #21
0
ファイル: RssNodeImport.php プロジェクト: Tawreh/mtg
 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();
 }
コード例 #22
0
ファイル: LegacyTest.php プロジェクト: aWEBoLabs/taxi
 protected function setUp()
 {
     parent::setUp();
     // Create a tags vocabulary for the 'article' content type.
     $vocabulary = Vocabulary::create(['name' => 'Tags', 'vid' => 'tags']);
     $vocabulary->save();
     $field_name = 'field_' . $vocabulary->id();
     $handler_settings = array('target_bundles' => array($vocabulary->id() => $vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     entity_get_form_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'entity_reference_autocomplete_tags'))->save();
     $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'administer nodes', 'bypass node access']));
 }
コード例 #23
0
 function testViewsHandlerVidField()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     $view = Views::getView('test_taxonomy_vid_field');
     $this->executeView($view);
     $actual = $renderer->executeInRenderContext(new RenderContext(), function () use($view) {
         return $view->field['vid']->advancedRender($view->result[0]);
     });
     $vocabulary = Vocabulary::load($this->term1->getVocabularyId());
     $expected = $vocabulary->get('name');
     $this->assertEqual($expected, $actual);
 }
コード例 #24
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig(static::$modules);
     $this->createType('page');
     $this->createType('article');
     $this->createType('blog');
     $this->createType('book');
     $this->createType('forum');
     $this->createType('test_content_type');
     Vocabulary::create(['vid' => 'test_vocabulary'])->save();
     $this->executeMigrations(['d7_field', 'd7_field_instance']);
 }
コード例 #25
0
 /**
  * Provides a workaround for the inability to use the standard profile.
  *
  * @see https://www.drupal.org/node/1708692
  */
 protected function mockStandardInstall()
 {
     $this->drupalCreateContentType(array('type' => 'article'));
     // Create the vocabulary for the tag field.
     $this->vocabulary = Vocabulary::create(['name' => 'Views testing tags', 'vid' => 'views_testing_tags']);
     $this->vocabulary->save();
     $field_name = 'field_' . $this->vocabulary->id();
     $handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     entity_get_form_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'entity_reference_autocomplete_tags', 'weight' => -4))->save();
     entity_get_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'entity_reference_label', 'weight' => 10))->save();
     entity_get_display('node', 'article', 'teaser')->setComponent($field_name, array('type' => 'entity_reference_label', 'weight' => 10))->save();
 }
コード例 #26
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Prepare to migrate user pictures as well.
     $this->installEntitySchema('file');
     $this->createType('page');
     $this->createType('article');
     $this->createType('blog');
     $this->createType('book');
     $this->createType('forum');
     $this->createType('test_content_type');
     Vocabulary::create(['vid' => 'test_vocabulary'])->save();
     $this->executeMigrations(['user_picture_field', 'user_picture_field_instance', 'd7_user_role', 'd7_field', 'd7_field_instance', 'd7_user']);
 }
コード例 #27
0
 /**
  * Form constructor.
  *
  * @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.
  *
  * @return array
  *   The form structure.
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $sitemap = \Drupal::service('custom_sitemap.sitemap');
     $entity_types = $sitemap->get_entity_types();
     $custom_links = $sitemap->get_custom_links();
     $form = array('entity-types' => array('#type' => 'vertical_tabs'), 'node' => array('#type' => 'details', '#title' => $this->t('Content types'), '#group' => 'entity-types'), 'taxonomy_term' => array('#type' => 'details', '#title' => $this->t('Vocabularies'), '#group' => 'entity-types'));
     /** @var NodeType[] $content_types */
     $content_types = NodeType::loadMultiple();
     $this->setEntityTypeDetailForm($form, 'node', $content_types, $entity_types['node']);
     /** @var Vocabulary[] $vocabularies */
     $vocabularies = Vocabulary::loadMultiple();
     $this->setEntityTypeDetailForm($form, 'taxonomy_term', $vocabularies, $entity_types['taxonomy_term']);
     return parent::buildForm($form, $form_state);
 }
コード例 #28
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp(FALSE);
     // Setup vocabulary and terms so the initial import is valid.
     Vocabulary::create(['vid' => 'tags', 'name' => 'Tags'])->save();
     // This will get a term ID of 3.
     $term = Term::create(['vid' => 'tags', 'name' => 'muh']);
     $term->save();
     // This will get a term ID of 4.
     $this->terms[$term->id()] = $term;
     $term = Term::create(['vid' => 'tags', 'name' => 'muh']);
     $term->save();
     $this->terms[$term->id()] = $term;
     ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
 }
コード例 #29
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('system_breadcrumb_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->type = $type->id();
     // Create a default vocabulary.
     $vocabulary = Vocabulary::create(array('name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'help' => '', 'nodes' => array('article' => 'article'), 'weight' => mt_rand(0, 10)));
     $vocabulary->save();
     $this->vocabulary = $vocabulary->id();
 }
コード例 #30
0
 /**
  * Tests token replacement in the "all terms" field handler.
  */
 public function testViewsHandlerAllTermsWithTokens()
 {
     $view = Views::getView('taxonomy_all_terms_test');
     $this->drupalGet('taxonomy_all_terms_token_test');
     // Term itself: {{ term_node_tid }}
     $this->assertText('Term: ' . $this->term1->getName());
     // The taxonomy term ID for the term: {{ term_node_tid__tid }}
     $this->assertText('The taxonomy term ID for the term: ' . $this->term1->id());
     // The taxonomy term name for the term: {{ term_node_tid__name }}
     $this->assertText('The taxonomy term name for the term: ' . $this->term1->getName());
     // The machine name for the vocabulary the term belongs to: {{ term_node_tid__vocabulary_vid }}
     $this->assertText('The machine name for the vocabulary the term belongs to: ' . $this->term1->getVocabularyId());
     // The name for the vocabulary the term belongs to: {{ term_node_tid__vocabulary }}
     $vocabulary = Vocabulary::load($this->term1->bundle());
     $this->assertText('The name for the vocabulary the term belongs to: ' . $vocabulary->label());
 }