本文整理汇总了PHP中Drupal\node\NodeInterface::getTypedData方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface::getTypedData方法的具体用法?PHP NodeInterface::getTypedData怎么用?PHP NodeInterface::getTypedData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\node\NodeInterface
的用法示例。
在下文中一共展示了NodeInterface::getTypedData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBubbleableMetadata
/**
* @cover replacePlaceHolders
*/
public function testBubbleableMetadata()
{
// Make sure the bubbleable metadata added by the fetcher is properly passed
// though.
$bubbleable_metadata = new BubbleableMetadata();
// Save the node, so it gets a cache tag.
$this->node->save();
$this->placeholderResolver->replacePlaceHolders('test {{node.field_integer}}', ['node' => $this->node->getTypedData()], $bubbleable_metadata);
$expected = ['node:' . $this->node->id()];
$this->assertEquals($expected, $bubbleable_metadata->getCacheTags());
// Ensure cache tags of filters are added in.
$bubbleable_metadata = new BubbleableMetadata();
$this->placeholderResolver->replacePlaceHolders("test {{ node.created.value | format_date('medium') }}", ['node' => $this->node->getTypedData()], $bubbleable_metadata);
$expected = Cache::mergeTags(['node:' . $this->node->id()], DateFormat::load('medium')->getCacheTags());
$this->assertEquals($expected, $bubbleable_metadata->getCacheTags());
}
示例2: testBubbleableMetadata
/**
* @cover fetchDataByPropertyPath
*/
public function testBubbleableMetadata()
{
$this->node->field_integer->setValue([]);
// Save the node, so that it gets an ID and it has a cache tag.
$this->node->save();
// Also add a user for testing cache tags of references.
$user = $this->entityTypeManager->getStorage('user')->create(['name' => 'test', 'type' => 'user']);
$user->save();
$this->node->uid->entity = $user;
$bubbleable_metadata = new BubbleableMetadata();
$this->dataFetcher->fetchDataByPropertyPath($this->node->getTypedData(), 'title.value', $bubbleable_metadata)->getValue();
$expected = ['node:' . $this->node->id()];
$this->assertEquals($expected, $bubbleable_metadata->getCacheTags());
// Test cache tags of references are added correctly.
$this->dataFetcher->fetchDataByPropertyPath($this->node->getTypedData(), 'uid.entity.name', $bubbleable_metadata)->getValue();
$expected = ['node:' . $this->node->id(), 'user:' . $user->id()];
$this->assertEquals($expected, $bubbleable_metadata->getCacheTags());
}