本文整理汇总了PHP中Drupal\Core\TypedData\TypedDataManager::createDataDefinition方法的典型用法代码示例。如果您正苦于以下问题:PHP TypedDataManager::createDataDefinition方法的具体用法?PHP TypedDataManager::createDataDefinition怎么用?PHP TypedDataManager::createDataDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\TypedData\TypedDataManager
的用法示例。
在下文中一共展示了TypedDataManager::createDataDefinition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDataReferences
/**
* Tests deriving metadata from data references.
*/
public function testDataReferences()
{
$language_reference_definition = DataReferenceDefinition::create('language');
$this->assertTrue($language_reference_definition instanceof DataReferenceDefinitionInterface);
// Test retrieving metadata about the referenced data.
$this->assertEqual($language_reference_definition->getTargetDefinition()->getDataType(), 'language');
// Test using the definition factory.
$language_reference_definition2 = $this->typedDataManager->createDataDefinition('language_reference');
$this->assertTrue($language_reference_definition2 instanceof DataReferenceDefinitionInterface);
$this->assertEqual($language_reference_definition, $language_reference_definition2);
}
示例2: testGetContextValuesContext
/**
* @covers ::getContextValues
*/
public function testGetContextValuesContext()
{
$data_definition = DataDefinition::createFromDataType('integer');
$typed_data = IntegerData::createInstance($data_definition);
$this->typedDataManager->createDataDefinition('integer')->willReturn($data_definition);
$this->typedDataManager->getDefaultConstraints($data_definition)->willReturn([]);
$this->typedDataManager->create($data_definition, 5)->willReturn($typed_data);
$input = ['foo' => ['label' => 'Foo', 'type' => 'integer', 'value' => 5]];
$expected = new Context(new ContextDefinition('integer', 'Foo'), 5);
$actual = $this->staticContext->getContextValues($input)['foo'];
$this->assertEquals($expected, $actual);
}
示例3: getTypedData
/**
* Returns a typed data object.
*
* This helper for quick creation of typed data objects.
*
* @param string $data_type
* The data type to create an object for.
* @param mixed[] $value
* The value to set.
*
* @return \Drupal\Core\TypedData\TypedDataInterface
* The created object.
*/
protected function getTypedData($data_type, $value)
{
$definition = $this->typedDataManager->createDataDefinition($data_type);
$data = $this->typedDataManager->create($definition);
$data->setValue($value);
return $data;
}
示例4: testEntityReferences
/**
* Tests deriving metadata from entity references.
*/
public function testEntityReferences()
{
$reference_definition = DataReferenceDefinition::create('entity');
$this->assertTrue($reference_definition instanceof DataReferenceDefinitionInterface);
// Test retrieving metadata about the referenced data.
$this->assertEqual($reference_definition->getTargetDefinition()->getDataType(), 'entity');
$this->assertTrue($reference_definition->getTargetDefinition() instanceof EntityDataDefinitionInterface);
// Test that the definition factory creates the right definition object.
$reference_definition2 = $this->typedDataManager->createDataDefinition('entity_reference');
$this->assertTrue($reference_definition2 instanceof DataReferenceDefinitionInterface);
$this->assertEqual($reference_definition2, $reference_definition);
}