本文整理汇总了PHP中Drupal\entity_test\Entity\EntityTest::save方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityTest::save方法的具体用法?PHP EntityTest::save怎么用?PHP EntityTest::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\entity_test\Entity\EntityTest
的用法示例。
在下文中一共展示了EntityTest::save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assertSavedFieldItemValue
/**
* Checks that the saved field item value matches the expected one.
*
* @param \Drupal\entity_test\Entity\EntityTest $entity
* The test entity.
* @param $expected_value
* The expected field item value.
*
* @return bool
* TRUE if the item value matches expectations, FALSE otherwise.
*/
protected function assertSavedFieldItemValue(EntityTest $entity, $expected_value)
{
$entity->setNewRevision(TRUE);
$entity->save();
$base_field_expected_value = str_replace($this->fieldName, 'field_test_item', $expected_value);
$result = $this->assertEqual($entity->field_test_item->value, $base_field_expected_value);
$result = $result && $this->assertEqual($entity->{$this->fieldName}->value, $expected_value);
$entity = $this->reloadEntity($entity);
$result = $result && $this->assertEqual($entity->field_test_item->value, $base_field_expected_value);
$result = $result && $this->assertEqual($entity->{$this->fieldName}->value, $expected_value);
return $result;
}
示例2: testCommentEntity
/**
* Test that comments correctly invalidate the cache tag of their host entity.
*/
public function testCommentEntity()
{
$this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'MISS');
$this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'HIT');
// Create a "Hippopotamus" comment.
$this->entityTestHippopotamidae = EntityTest::create(array('name' => 'Hippopotamus', 'type' => 'bar'));
$this->entityTestHippopotamidae->save();
$this->verifyPageCache($this->entityTestHippopotamidae->urlInfo(), 'MISS');
$this->verifyPageCache($this->entityTestHippopotamidae->urlInfo(), 'HIT');
$hippo_comment = Comment::create(array('subject' => 'Hippopotamus', 'comment_body' => array('value' => 'The common hippopotamus (Hippopotamus amphibius), or hippo, is a large, mostly herbivorous mammal in sub-Saharan Africa', 'format' => 'plain_text'), 'entity_id' => $this->entityTestHippopotamidae->id(), 'entity_type' => 'entity_test', 'field_name' => 'comment', 'status' => CommentInterface::PUBLISHED));
$hippo_comment->save();
// Ensure that a new comment only invalidates the commented entity.
$this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'HIT');
$this->verifyPageCache($this->entityTestHippopotamidae->urlInfo(), 'MISS');
$this->assertText($hippo_comment->getSubject());
// Ensure that updating an existing comment only invalidates the commented
// entity.
$this->entity->save();
$this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'MISS');
$this->verifyPageCache($this->entityTestHippopotamidae->urlInfo(), 'HIT');
}
示例3: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->drupalPlaceBlock('system_breadcrumb_block');
// Create a bundle for entity_test.
entity_test_create_bundle('entity_test', 'Entity Test', 'entity_test');
entity_create('comment_type', array('id' => 'comment', 'label' => 'Comment settings', 'description' => 'Comment settings', 'target_entity_type_id' => 'entity_test'))->save();
// Create comment field on entity_test bundle.
$this->addDefaultCommentField('entity_test', 'entity_test');
// Verify that bundles are defined correctly.
$bundles = \Drupal::entityManager()->getBundleInfo('comment');
$this->assertEqual($bundles['comment']['label'], 'Comment settings');
// Create test user.
$this->adminUser = $this->drupalCreateUser(array('administer comments', 'skip comment approval', 'post comments', 'access comments', 'view test entity', 'administer entity_test content'));
// Enable anonymous and authenticated user comments.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access comments', 'post comments', 'skip comment approval'));
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array('access comments', 'post comments', 'skip comment approval'));
// Create a test entity.
$random_label = $this->randomMachineName();
$data = array('type' => 'entity_test', 'name' => $random_label);
$this->entity = entity_create('entity_test', $data);
$this->entity->save();
}
示例4: setUp
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema($this->entityTypeId);
$this->installEntitySchema('filter_format');
// Setup a field and an entity display.
EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
])->save();
FieldStorageConfig::create([
'field_name' => $this->fieldName,
'entity_type' => $this->entityTypeId,
'type' => 'text',
])->save();
FieldConfig::create([
'entity_type' => $this->entityTypeId,
'field_name' => $this->fieldName,
'bundle' => $this->entityTypeId,
])->save();
$this->entityViewDisplay = EntityViewDisplay::load('entity_test.entity_test.default');
// Create a test entity with a test value.
$this->entity = EntityTest::create();
$this->entity->{$this->fieldName}->value = 'lorem ipsum';
$this->entity->save();
// Set the default filter format.
FilterFormat::create([
'format' => 'test_format',
'name' => $this->randomMachineName(),
])->save();
$this->container->get('config.factory')
->getEditable('filter.settings')
->set('fallback_format', 'test_format')
->save();
}