本文整理汇总了PHP中Drupal\comment\Entity\CommentType类的典型用法代码示例。如果您正苦于以下问题:PHP CommentType类的具体用法?PHP CommentType怎么用?PHP CommentType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommentType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: 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
示例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: testCommentType
/**
* Tests the Drupal 6 to Drupal 8 comment type migration.
*/
public function testCommentType()
{
$comment_type = CommentType::load('comment');
$this->assertIdentical('node', $comment_type->getTargetEntityTypeId());
$comment_type = CommentType::load('comment_no_subject');
$this->assertIdentical('node', $comment_type->getTargetEntityTypeId());
}
开发者ID:scratch,项目名称:gai,代码行数:10,代码来源:MigrateCommentTypeTest.php
示例4: createNodeBundles
/**
* Creates the necessary node bundles for the default configuration.
*/
protected function createNodeBundles()
{
if ($this->profile != 'standard') {
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
}
// Add comments to article.
$comment_type = CommentType::create(array('id' => 'comment', 'target_entity_type_id' => 'node'));
$comment_type->save();
$this->addDefaultCommentField('node', 'article');
// Add Image field to article.
$field_name = strtolower('field_image');
$min_resolution = 50;
$max_resolution = 100;
$field_settings = array('max_resolution' => $max_resolution . 'x' . $max_resolution, 'min_resolution' => $min_resolution . 'x' . $min_resolution, 'alt_field' => 0);
$this->createImageField($field_name, 'article', array(), $field_settings);
// Add tags field to Article.
// Create a tags vocabulary for the 'article' content type.
$vocabulary = entity_create('taxonomy_vocabulary', array('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', '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();
}
开发者ID:alexku,项目名称:travisintegrationtest,代码行数:30,代码来源:IntegrationTest.php
示例5: assertEntity
/**
* Asserts a comment type entity.
*
* @param string $id
* The entity ID.
* @param string $label
* The entity label.
*/
protected function assertEntity($id, $label)
{
$entity = CommentType::load($id);
$this->assertTrue($entity instanceof CommentTypeInterface);
/** @var \Drupal\comment\CommentTypeInterface $entity */
$this->assertIdentical($label, $entity->label());
$this->assertIdentical('node', $entity->getTargetEntityTypeId());
}
开发者ID:komejo,项目名称:article-test,代码行数:16,代码来源:MigrateCommentTypeTest.php
示例6: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('entity_test');
$this->installEntitySchema('user');
$this->installEntitySchema('comment');
$this->installSchema('dblog', ['watchdog']);
// Create a new 'comment' comment-type.
CommentType::create(['id' => 'comment', 'label' => $this->randomString()])->save();
}
开发者ID:eigentor,项目名称:tommiblog,代码行数:13,代码来源:CommentIntegrationTest.php
示例7: createType
/**
* Creates a node type with a corresponding comment type.
*
* @param string $id
* The node type ID.
*/
protected function createType($id) {
NodeType::create([
'type' => $id,
'label' => $this->randomString(),
])->save();
CommentType::create([
'id' => 'comment_node_' . $id,
'label' => $this->randomString(),
'target_entity_type_id' => 'node',
])->save();
}
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:18,代码来源:MigrateUserTest.php
示例8: testCommentFieldNonStringId
/**
* Tests that comment fields cannot be added entities with non-integer IDs.
*/
public function testCommentFieldNonStringId()
{
try {
$bundle = CommentType::create(array('id' => 'foo', 'label' => 'foo', 'description' => '', 'target_entity_type_id' => 'entity_test_string_id'));
$bundle->save();
$field_storage = entity_create('field_storage_config', array('field_name' => 'foo', 'entity_type' => 'entity_test_string_id', 'settings' => array('comment_type' => 'entity_test_string_id'), 'type' => 'comment'));
$field_storage->save();
$this->fail('Did not throw an exception as expected.');
} catch (\UnexpectedValueException $e) {
$this->pass('Exception thrown when trying to create comment field on Entity Type with string ID.');
}
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:15,代码来源:CommentStringIdEntitiesTest.php
示例9: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('comment');
$this->installEntitySchema('node');
// Make sure uid 0 is created (default uid for comments is 0).
$storage = \Drupal::entityManager()->getStorage('user');
// Insert a row for the anonymous user.
$storage->create(array('uid' => 0, 'status' => 0, 'name' => ''))->save();
// Need at least one node type and comment type present.
NodeType::create(['type' => 'testnodetype', 'name' => 'Test node type'])->save();
CommentType::create(['id' => 'testcommenttype', 'label' => 'Test comment type', 'target_entity_type_id' => 'node'])->save();
}
开发者ID:sarahwillem,项目名称:OD8,代码行数:16,代码来源:MigrateCommentStubTest.php
示例10: setUp
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE)
{
parent::setUp(FALSE);
// Install the necessary dependencies for node type creation to work.
$this->installEntitySchema('node');
$this->installConfig(array('field', 'node'));
$comment_type = CommentType::create(array('id' => 'comment', 'label' => 'Comment settings', 'description' => 'Comment settings', 'target_entity_type_id' => 'node'));
$comment_type->save();
$content_type = NodeType::create(['type' => $this->randomMachineName(), 'name' => $this->randomString()]);
$content_type->save();
$field_storage = FieldStorageConfig::create(array('field_name' => Unicode::strtolower($this->randomMachineName()), 'entity_type' => 'node', 'type' => 'comment'));
$field_storage->save();
FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $content_type->id(), 'label' => $this->randomMachineName() . '_label', 'description' => $this->randomMachineName() . '_description', 'settings' => array('comment_type' => $comment_type->id())])->save();
FieldConfig::create(['field_storage' => FieldStorageConfig::loadByName('node', 'body'), 'bundle' => $content_type->id(), 'label' => $this->randomMachineName() . '_body', 'settings' => array('display_summary' => TRUE)])->save();
ViewTestData::createTestViews(get_class($this), array('views_test_config'));
}
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:19,代码来源:ViewEntityDependenciesTest.php
示例11: setUp
/**
* {@inheritdoc}
*/
public function setUp($processor = NULL)
{
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.
$manager = \Drupal::getContainer()->get('plugin.manager.search_api.datasource');
$datasources['entity:comment'] = $manager->createInstance('entity:comment', array('index' => $this->index));
$datasources['entity:node'] = $manager->createInstance('entity:node', array('index' => $this->index));
$datasources['entity:user'] = $manager->createInstance('entity:user', array('index' => $this->index));
$this->index->setDatasources($datasources);
$this->index->save();
\Drupal::getContainer()->get('search_api.index_task_manager')->addItemsAll($this->index);
$index_storage = \Drupal::entityTypeManager()->getStorage('search_api_index');
$index_storage->resetCache([$this->index->id()]);
$this->index = $index_storage->load($this->index->id());
}
开发者ID:curveagency,项目名称:intranet,代码行数:44,代码来源:ContentAccessTest.php
示例12: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('comment');
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();
$this->installEntitySchema('node');
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();
$this->executeMigration('d7_field');
$this->executeMigration('d7_field_instance');
$this->executeMigration('d7_view_modes');
$this->executeMigration('d7_field_formatter_settings');
}
开发者ID:scratch,项目名称:gai,代码行数:25,代码来源:MigrateFieldFormatterSettingsTest.php
示例13: testCommentTypeDeletion
/**
* Tests deleting a comment type that still has content.
*/
public function testCommentTypeDeletion()
{
// Create a comment type programmatically.
$type = $this->createCommentType('foo');
$this->drupalCreateContentType(array('type' => 'page'));
\Drupal::service('comment.manager')->addDefaultField('node', 'page', 'foo', CommentItemInterface::OPEN, 'foo');
$field_storage = FieldStorageConfig::loadByName('node', 'foo');
$this->drupalLogin($this->adminUser);
// Create a node.
$node = Node::create(array('type' => 'page', 'title' => 'foo'));
$node->save();
// Add a new comment of this type.
$comment = Comment::create(array('comment_type' => 'foo', 'entity_type' => 'node', 'field_name' => 'foo', 'entity_id' => $node->id()));
$comment->save();
// Attempt to delete the comment type, which should not be allowed.
$this->drupalGet('admin/structure/comment/manage/' . $type->id() . '/delete');
$this->assertRaw(t('%label is used by 1 comment on your site. You can not remove this comment type until you have removed all of the %label comments.', array('%label' => $type->label())), 'The comment type will not be deleted until all comments of that type are removed.');
$this->assertRaw(t('%label is used by the %field field on your site. You can not remove this comment type until you have removed the field.', array('%label' => 'foo', '%field' => 'node.foo')), 'The comment type will not be deleted until all fields of that type are removed.');
$this->assertNoText(t('This action cannot be undone.'), 'The comment type deletion confirmation form is not available.');
// Delete the comment and the field.
$comment->delete();
$field_storage->delete();
// Attempt to delete the comment type, which should now be allowed.
$this->drupalGet('admin/structure/comment/manage/' . $type->id() . '/delete');
$this->assertRaw(t('Are you sure you want to delete %type?', array('%type' => $type->id())), 'The comment type is available for deletion.');
$this->assertText(t('This action cannot be undone.'), 'The comment type deletion confirmation form is available.');
// Test exception thrown when re-using an existing comment type.
try {
\Drupal::service('comment.manager')->addDefaultField('comment', 'comment', 'bar');
$this->fail('Exception not thrown.');
} catch (\InvalidArgumentException $e) {
$this->pass('Exception thrown if attempting to re-use comment-type from another entity type.');
}
// Delete the comment type.
$this->drupalPostForm('admin/structure/comment/manage/' . $type->id() . '/delete', array(), t('Delete'));
$this->assertNull(CommentType::load($type->id()), 'Comment type deleted.');
$this->assertRaw(t('Comment type %label has been deleted.', array('%label' => $type->label())));
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:41,代码来源:CommentTypeTest.php
示例14: bundleFieldDefinitions
/**
* {@inheritdoc}
*/
public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions)
{
if ($comment_type = CommentType::load($bundle)) {
$fields['entity_id'] = clone $base_field_definitions['entity_id'];
$fields['entity_id']->setSetting('target_type', $comment_type->getTargetEntityTypeId());
return $fields;
}
return array();
}
开发者ID:brstde,项目名称:gap1,代码行数:12,代码来源:Comment.php
示例15: createCommentType
/**
* Creates a comment comment type (bundle).
*
* @param string $label
* The comment type label.
*
* @return \Drupal\comment\Entity\CommentType
* Created comment type.
*/
protected function createCommentType($label)
{
$bundle = CommentType::create(array('id' => $label, 'label' => $label, 'description' => '', 'target_entity_type_id' => 'node'));
$bundle->save();
return $bundle;
}
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:15,代码来源:CommentTestBase.php
示例16: testCommentFunctionality
//.........这里部分代码省略.........
$this->assertRaw('comments[' . $comment1->id() . ']', 'Comment was published.');
// Delete the comment.
$this->performCommentOperation($comment1, 'delete');
$this->drupalGet('admin/content/comment');
$this->assertNoRaw('comments[' . $comment1->id() . ']', 'Comment was deleted.');
// Post another comment.
$comment1 = $this->postComment($this->entity, $this->randomMachineName(), $this->randomMachineName());
$this->assertTrue($this->commentExists($comment1), 'Comment on test entity exists.');
// Check that the comment was found.
$this->drupalGet('admin/content/comment');
$this->assertRaw('comments[' . $comment1->id() . ']', 'Comment was published.');
// Check that entity access applies to administrative page.
$this->assertText($this->entity->label(), 'Name of commented account found.');
$limited_user = $this->drupalCreateUser(array('administer comments'));
$this->drupalLogin($limited_user);
$this->drupalGet('admin/content/comment');
$this->assertNoText($this->entity->label(), 'No commented account name found.');
$this->drupalLogout();
// Deny anonymous users access to comments.
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array('access comments' => FALSE, 'post comments' => FALSE, 'skip comment approval' => FALSE, 'view test entity' => TRUE));
// Attempt to view comments while disallowed.
$this->drupalGet('entity-test/' . $this->entity->id());
$this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.');
$this->assertNoLink('Add new comment', 'Link to add comment was found.');
// Attempt to view test entity comment form while disallowed.
$this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment');
$this->assertResponse(403);
$this->assertNoFieldByName('subject[0][value]', '', 'Subject field not found.');
$this->assertNoFieldByName('comment_body[0][value]', '', 'Comment field not found.');
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array('access comments' => TRUE, 'post comments' => FALSE, 'view test entity' => TRUE, 'skip comment approval' => FALSE));
$this->drupalGet('entity_test/' . $this->entity->id());
$this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments were displayed.');
$this->assertLink('Log in', 0, 'Link to log in was found.');
$this->assertLink('register', 0, 'Link to register was found.');
$this->assertNoFieldByName('subject[0][value]', '', 'Subject field not found.');
$this->assertNoFieldByName('comment_body[0][value]', '', 'Comment field not found.');
// Test the combination of anonymous users being able to post, but not view
// comments, to ensure that access to post comments doesn't grant access to
// view them.
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array('access comments' => FALSE, 'post comments' => TRUE, 'skip comment approval' => TRUE, 'view test entity' => TRUE));
$this->drupalGet('entity_test/' . $this->entity->id());
$this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.');
$this->assertFieldByName('subject[0][value]', '', 'Subject field found.');
$this->assertFieldByName('comment_body[0][value]', '', 'Comment field found.');
$this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment/' . $comment1->id());
$this->assertResponse(403);
$this->assertNoText($comment1->getSubject(), 'Comment not displayed.');
// Test comment field widget changes.
$limited_user = $this->drupalCreateUser(array('administer entity_test fields', 'view test entity', 'administer entity_test content'));
$this->drupalLogin($limited_user);
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment');
$this->assertNoFieldChecked('edit-default-value-input-comment-0-status-0');
$this->assertNoFieldChecked('edit-default-value-input-comment-0-status-1');
$this->assertFieldChecked('edit-default-value-input-comment-0-status-2');
// Test comment option change in field settings.
$edit = array('default_value_input[comment][0][status]' => CommentItemInterface::CLOSED, 'settings[anonymous]' => COMMENT_ANONYMOUS_MAY_CONTACT);
$this->drupalPostForm(NULL, $edit, t('Save settings'));
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment');
$this->assertNoFieldChecked('edit-default-value-input-comment-0-status-0');
$this->assertFieldChecked('edit-default-value-input-comment-0-status-1');
$this->assertNoFieldChecked('edit-default-value-input-comment-0-status-2');
$this->assertFieldByName('settings[anonymous]', COMMENT_ANONYMOUS_MAY_CONTACT);
// Add a new comment-type.
$bundle = CommentType::create(array('id' => 'foobar', 'label' => 'Foobar', 'description' => '', 'target_entity_type_id' => 'entity_test'));
$bundle->save();
// Add a new comment field.
$storage_edit = array('settings[comment_type]' => 'foobar');
$this->fieldUIAddNewField('entity_test/structure/entity_test', 'foobar', 'Foobar', 'comment', $storage_edit);
// Add a third comment field.
$this->fieldUIAddNewField('entity_test/structure/entity_test', 'barfoo', 'BarFoo', 'comment', $storage_edit);
// Check the field contains the correct comment type.
$field_storage = FieldStorageConfig::load('entity_test.field_barfoo');
$this->assertTrue($field_storage);
$this->assertEqual($field_storage->getSetting('comment_type'), 'foobar');
$this->assertEqual($field_storage->getCardinality(), 1);
// Test the new entity commenting inherits default.
$random_label = $this->randomMachineName();
$data = array('bundle' => 'entity_test', 'name' => $random_label);
$new_entity = entity_create('entity_test', $data);
$new_entity->save();
$this->drupalGet('entity_test/manage/' . $new_entity->id());
$this->assertNoFieldChecked('edit-field-foobar-0-status-1');
$this->assertFieldChecked('edit-field-foobar-0-status-2');
$this->assertNoField('edit-field-foobar-0-status-0');
// @todo Check proper url and form https://www.drupal.org/node/2458323
$this->drupalGet('comment/reply/entity_test/comment/' . $new_entity->id());
$this->assertNoFieldByName('subject[0][value]', '', 'Subject field found.');
$this->assertNoFieldByName('comment_body[0][value]', '', 'Comment field found.');
// Test removal of comment_body field.
$limited_user = $this->drupalCreateUser(array('administer entity_test fields', 'post comments', 'administer comment fields', 'administer comment types'));
$this->drupalLogin($limited_user);
$this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment');
$this->assertFieldByName('comment_body[0][value]', '', 'Comment body field found.');
$this->fieldUIDeleteField('admin/structure/comment/manage/comment', 'comment.comment.comment_body', 'Comment', 'Comment settings');
$this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment');
$this->assertNoFieldByName('comment_body[0][value]', '', 'Comment body field not found.');
// Set subject field to autogenerate it.
$edit = ['subject[0][value]' => ''];
$this->drupalPostForm(NULL, $edit, t('Save'));
}
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:101,代码来源:CommentNonNodeTest.php
示例17: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
// Honeypot Configuration.
$form['configuration'] = ['#type' => 'fieldset', '#title' => t('Honeypot Configuration'), '#collapsible' => TRUE, '#collapsed' => FALSE];
$form['configuration']['protect_all_forms'] = ['#type' => 'checkbox', '#title' => t('Protect all forms with Honeypot'), '#description' => t('Enable Honeypot protection for ALL forms on this site (it is best to only enable Honeypot for the forms you need below).'), '#default_value' => $this->config('honeypot.settings')->get('protect_all_forms')];
$form['configuration']['protect_all_forms']['#description'] .= '<br />' . t('<strong>Page caching will be disabled on any page where a form is present if the Honeypot time limit is not set to 0.</strong>');
$form['configuration']['log'] = ['#type' => 'checkbox', '#title' => t('Log blocked form submissions'), '#description' => t('Log submissions that are blocked due to Honeypot protection.'), '#default_value' => $this->config('honeypot.settings')->get('log')];
$form['configuration']['element_name'] = ['#type' => 'textfield', '#title' => t('Honeypot element name'), '#description' => t("The name of the Honeypot form field. It's usually most effective to use a generic name like email, homepage, or link, but this should be changed if it interferes with fields that are already in your forms. Must not contain spaces or special characters."), '#default_value' => $this->config('honeypot.settings')->get('element_name'), '#required' => TRUE, '#size' => 30];
$form['configuration']['time_limit'] = ['#type' => 'textfield', '#title' => t('Honeypot time limit'), '#description' => t('Minimum time required before form should be considered entered by a human instead of a bot. Set to 0 to disable.'), '#default_value' => $this->config('honeypot.settings')->get('time_limit'), '#required' => TRUE, '#size' => 5, '#field_suffix' => t('seconds')];
$form['configuration']['time_limit']['#description'] .= '<br />' . t('<strong>Page caching will be disabled if there is a form protected by time limit on the page.</strong>');
// Honeypot Enabled forms.
$form_settings = $this->config('honeypot.settings')->get('form_settings');
$form['form_settings'] = ['#type' => 'fieldset', '#title' => t('Honeypot Enabled Forms'), '#description' => t("Check the boxes next to individual forms on which you'd like Honeypot protection enabled."), '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE, '#states' => ['invisible' => ['input[name="protect_all_forms"]' => ['checked' => TRUE]]]];
// Generic forms.
$form['form_settings']['general_forms'] = ['#markup' => '<h5>' . t('General Forms') . '</h5>'];
// User register form.
$form['form_settings']['user_register_form'] = ['#type' => 'checkbox', '#title' => t('User Registration form'), '#default_value' => $this->getFormSettingsValue($form_settings, 'user_register_form')];
// User password form.
$form['form_settings']['user_pass'] = ['#type' => 'checkbox', '#title' => t('User Password Reset form'), '#default_value' => $this->getFormSettingsValue($form_settings, 'user_pass')];
// If webform.module enabled, add webforms.
// TODO D8 - See if D8 version of Webform.module still uses this form ID.
if (\Drupal::moduleHandler()->moduleExists('webform')) {
$form['form_settings']['webforms'] = ['#type' => 'checkbox', '#title' => t('Webforms (all)'), '#default_value' => $this->getFormSettingsValue($form_settings, 'webforms')];
}
// If contact.module enabled, add contact forms.
if (\Drupal::moduleHandler()->moduleExists('contact')) {
$form['form_settings']['contact_forms'] = ['#markup' => '<h5>' . t('Contact Forms') . '</h5>'];
$bundles = \Drupal::entityManager()->getBundleInfo('contact_message');
$formController = \Drupal::entityManager()->getFormObject('contact_message', 'default');
foreach ($bundles as $bundle_key => $bundle) {
$stub = entity_create('contact_message', ['contact_form' => $bundle_key]);
$formController->setEntity($stub);
$form_id = $formController->getFormId();
$form['form_settings'][$form_id] = ['#type' => 'checkbox', '#title' => SafeMarkup::checkPlain($bundle['label']), '#default_value' => $this->getFormSettingsValue($form_settings, $form_id)];
}
}
// Node types for node forms.
if (\Drupal::moduleHandler()->moduleExists('node')) {
$types = NodeType::loadMultiple();
if (!empty($types)) {
// Node forms.
$form['form_settings']['node_forms'] = ['#markup' => '<h5>' . t('Node Forms') . '</h5>'];
foreach ($types as $type) {
$id = $type->getEntityTypeId() . '_node_form';
$form['form_settings'][$id] = ['#type' => 'checkbox', '#title' => t('@name node form', ['@name' => $type->label()]), '#default_value' => $this->getFormSettingsValue($form_settings, $id)];
}
}
}
// Comment types for comment forms.
if (\Drupal::moduleHandler()->moduleExists('comment')) {
$types = CommentType::loadMultiple();
if (!empty($types)) {
$form['form_settings']['comment_forms'] = ['#markup' => '<h5>' . t('Comment Forms') . '</h5>'];
foreach ($types as $type) {
$id = 'comment_' . $type->id() . '_form';
$form['form_settings'][$id] = ['#type' => 'checkbox', '#title' => t('@name comment form', ['@name' => $type->label()]), '#default_value' => $this->getFormSettingsValue($form_settings, $id)];
}
}
}
// Store the keys we want to save in configuration when form is submitted.
$keys_to_save = array_keys($form['configuration']);
foreach ($keys_to_save as $key => $key_to_save) {
if (strpos($key_to_save, '#') !== FALSE) {
unset($keys_to_save[$key]);
}
}
$form_state->setStorage(['keys' => $keys_to_save]);
// For now, manually add submit button. Hopefully, by the time D8 is
// released, there will be something like system_settings_form() in D7.
$form['actions']['#type'] = 'container';
$form['actions']['submit'] = ['#type' => 'submit', '#value' => t('Save configuration')];
return $form;
}
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:76,代码来源:HoneypotSettingsController.php
示例18: settingsForm
/**
* {@inheritdoc}
*/
public function settingsForm(array &$form, FormStateInterface $form_state, $has_data)
{
$element = array();
// @todo Inject entity storage once typed-data supports container injection.
// See https://drupal.org/node/2053415 for more details.
$comment_types = CommentType::loadMultiple();
$options = array();
$entity_type = $this->getEntity()->getEntityTypeId();
foreach ($comment_types as $comment_type) {
if ($comment_type->getTargetEntityTypeId() == $entity_type) {
$options[$comment_type->id()] = $comment_type->label();
}
}
$element['comment_type'] = array('#type' => 'select', '#title' => t('Comment type'), '#options' => $options, '#description' => t('Select the Comment type to use for this comment field.'), '#default_value' => $this->getSetting('comment_type'), '#disabled' => $has_data);
return $element;
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:19,代码来源:CommentItem.php
示例19: testCommentFieldCreate
/**
* Tests creating a comment field through the interface.
*/
public function testCommentFieldCreate()
{
// Create user who can administer user fields.
$user = $this->drupalCreateUser(array('administer user fields'));
$this->drupalLogin($user);
// Create comment field in account settings.
$edit = array('new_storage_type' => 'comment', 'label' => 'User comment', 'field_name' => 'user_comment');
$this->drupalPostForm('admin/config/people/accounts/fields/add-field', $edit, 'Save and continue');
// Try to save the comment field without selecting a comment type.
$edit = array();
$this->drupalPostForm('admin/config/people/accounts/fields/user.user.field_user_comment/storage', $edit, t('Save field settings'));
// We should get an error message.
$this->assertText(t('An illegal choice has been detected. Please contact the site administrator.'));
// Create a comment type for users.
$bundle = CommentType::create(array('id' => 'user_comment_type', 'label' => 'user_comment_type', 'description' => '', 'target_entity_type_id' => 'user'));
$bundle->save();
// Select a comment type and try to save again.
$edit = array('settings[comment_type]' => 'user_comment_type');
$this->drupalPostForm('admin/config/people/accounts/fields/user.user.field_user_comment/storage', $edit, t('Save field settings'));
// We shouldn't get an error message.
$this->assertNoText(t('An illegal choice has been detected. Please contact the site administrator.'));
}
开发者ID:HakS,项目名称:drupal8_training,代码行数:25,代码来源:CommentFieldsTest.php
示 |
请发表评论