本文整理汇总了PHP中Drupal\Core\Field\FieldTypePluginManagerInterface类的典型用法代码示例。如果您正苦于以下问题:PHP FieldTypePluginManagerInterface类的具体用法?PHP FieldTypePluginManagerInterface怎么用?PHP FieldTypePluginManagerInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FieldTypePluginManagerInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructs a new DisplayOverviewBase.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
* The field type manager.
* @param \Drupal\Component\Plugin\PluginManagerBase $plugin_manager
* The widget or formatter plugin manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
*/
public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager, ConfigFactoryInterface $config_factory)
{
parent::__construct($entity_manager);
$this->fieldTypes = $field_type_manager->getDefinitions();
$this->pluginManager = $plugin_manager;
$this->configFactory = $config_factory;
}
示例2: __construct
/**
* Constructs a new FieldStorageConfigListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
* The 'field type' plugin manager.
*/
public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, EntityTypeBundleInfoInterface $bundle_info_service)
{
parent::__construct($entity_type, $entity_manager->getStorage($entity_type->id()));
$this->entityManager = $entity_manager;
$this->bundles = $bundle_info_service->getAllBundleInfo();
$this->fieldTypeManager = $field_type_manager;
$this->fieldTypes = $this->fieldTypeManager->getDefinitions();
}
示例3: __construct
/**
* Constructs a new FieldStorageConfigListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
* The 'field type' plugin manager.
*/
public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager)
{
parent::__construct($entity_type, $entity_manager->getStorage($entity_type->id()));
$this->entityManager = $entity_manager;
$this->bundles = entity_get_bundles();
$this->fieldTypeManager = $field_type_manager;
$this->fieldTypes = $this->fieldTypeManager->getDefinitions();
}
示例4: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->entityManager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
$this->formatterPluginManager = $this->getMockBuilder('Drupal\\Core\\Field\\FormatterPluginManager')->disableOriginalConstructor()->getMock();
$this->fieldTypePluginManager = $this->getMock('Drupal\\Core\\Field\\FieldTypePluginManagerInterface');
$this->fieldTypePluginManager->expects($this->any())->method('getDefaultStorageSettings')->willReturn([]);
$this->fieldTypePluginManager->expects($this->any())->method('getDefaultFieldSettings')->willReturn([]);
$this->languageManager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
$this->renderer = $this->getMock('Drupal\\Core\\Render\\RendererInterface');
$this->setupExecutableAndView();
$this->setupViewsData();
$this->display = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')->disableOriginalConstructor()->getMock();
$this->container = new ContainerBuilder();
$this->container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
\Drupal::setContainer($this->container);
}
示例5: __construct
/**
* Constructs a new EntityDisplayFormBase.
*
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
* The field type manager.
* @param \Drupal\Component\Plugin\PluginManagerBase $plugin_manager
* The widget or formatter plugin manager.
*/
public function __construct(FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager)
{
$this->fieldTypes = $field_type_manager->getDefinitions();
$this->pluginManager = $plugin_manager;
}
示例6: mapToStorageRecord
/**
* {@inheritdoc}
*/
protected function mapToStorageRecord(EntityInterface $entity)
{
$record = parent::mapToStorageRecord($entity);
$class = $this->fieldTypeManager->getPluginClass($record['field_type']);
$record['settings'] = $class::fieldSettingsToConfigData($record['settings']);
return $record;
}
示例7: getDerivativeDefinitions
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition)
{
foreach ($this->fieldTypePluginManager->getDefinitions() as $plugin_id => $definition) {
$definition['definition_class'] = '\\Drupal\\Core\\Field\\TypedData\\FieldItemDataDefinition';
$definition['list_definition_class'] = '\\Drupal\\Core\\Field\\FieldDefinition';
$this->derivatives[$plugin_id] = $definition;
}
return $this->derivatives;
}
示例8: calculateDependencies
/**
* {@inheritdoc}
*/
public function calculateDependencies()
{
$this->dependencies = parent::calculateDependencies();
// Add a dependency on the module that provides the field type using the
// source plugin configuration.
$source_configuration = $this->migration->get('source');
if (isset($source_configuration['constants']['type'])) {
$field_type = $this->fieldTypePluginManager->getDefinition($source_configuration['constants']['type']);
$this->addDependency('module', $field_type['provider']);
}
return $this->dependencies;
}
示例9: processStubRow
/**
* Populates as much of the stub row as possible.
*
* @param \Drupal\migrate\Row $row
* The row of data.
*/
protected function processStubRow(Row $row)
{
$bundle_key = $this->getKey('bundle');
if ($bundle_key && empty($row->getDestinationProperty($bundle_key))) {
if (empty($this->bundles)) {
throw new MigrateException('Stubbing failed, no bundles available for entity type: ' . $this->storage->getEntityTypeId());
}
$row->setDestinationProperty($bundle_key, reset($this->bundles));
}
// Populate any required fields not already populated.
$fields = $this->entityManager->getFieldDefinitions($this->storage->getEntityTypeId(), $bundle_key);
foreach ($fields as $field_name => $field_definition) {
if ($field_definition->isRequired() && is_null($row->getDestinationProperty($field_name))) {
// Use the configured default value for this specific field, if any.
if ($default_value = $field_definition->getDefaultValueLiteral()) {
$values[] = $default_value;
} else {
// Otherwise, ask the field type to generate a sample value.
$field_type = $field_definition->getType();
/** @var \Drupal\Core\Field\FieldItemInterface $field_type_class */
$field_type_class = $this->fieldTypeManager->getPluginClass($field_definition->getType());
$values = $field_type_class::generateSampleValue($field_definition);
if (is_null($values)) {
// Handle failure to generate a sample value.
throw new MigrateException('Stubbing failed, unable to generate value for field ' . $field_name);
}
}
$row->setDestinationProperty($field_name, $values);
}
}
}
示例10: getExistingFieldOptions
/**
* Returns an array of existing fields to be added to a bundle.
*
* @return array
* An array of existing fields keyed by field name.
*/
protected function getExistingFieldOptions()
{
$options = array();
// Collect candidate field instances: all instances of fields for this
// entity type that are not already present in the current bundle.
$field_map = \Drupal::entityManager()->getFieldMap();
$instance_ids = array();
if (!empty($field_map[$this->entity_type])) {
foreach ($field_map[$this->entity_type] as $field_name => $data) {
if (!in_array($this->bundle, $data['bundles'])) {
$bundle = reset($data['bundles']);
$instance_ids[] = $this->entity_type . '.' . $bundle . '.' . $field_name;
}
}
}
// Load the instances and build the list of options.
if ($instance_ids) {
$field_types = $this->fieldTypeManager->getDefinitions();
$instances = $this->entityManager->getStorage('field_instance_config')->loadMultiple($instance_ids);
foreach ($instances as $instance) {
// Do not show:
// - locked fields,
// - fields that should not be added via user interface.
$field_type = $instance->getType();
$field_storage = $instance->getFieldStorageDefinition();
if (empty($field_storage->locked) && empty($field_types[$field_type]['no_ui'])) {
$options[$instance->getName()] = array('type' => $field_type, 'type_label' => $field_types[$field_type]['label'], 'field' => $instance->getName(), 'label' => $instance->getLabel());
}
}
}
return $options;
}
示例11: testOnDependencyRemoval
/**
* @covers ::onDependencyRemoval
*/
public function testOnDependencyRemoval()
{
$this->fieldTypePluginManager->expects($this->any())->method('getDefinition')->with('test_field')->willReturn(['class' => '\\Drupal\\Tests\\field\\Unit\\DependencyFieldItem']);
$field = new FieldConfig(['field_name' => $this->fieldStorage->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle', 'field_type' => 'test_field', 'dependencies' => ['module' => ['fruiter']], 'third_party_settings' => ['fruiter' => ['fruit' => 'apple']]]);
$changed = $field->onDependencyRemoval(['module' => ['fruiter']]);
$this->assertTrue($changed);
}
示例12: testCalculateDependencies
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependencies()
{
// Create a mock entity type for FieldStorageConfig.
$fieldStorageConfigentityType = $this->getMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface');
$fieldStorageConfigentityType->expects($this->any())->method('getProvider')->will($this->returnValue('field'));
// Create a mock entity type to attach the field to.
$attached_entity_type_id = $this->randomMachineName();
$attached_entity_type = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$attached_entity_type->expects($this->any())->method('getProvider')->will($this->returnValue('entity_provider_module'));
// Get definition is called three times. Twice in
// ConfigEntityBase::addDependency() to get the provider of the field config
// entity type and once in FieldStorageConfig::calculateDependencies() to
// get the provider of the entity type that field is attached to.
$this->entityManager->expects($this->any())->method('getDefinition')->willReturnMap([['field_storage_config', TRUE, $fieldStorageConfigentityType], [$attached_entity_type_id, TRUE, $attached_entity_type]]);
$this->fieldTypeManager->expects($this->atLeastOnce())->method('getDefinition')->with('test_field_type', FALSE)->willReturn(['class' => TestFieldType::class]);
$field_storage = new FieldStorageConfig(['entity_type' => $attached_entity_type_id, 'field_name' => 'test_field', 'type' => 'test_field_type', 'module' => 'test_module']);
$dependencies = $field_storage->calculateDependencies()->getDependencies();
$this->assertEquals(['entity_provider_module', 'entity_test', 'test_module'], $dependencies['module']);
$this->assertEquals(['stark'], $dependencies['theme']);
}
示例13: testCalculateDependenciesIncorrectBundle
/**
* Test that invalid bundles are handled.
*
* @expectedException \LogicException
* @expectedExceptionMessage Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists.
*/
public function testCalculateDependenciesIncorrectBundle()
{
$storage = $this->getMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
$storage->expects($this->any())->method('load')->with('test_bundle_not_exists')->will($this->returnValue(NULL));
$this->entityManager->expects($this->any())->method('getStorage')->with('bundle_entity_type')->will($this->returnValue($storage));
$target_entity_type = new EntityType(array('id' => 'test_entity_type', 'bundle_entity_type' => 'bundle_entity_type'));
$this->entityManager->expects($this->at(0))->method('getDefinition')->with($this->entityTypeId)->willReturn($this->entityType);
$this->entityManager->expects($this->at(1))->method('getDefinition')->with($this->entityTypeId)->willReturn($this->entityType);
$this->entityManager->expects($this->at(2))->method('getDefinition')->with($this->entityTypeId)->willReturn($this->entityType);
$this->entityManager->expects($this->at(3))->method('getDefinition')->with('test_entity_type')->willReturn($target_entity_type);
$this->fieldTypePluginManager->expects($this->any())->method('getDefinition')->with('test_field')->willReturn(['provider' => 'test_module', 'config_dependencies' => ['module' => ['test_module2']], 'class' => '\\Drupal\\Tests\\field\\Unit\\DependencyFieldItem']);
$field = new FieldConfig(array('field_name' => $this->fieldStorage->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle_not_exists', 'field_type' => 'test_field'), $this->entityTypeId);
$field->calculateDependencies();
}
示例14: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $field_config)
{
/** @var \Drupal\field\FieldConfigInterface $field_config */
$field_storage = $field_config->getFieldStorageDefinition();
$route_parameters = array('field_config' => $field_config->id()) + FieldUI::getRouteBundleParameter($this->entityManager->getDefinition($this->targetEntityTypeId), $this->targetBundle);
$row = array('id' => Html::getClass($field_config->getName()), 'data' => array('label' => $field_config->getLabel(), 'field_name' => $field_config->getName(), 'field_type' => array('data' => array('#type' => 'link', '#title' => $this->fieldTypeManager->getDefinitions()[$field_storage->getType()]['label'], '#url' => Url::fromRoute("entity.field_config.{$this->targetEntityTypeId}_storage_edit_form", $route_parameters), '#options' => array('attributes' => array('title' => $this->t('Edit field settings.')))))));
// Add the operations.
$row['data'] = $row['data'] + parent::buildRow($field_config);
if ($field_storage->isLocked()) {
$row['data']['operations'] = array('data' => array('#markup' => $this->t('Locked')));
$row['class'][] = 'menu-disabled';
}
return $row;
}
示例15: getExistingFieldStorageOptions
/**
* Returns an array of existing field storages that can be added to a bundle.
*
* @return array
* An array of existing field storages keyed by name.
*/
protected function getExistingFieldStorageOptions()
{
$options = array();
// Load the field_storages and build the list of options.
$field_types = $this->fieldTypePluginManager->getDefinitions();
foreach ($this->entityManager->getFieldStorageDefinitions($this->entityTypeId) as $field_name => $field_storage) {
// Do not show:
// - non-configurable field storages,
// - locked field storages,
// - field storages that should not be added via user interface,
// - field storages that already have a field in the bundle.
$field_type = $field_storage->getType();
if ($field_storage instanceof FieldStorageConfigInterface && !$field_storage->isLocked() && empty($field_types[$field_type]['no_ui']) && !in_array($this->bundle, $field_storage->getBundles(), TRUE)) {
$options[$field_name] = $this->t('@type: @field', array('@type' => $field_types[$field_type]['label'], '@field' => $field_name));
}
}
asort($options);
return $options;
}