本文整理汇总了PHP中Drupal\comment\Entity\CommentType类的典型用法代码示例。如果您正苦于以下问题:PHP CommentType类的具体用法?PHP CommentType怎么用?PHP CommentType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommentType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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']);
}
示例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);
}
示例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());
}
示例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();
}
示例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());
}
示例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();
}
示例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();
}
示例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.');
}
}
示例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();
}
示例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'));
}
示例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());
}
示例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');
}
示例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())));
}
示例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();
}
示例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;
}