本文整理汇总了PHP中Drupal\Core\TypedData\TypedDataManager::getDefinition方法的典型用法代码示例。如果您正苦于以下问题:PHP TypedDataManager::getDefinition方法的具体用法?PHP TypedDataManager::getDefinition怎么用?PHP TypedDataManager::getDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\TypedData\TypedDataManager
的用法示例。
在下文中一共展示了TypedDataManager::getDefinition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterPluginDefinitionsByContexts
/**
* {@inheritdoc}
*/
public function filterPluginDefinitionsByContexts(array $contexts, array $definitions)
{
return array_filter($definitions, function ($plugin_definition) use($contexts) {
// If this plugin doesn't need any context, it is available to use.
if (!isset($plugin_definition['context'])) {
return TRUE;
}
// Build an array of requirements out of the contexts specified by the
// plugin definition.
$requirements = array();
/** @var $plugin_context \Drupal\Core\Plugin\Context\ContextDefinitionInterface */
foreach ($plugin_definition['context'] as $context_id => $plugin_context) {
$definition = $this->typedDataManager->getDefinition($plugin_context->getDataType());
$definition['type'] = $plugin_context->getDataType();
// If the plugin specifies additional constraints, add them to the
// constraints defined by the plugin type.
if ($plugin_constraints = $plugin_context->getConstraints()) {
// Ensure the array exists before adding in constraints.
if (!isset($definition['constraints'])) {
$definition['constraints'] = array();
}
$definition['constraints'] += $plugin_constraints;
}
// Assume the requirement is required if unspecified.
if (!isset($definition['required'])) {
$definition['required'] = TRUE;
}
// @todo Use context definition objects after
// https://drupal.org/node/2281635.
$requirements[$context_id] = new DataDefinition($definition);
}
// Check the set of contexts against the requirements.
return $this->checkRequirements($contexts, $requirements);
});
}
示例2: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
$this->moduleHandler->getImplementations('entity_type_build')->willReturn([]);
$this->moduleHandler->alter('entity_type', Argument::type('array'))->willReturn(NULL);
$this->moduleHandler->alter('entity_base_field_info', Argument::type('array'), Argument::any())->willReturn(NULL);
$this->moduleHandler->alter('entity_bundle_field_info', Argument::type('array'), Argument::any(), Argument::type('string'))->willReturn(NULL);
$this->cacheBackend = $this->prophesize(CacheBackendInterface::class);
$this->cacheTagsInvalidator = $this->prophesize(CacheTagsInvalidatorInterface::class);
$language = new Language(['id' => 'en']);
$this->languageManager = $this->prophesize(LanguageManagerInterface::class);
$this->languageManager->getCurrentLanguage()->willReturn($language);
$this->languageManager->getLanguages()->willReturn(['en' => (object) ['id' => 'en']]);
$this->typedDataManager = $this->prophesize(TypedDataManager::class);
$this->typedDataManager->getDefinition('field_item:boolean')->willReturn(['class' => BooleanItem::class]);
$this->eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
$this->keyValueFactory = $this->prophesize(KeyValueFactoryInterface::class);
$this->container = $this->prophesize(ContainerInterface::class);
$this->container->get('cache_tags.invalidator')->willReturn($this->cacheTagsInvalidator->reveal());
$this->container->get('typed_data_manager')->willReturn($this->typedDataManager->reveal());
\Drupal::setContainer($this->container->reveal());
$this->discovery = $this->prophesize(DiscoveryInterface::class);
$translation_manager = $this->prophesize(TranslationInterface::class);
$this->entityManager = new TestEntityManager(new \ArrayObject(), $this->moduleHandler->reveal(), $this->cacheBackend->reveal(), $this->languageManager->reveal(), $translation_manager->reveal(), $this->getClassResolverStub(), $this->typedDataManager->reveal(), $this->keyValueFactory->reveal(), $this->eventDispatcher->reveal());
$this->entityManager->setContainer($this->container->reveal());
$this->entityManager->setDiscovery($this->discovery->reveal());
}