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

PHP Entity\NodeType类代码示例

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

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



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

示例1: testDisplayRevisionTab

 /**
  * Checks that the Revision tab is displayed correctly.
  */
 function testDisplayRevisionTab()
 {
     $this->drupalPlaceBlock('local_tasks_block');
     $this->drupalLogin($this->editor);
     $node_storage = $this->container->get('entity.manager')->getStorage('node');
     // Set page revision setting 'create new revision'. This will mean new
     // revisions are created by default when the node is edited.
     $type = NodeType::load('page');
     $type->setNewRevision(TRUE);
     $type->save();
     // Create the node.
     $node = $this->drupalCreateNode();
     // Verify the checkbox is checked on the node edit form.
     $this->drupalGet('node/' . $node->id() . '/edit');
     $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
     // Uncheck the create new revision checkbox and save the node.
     $edit = array('revision' => FALSE);
     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save and keep published');
     $this->assertUrl($node->toUrl());
     $this->assertNoLink(t('Revisions'));
     // Verify the checkbox is checked on the node edit form.
     $this->drupalGet('node/' . $node->id() . '/edit');
     $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
     // Submit the form without changing the checkbox.
     $edit = array();
     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save and keep published');
     $this->assertUrl($node->toUrl());
     $this->assertLink(t('Revisions'));
 }
开发者ID:Wylbur,项目名称:gj,代码行数:32,代码来源:NodeRevisionsUiBypassAccessTest.php


示例2: setUp

 /**
  * Performs setup tasks before each individual test method is run.
  */
 public function setUp()
 {
     parent::setUp('content_access');
     // The parent method already installs most needed node and comment schemas,
     // but here we also need the comment statistics.
     $this->installSchema('comment', array('comment_entity_statistics'));
     // Create a node type for testing.
     $type = NodeType::create(array('type' => 'page', 'name' => 'page'));
     $type->save();
     // Create anonymous user role.
     $role = Role::create(array('id' => 'anonymous', 'label' => 'anonymous'));
     $role->save();
     // Insert the anonymous user into the database, as the user table is inner
     // joined by \Drupal\comment\CommentStorage.
     User::create(array('uid' => 0, 'name' => ''))->save();
     // Create a node with attached comment.
     $this->nodes[0] = Node::create(array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => 'test title'));
     $this->nodes[0]->save();
     $comment_type = CommentType::create(array('id' => 'comment', 'target_entity_type_id' => 'node'));
     $comment_type->save();
     $this->installConfig(array('comment'));
     $this->addDefaultCommentField('node', 'page');
     $comment = Comment::create(array('entity_type' => 'node', 'entity_id' => $this->nodes[0]->id(), 'field_name' => 'comment', 'body' => 'test body', 'comment_type' => $comment_type->id()));
     $comment->save();
     $this->comments[] = $comment;
     $this->nodes[1] = Node::create(array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => 'some title'));
     $this->nodes[1]->save();
     $this->nodes[2] = Node::create(array('status' => NODE_NOT_PUBLISHED, 'type' => 'page', 'title' => 'other title'));
     $this->nodes[2]->save();
     // Also index users, to verify that they are unaffected by the processor.
     $this->index->set('datasources', array('entity:comment', 'entity:node', 'entity:user'));
     $this->index->save();
     $this->index = entity_load('search_api_index', $this->index->id(), TRUE);
 }
开发者ID:alexku,项目名称:travisintegrationtest,代码行数:37,代码来源:ContentAccessTest.php


示例3: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('node');
     // Need at least one node type present.
     NodeType::create(['type' => 'testnodetype', 'name' => 'Test node type'])->save();
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:10,代码来源:MigrateNodeStubTest.php


示例4: addParagraphedContentType

 /**
  * Adds a content type with a Paragraphs field.
  *
  * @param string $content_type_name
  *   Content type name to be used.
  * @param string $paragraphs_field_name
  *   Paragraphs field name to be used.
  */
 protected function addParagraphedContentType($content_type_name, $paragraphs_field_name)
 {
     // Create the content type.
     $node_type = NodeType::create(['type' => $content_type_name, 'name' => $content_type_name]);
     $node_type->save();
     $this->addParagraphsField($content_type_name, $paragraphs_field_name, 'node');
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:15,代码来源:ParagraphsTestBase.php


示例5: testRenameValidation

 /**
  * Tests configuration renaming validation.
  */
 public function testRenameValidation()
 {
     // Create a test entity.
     $test_entity_id = $this->randomMachineName();
     $test_entity = entity_create('config_test', array('id' => $test_entity_id, 'label' => $this->randomMachineName()));
     $test_entity->save();
     $uuid = $test_entity->uuid();
     // Stage the test entity and then delete it from the active storage.
     $active = $this->container->get('config.storage');
     $sync = $this->container->get('config.storage.sync');
     $this->copyConfig($active, $sync);
     $test_entity->delete();
     // Create a content type with a matching UUID in the active storage.
     $content_type = NodeType::create(['type' => Unicode::strtolower($this->randomMachineName(16)), 'name' => $this->randomMachineName(), 'uuid' => $uuid]);
     $content_type->save();
     // Confirm that the staged configuration is detected as a rename since the
     // UUIDs match.
     $this->configImporter->reset();
     $expected = array('node.type.' . $content_type->id() . '::config_test.dynamic.' . $test_entity_id);
     $renames = $this->configImporter->getUnprocessedConfiguration('rename');
     $this->assertIdentical($expected, $renames);
     // Try to import the configuration. We expect an exception to be thrown
     // because the staged entity is of a different type.
     try {
         $this->configImporter->import();
         $this->fail('Expected ConfigImporterException thrown when a renamed configuration entity does not match the existing entity type.');
     } catch (ConfigImporterException $e) {
         $this->pass('Expected ConfigImporterException thrown when a renamed configuration entity does not match the existing entity type.');
         $expected = array(SafeMarkup::format('Entity type mismatch on rename. @old_type not equal to @new_type for existing configuration @old_name and staged configuration @new_name.', array('@old_type' => 'node_type', '@new_type' => 'config_test', '@old_name' => 'node.type.' . $content_type->id(), '@new_name' => 'config_test.dynamic.' . $test_entity_id)));
         $this->assertEqual($expected, $this->configImporter->getErrors());
     }
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:35,代码来源:ConfigImportRenameValidationTest.php


示例6: testScheduledNodeDelete

 /**
  * Tests the deletion of a scheduled node.
  *
  * This tests if it is possible to delete a node that does not have a
  * publication date set, when scheduled publishing is required.
  *
  * @see https://drupal.org/node/1614880
  */
 public function testScheduledNodeDelete()
 {
     // Log in.
     $this->drupalLogin($this->adminUser);
     // Create a published and an unpublished node, both without scheduling.
     $published_node = $this->drupalCreateNode(['type' => 'page', 'status' => 1]);
     $unpublished_node = $this->drupalCreateNode(['type' => 'page', 'status' => 0]);
     // Make scheduled publishing and unpublishing required.
     $node_type = NodeType::load('page');
     $node_type->setThirdPartySetting('scheduler', 'publish_required', TRUE);
     $node_type->setThirdPartySetting('scheduler', 'unpublish_required', TRUE);
     $node_type->save();
     // Check that deleting the nodes does not throw form validation errors.
     ### @TODO Delete was a button in 7.x but a separate link node/<nid>/delete in 8.x
     ### Is the previous validation (that we had to avoid on delete) still done now in D8, given that there is no form?
     ### Maybe this test is not actually checking anything useful? Can it be altered to do something testable?
     $this->drupalGet('node/' . $published_node->id() . '/delete');
     // Note that the text 'error message' is used in a header h2 html tag which
     // is normally made hidden from browsers but will be in the page source.
     // It is also good when testing for the absense of somthing to also test
     // for the presence of text, hence the second assertion for each check.
     $this->assertNoRaw(t('Error message'), 'No error messages are shown when trying to delete a published node with no scheduling information.');
     $this->assertRaw(t('Are you sure you want to delete the content'), 'The deletion warning message is shown immediately when trying to delete a published node with no scheduling information.');
     $this->drupalGet('node/' . $unpublished_node->id() . '/delete');
     $this->assertNoRaw(t('Error message'), 'No error messages are shown when trying to delete an unpublished node with no scheduling information.');
     $this->assertRaw(t('Are you sure you want to delete the content'), 'The deletion warning message is shown immediately when trying to delete an unpublished node with no scheduling information.');
 }
开发者ID:blakefrederick,项目名称:sas-backend,代码行数:35,代码来源:SchedulerDeleteNodeTest.php


示例7: setUp

  public function setUp() {
    parent::setup();

    $this->installConfig(array('pathauto', 'taxonomy', 'system', 'node'));

    $this->installEntitySchema('user');
    $this->installEntitySchema('node');
    $this->installEntitySchema('taxonomy_term');

    ConfigurableLanguage::createFromLangcode('fr')->save();

    $this->installSchema('node', array('node_access'));
    $this->installSchema('system', array('url_alias', 'sequences', 'router'));

    $type = NodeType::create(['type' => 'page']);
    $type->save();
    node_add_body_field($type);

    $this->nodePattern = $this->createPattern('node', '/content/[node:title]');
    $this->userPattern = $this->createPattern('user', '/users/[user:name]');

    \Drupal::service('router.builder')->rebuild();

    $this->currentUser = entity_create('user', array('name' => $this->randomMachineName()));
    $this->currentUser->save();
  }
开发者ID:AshishNaik021,项目名称:iimisac-d8,代码行数:26,代码来源:PathautoUnitTest.php


示例8: prepareTranslationSuggestions

 /**
  * Prepare a node to get suggestions from.
  *
  * Creates a node with two file fields. The first one is not translatable,
  * the second one is. Both fields got two files attached, where one has
  * translatable content (title and atl-text) and the other one not.
  *
  * @return object
  *   The node which is prepared with all needed fields for the suggestions.
  */
 protected function prepareTranslationSuggestions()
 {
     // Create a content type with fields.
     // Only the first field is a translatable reference.
     $type = NodeType::create(['type' => $this->randomMachineName()]);
     $type->save();
     $content_translation_manager = \Drupal::service('content_translation.manager');
     $content_translation_manager->setEnabled('node', $type->id(), TRUE);
     $field1 = FieldStorageConfig::create(array('field_name' => 'field1', 'entity_type' => 'node', 'type' => 'entity_reference', 'cardinality' => -1, 'settings' => array('target_type' => 'node')));
     $field1->save();
     $field2 = FieldStorageConfig::create(array('field_name' => 'field2', 'entity_type' => 'node', 'type' => 'entity_reference', 'cardinality' => -1, 'settings' => array('target_type' => 'node')));
     $field2->save();
     // Create field instances on the content type.
     FieldConfig::create(array('field_storage' => $field1, 'bundle' => $type->id(), 'label' => 'Field 1', 'translatable' => FALSE, 'settings' => array()))->save();
     FieldConfig::create(array('field_storage' => $field2, 'bundle' => $type->id(), 'label' => 'Field 2', 'translatable' => TRUE, 'settings' => array()))->save();
     // Create a translatable body field.
     node_add_body_field($type);
     $field = FieldConfig::loadByName('node', $type->id(), 'body');
     $field->setTranslatable(TRUE);
     $field->save();
     // Create 4 nodes to be referenced.
     $references = array();
     for ($i = 0; $i < 4; $i++) {
         $references[$i] = Node::create(array('title' => $this->randomMachineName(), 'body' => $this->randomMachineName(), 'type' => $type->id()));
         $references[$i]->save();
     }
     // Create a node with two translatable and two non-translatable references.
     $node = Node::create(array('title' => $this->randomMachineName(), 'type' => $type->id(), 'language' => 'en', 'body' => $this->randomMachineName(), $field1->getName() => array(array('target_id' => $references[0]->id()), array('target_id' => $references[1]->id())), $field2->getName() => array(array('target_id' => $references[2]->id()), array('target_id' => $references[3]->id()))));
     $node->save();
     $link = MenuLinkContent::create(['link' => [['uri' => 'entity:node/' . $node->id()]], 'title' => 'Node menu link', 'menu_name' => 'main']);
     $link->save();
     $node->link = $link;
     return $node;
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:44,代码来源:ContentEntitySuggestionsTest.php


示例9: testExportWithReferences

 /**
  * Tests exportContentWithReferences().
  */
 public function testExportWithReferences()
 {
     \Drupal::service('module_installer')->install(['node', 'default_content']);
     \Drupal::service('router.builder')->rebuild();
     $this->defaultContentManager = \Drupal::service('default_content.manager');
     $user = User::create(['name' => 'my username']);
     $user->save();
     // Reload the user to get the proper casted values from the DB.
     $user = User::load($user->id());
     $node_type = NodeType::create(['type' => 'test']);
     $node_type->save();
     $node = Node::create(['type' => $node_type->id(), 'title' => 'test node', 'uid' => $user->id()]);
     $node->save();
     // Reload the node to get the proper casted values from the DB.
     $node = Node::load($node->id());
     /** @var \Symfony\Component\Serializer\Serializer $serializer */
     $serializer = \Drupal::service('serializer');
     \Drupal::service('rest.link_manager')->setLinkDomain(DefaultContentManager::LINK_DOMAIN);
     $expected_node = $serializer->serialize($node, 'hal_json', ['json_encode_options' => JSON_PRETTY_PRINT]);
     $expected_user = $serializer->serialize($user, 'hal_json', ['json_encode_options' => JSON_PRETTY_PRINT]);
     $exported_by_entity_type = $this->defaultContentManager->exportContentWithReferences('node', $node->id());
     // Ensure that the node type is not tryed to be exported.
     $this->assertEqual(array_keys($exported_by_entity_type), ['node', 'user']);
     // Ensure the right UUIDs are exported.
     $this->assertEqual([$node->uuid()], array_keys($exported_by_entity_type['node']));
     $this->assertEqual([$user->uuid()], array_keys($exported_by_entity_type['user']));
     // Compare the actual serialized data.
     $this->assertEqual(reset($exported_by_entity_type['node']), $expected_node);
     $this->assertEqual(reset($exported_by_entity_type['user']), $expected_user);
 }
开发者ID:lokeoke,项目名称:d8intranet,代码行数:33,代码来源:DefaultContentManagerIntegrationTest.php


示例10: testNodeFormSaveWithoutRevision

 /**
  * Checks that unchecking 'Create new revision' works when editing a node.
  */
 function testNodeFormSaveWithoutRevision()
 {
     $this->drupalLogin($this->editor);
     $node_storage = $this->container->get('entity.manager')->getStorage('node');
     // Set page revision setting 'create new revision'. This will mean new
     // revisions are created by default when the node is edited.
     $type = NodeType::load('page');
     $type->setNewRevision(TRUE);
     $type->save();
     // Create the node.
     $node = $this->drupalCreateNode();
     // Verify the checkbox is checked on the node edit form.
     $this->drupalGet('node/' . $node->id() . '/edit');
     $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
     // Uncheck the create new revision checkbox and save the node.
     $edit = array('revision' => FALSE);
     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
     // Load the node again and check the revision is the same as before.
     $node_storage->resetCache(array($node->id()));
     $node_revision = $node_storage->load($node->id(), TRUE);
     $this->assertEqual($node_revision->getRevisionId(), $node->getRevisionId(), "After an existing node is saved with 'Create new revision' unchecked, a new revision is not created.");
     // Verify the checkbox is checked on the node edit form.
     $this->drupalGet('node/' . $node->id() . '/edit');
     $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
     // Submit the form without changing the checkbox.
     $edit = array();
     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
     // Load the node again and check the revision is different from before.
     $node_storage->resetCache(array($node->id()));
     $node_revision = $node_storage->load($node->id());
     $this->assertNotEqual($node_revision->getRevisionId(), $node->getRevisionId(), "After an existing node is saved with 'Create new revision' checked, a new revision is created.");
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:35,代码来源:NodeRevisionsUiTest.php


示例11: setUp

 protected function setUp()
 {
     parent::setUp();
     node_access_test_add_field(NodeType::load('article'));
     node_access_rebuild();
     \Drupal::state()->set('node_access_test.private', TRUE);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:7,代码来源:NodeAccessBaseTableTest.php


示例12: testNodeType

 /**
  * Tests Drupal 6 node type to Drupal 8 migration.
  */
 public function testNodeType()
 {
     $migration = entity_load('migration', 'd6_node_type');
     // Test the test_page content type.
     $node_type_page = NodeType::load('test_page');
     $this->assertIdentical('test_page', $node_type_page->id(), 'Node type test_page loaded');
     $this->assertIdentical(TRUE, $node_type_page->displaySubmitted());
     $this->assertIdentical(FALSE, $node_type_page->isNewRevision());
     $this->assertIdentical(DRUPAL_OPTIONAL, $node_type_page->getPreviewMode());
     $this->assertIdentical($migration->getIdMap()->lookupDestinationID(array('test_page')), array('test_page'));
     // Test we have a body field.
     $field = FieldConfig::loadByName('node', 'test_page', 'body');
     $this->assertIdentical('This is the body field label', $field->getLabel(), 'Body field was found.');
     // Test the test_story content type.
     $node_type_story = NodeType::load('test_story');
     $this->assertIdentical('test_story', $node_type_story->id(), 'Node type test_story loaded');
     $this->assertIdentical(TRUE, $node_type_story->displaySubmitted());
     $this->assertIdentical(FALSE, $node_type_story->isNewRevision());
     $this->assertIdentical(DRUPAL_OPTIONAL, $node_type_story->getPreviewMode());
     $this->assertIdentical($migration->getIdMap()->lookupDestinationID(array('test_story')), array('test_story'));
     // Test we don't have a body field.
     $field = FieldConfig::loadByName('node', 'test_story', 'body');
     $this->assertIdentical(NULL, $field, 'No body field found');
     // Test the test_event content type.
     $node_type_event = NodeType::load('test_event');
     $this->assertIdentical('test_event', $node_type_event->id(), 'Node type test_event loaded');
     $this->assertIdentical(TRUE, $node_type_event->displaySubmitted());
     $this->assertIdentical(TRUE, $node_type_event->isNewRevision());
     $this->assertIdentical(DRUPAL_OPTIONAL, $node_type_event->getPreviewMode());
     $this->assertIdentical($migration->getIdMap()->lookupDestinationID(array('test_event')), array('test_event'));
     // Test we have a body field.
     $field = FieldConfig::loadByName('node', 'test_event', 'body');
     $this->assertIdentical('Body', $field->getLabel(), 'Body field was found.');
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:37,代码来源:MigrateNodeTypeTest.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: settingsForm

 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $options = array();
     $types = NodeType::loadMultiple();
     $comment_fields = $this->commentManager ? $this->commentManager->getFields('node') : array();
     $map = array($this->t('Hidden'), $this->t('Closed'), $this->t('Open'));
     foreach ($types as $type) {
         $options[$type->id()] = array('type' => array('#markup' => $this->t($type->label())));
         if ($this->commentManager) {
             $fields = array();
             foreach ($comment_fields as $field_name => $info) {
                 // Find all comment fields for the bundle.
                 if (in_array($type->id(), $info['bundles'])) {
                     $instance = FieldConfig::loadByName('node', $type->id(), $field_name);
                     $default_mode = reset($instance->default_value);
                     $fields[] = SafeMarkup::format('@field: !state', array('@field' => $instance->label(), '!state' => $map[$default_mode['status']]));
                 }
             }
             // @todo Refactor display of comment fields.
             if (!empty($fields)) {
                 $options[$type->id()]['comments'] = array('data' => array('#theme' => 'item_list', '#items' => $fields));
             } else {
                 $options[$type->id()]['comments'] = $this->t('No comment fields');
             }
         }
     }
     if (empty($options)) {
         $create_url = $this->urlGenerator->generateFromRoute('node.type_add');
         $this->setMessage($this->t('You do not have any content types that can be generated. <a href="@create-type">Go create a new content type</a> already!</a>', array('@create-type' => $create_url)), 'error', FALSE);
         return;
     }
     $header = array('type' => $this->t('Content type'));
     if ($this->commentManager) {
         $header['comments'] = array('data' => $this->t('Comments'), 'class' => array(RESPONSIVE_PRIORITY_MEDIUM));
     }
     $form['node_types'] = array('#type' => 'tableselect', '#header' => $header, '#options' => $options);
     $form['kill'] = array('#type' => 'checkbox', '#title' => $this->t('<strong>Delete all content</strong> in these content types before generating new content.'), '#default_value' => $this->getSetting('kill'));
     $form['num'] = array('#type' => 'textfield', '#title' => $this->t('How many nodes would you like to generate?'), '#default_value' => $this->getSetting('num'), '#size' => 10);
     $options = array(1 => $this->t('Now'));
     foreach (array(3600, 86400, 604800, 2592000, 31536000) as $interval) {
         $options[$interval] = \Drupal::service('date.formatter')->formatInterval($interval, 1) . ' ' . $this->t('ago');
     }
     $form['time_range'] = array('#type' => 'select', '#title' => $this->t('How far back in time should the nodes be dated?'), '#description' => $this->t('Node creation dates will be distributed randomly from the current time, back to the selected time.'), '#options' => $options, '#default_value' => 604800);
     $form['max_comments'] = array('#type' => $this->moduleHandler->moduleExists('comment') ? 'textfield' : 'value', '#title' => $this->t('Maximum number of comments per node.'), '#description' => $this->t('You must also enable comments for the content types you are generating. Note that some nodes will randomly receive zero comments. Some will receive the max.'), '#default_value' => $this->getSetting('max_comments'), '#size' => 3, '#access' => $this->moduleHandler->moduleExists('comment'));
     $form['title_length'] = array('#type' => 'textfield', '#title' => $this->t('Maximum number of words in titles'), '#default_value' => $this->getSetting('title_length'), '#size' => 10);
     $form['add_alias'] = array('#type' => 'checkbox', '#disabled' => !$this->moduleHandler->moduleExists('path'), '#description' => $this->t('Requires path.module'), '#title' => $this->t('Add an url alias for each node.'), '#default_value' => FALSE);
     $form['add_statistics'] = array('#type' => 'checkbox', '#title' => $this->t('Add statistics for each node (node_counter table).'), '#default_value' => TRUE, '#access' => $this->moduleHandler->moduleExists('statistics'));
     $options = array();
     // We always need a language
     $languages = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_ALL);
     foreach ($languages as $langcode => $language) {
         $options[$langcode] = $language->getName();
     }
     $default_language = \Drupal::service('language.default')->get();
     $default_langcode = $default_language->getId();
     $form['add_language'] = array('#type' => 'select', '#title' => $this->t('Set language on nodes'), '#multiple' => TRUE, '#description' => $this->t('Requires locale.module'), '#options' => $options, '#default_value' => array($default_langcode));
     $form['submit'] = array('#type' => 'submit', '#value' => $this->t('Generate'), '#tableselect' => TRUE);
     $form['#redirect'] = FALSE;
     return $form;
 }
开发者ID:slovak-drupal-association,项目名称:dccs,代码行数:63,代码来源:ContentDevelGenerate.php


示例15: setUp

 protected function setUp()
 {
     parent::setUp();
     // Ensure the page node type exists.
     NodeType::create(['type' => 'page', 'name' => 'page'])->save();
     ViewTestData::createTestViews(get_class($this), array('field_test_views'));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:7,代码来源:FieldTestBase.php


示例16: testComment

 /**
  * Tests the normalization of comments.
  */
 public function testComment()
 {
     $node_type = NodeType::create(['type' => 'example_type']);
     $node_type->save();
     $account = User::create(['name' => $this->randomMachineName()]);
     $account->save();
     // Add comment type.
     $this->container->get('entity.manager')->getStorage('comment_type')->create(array('id' => 'comment', 'label' => 'comment', 'target_entity_type_id' => 'node'))->save();
     $this->addDefaultCommentField('node', 'example_type');
     $node = Node::create(['title' => $this->randomMachineName(), 'uid' => $account->id(), 'type' => $node_type->id(), 'status' => NODE_PUBLISHED, 'promote' => 1, 'sticky' => 0, 'body' => [['value' => $this->randomMachineName(), 'format' => $this->randomMachineName()]]]);
     $node->save();
     $parent_comment = Comment::create(array('uid' => $account->id(), 'subject' => $this->randomMachineName(), 'comment_body' => ['value' => $this->randomMachineName(), 'format' => NULL], 'entity_id' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment'));
     $parent_comment->save();
     $comment = Comment::create(array('uid' => $account->id(), 'subject' => $this->randomMachineName(), 'comment_body' => ['value' => $this->randomMachineName(), 'format' => NULL], 'entity_id' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'pid' => $parent_comment->id(), 'mail' => '[email protected]', 'homepage' => 'http://buytaert.net'));
     $comment->save();
     $original_values = $comment->toArray();
     // Hostname will always be denied view access.
     // No value will exist for name as this is only for anonymous users.
     unset($original_values['hostname'], $original_values['name']);
     $normalized = $this->serializer->normalize($comment, $this->format, ['account' => $account]);
     // Assert that the hostname field does not appear at all in the normalized
     // data.
     $this->assertFalse(array_key_exists('hostname', $normalized), 'Hostname was not found in normalized comment data.');
     /** @var \Drupal\comment\CommentInterface $denormalized_comment */
     $denormalized_comment = $this->serializer->denormalize($normalized, 'Drupal\\comment\\Entity\\Comment', $this->format, ['account' => $account]);
     // Before comparing, unset values that are expected to differ.
     $denormalized_comment_values = $denormalized_comment->toArray();
     unset($denormalized_comment_values['hostname'], $denormalized_comment_values['name']);
     $this->assertEqual($original_values, $denormalized_comment_values, 'The expected comment values are restored after normalizing and denormalizing.');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:33,代码来源:EntityNormalizeTest.php


示例17: testRecreateEntity

 public function testRecreateEntity()
 {
     $type_name = Unicode::strtolower($this->randomMachineName(16));
     $content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type one'));
     $content_type->save();
     node_add_body_field($content_type);
     /** @var \Drupal\Core\Config\StorageInterface $active */
     $active = $this->container->get('config.storage');
     /** @var \Drupal\Core\Config\StorageInterface $sync */
     $sync = $this->container->get('config.storage.sync');
     $config_name = $content_type->getEntityType()->getConfigPrefix() . '.' . $content_type->id();
     $this->copyConfig($active, $sync);
     // Delete the content type. This will also delete a field storage, a field,
     // an entity view display and an entity form display.
     $content_type->delete();
     $this->assertFalse($active->exists($config_name), 'Content type\'s old name does not exist active store.');
     // Recreate with the same type - this will have a different UUID.
     $content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type two'));
     $content_type->save();
     node_add_body_field($content_type);
     $this->configImporter->reset();
     // A node type, a field, an entity view display and an entity form display
     // will be recreated.
     $creates = $this->configImporter->getUnprocessedConfiguration('create');
     $deletes = $this->configImporter->getUnprocessedConfiguration('delete');
     $this->assertEqual(5, count($creates), 'There are 5 configuration items to create.');
     $this->assertEqual(5, count($deletes), 'There are 5 configuration items to delete.');
     $this->assertEqual(0, count($this->configImporter->getUnprocessedConfiguration('update')), 'There are no configuration items to update.');
     $this->assertIdentical($creates, array_reverse($deletes), 'Deletes and creates contain the same configuration names in opposite orders due to dependencies.');
     $this->configImporter->import();
     // Verify that there is nothing more to import.
     $this->assertFalse($this->configImporter->reset()->hasUnprocessedConfigurationChanges());
     $content_type = NodeType::load($type_name);
     $this->assertEqual('Node type one', $content_type->label());
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:35,代码来源:ConfigImportRecreateTest.php


示例18: createNodeType

 /**
  * Creates a new node type.
  *
  * @param string $label
  *   The human-readable label of the type to create.
  * @param string $machine_name
  *   The machine name of the type to create.
  *
  * @return NodeType
  *   The node type just created.
  */
 protected function createNodeType($label, $machine_name)
 {
     /** @var NodeType $node_type */
     $node_type = NodeType::create(['type' => $machine_name, 'label' => $label]);
     $node_type->save();
     return $node_type;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:18,代码来源:LatestRevisionViewsFilterTest.php


示例19: testNodeType

 /**
  * Tests the node type config entity.
  */
 public function testNodeType()
 {
     // Create an english test entity.
     $node_type = NodeType::create(array('type' => 'test', 'name' => 'Node type name', 'description' => 'Node type description', 'title_label' => 'Title label', 'langcode' => 'en'));
     $node_type->save();
     $job = tmgmt_job_create('en', 'de');
     $job->translator = 'test_translator';
     $job->save();
     $job_item = tmgmt_job_item_create('config', 'node_type', 'node.type.' . $node_type->id(), array('tjid' => $job->id()));
     $job_item->save();
     $source_plugin = $this->container->get('plugin.manager.tmgmt.source')->createInstance('config');
     $data = $source_plugin->getData($job_item);
     // Test the name property.
     $this->assertEqual($data['name']['#label'], 'Name');
     $this->assertEqual($data['name']['#text'], $node_type->label());
     $this->assertEqual($data['name']['#translate'], TRUE);
     $this->assertEqual($data['description']['#label'], 'Description');
     $this->assertEqual($data['description']['#text'], $node_type->getDescription());
     $this->assertEqual($data['description']['#translate'], TRUE);
     // Test item types.
     $this->assertEqual($source_plugin->getItemTypes()['node_type'], t('Content type'));
     // Now request a translation and save it back.
     $job->requestTranslation();
     $items = $job->getItems();
     $item = reset($items);
     $item->acceptTranslation();
     $data = $item->getData();
     // Check that the translations were saved correctly.
     $language_manager = \Drupal::languageManager();
     $language_manager->setConfigOverrideLanguage($language_manager->getLanguage('de'));
     $node_type = entity_load('node_type', $node_type->id());
     $this->assertEqual($node_type->label(), $data['name']['#translation']['#text']);
     $this->assertEqual($node_type->getDescription(), $data['description']['#translation']['#text']);
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:37,代码来源:ConfigSourceUnitTest.php


示例20: setUp

该文章已有0人参与评论

请发表评论

全部评论

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