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