本文整理匯總了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);
}