Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes

This commit is contained in:
Pantheon Automation 2016-04-20 09:56:34 -07:00 committed by Greg Anderson
parent b11a755ba8
commit c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions

View file

@ -1,71 +0,0 @@
migrate.source.d6_field_instance_per_form_display:
type: migrate_source_sql
label: 'Drupal 6 field instance form display'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d6_field:
type: migrate_source_sql
label: 'Drupal 6 field'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d6_field_formatter_settings:
type: migrate_source_sql
label: 'Drupal 6 field formatter settings'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d6_field_instance:
type: migrate_source_sql
label: 'Drupal 6 field instance'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d6_field_instance_per_view_mode:
type: migrate_source_sql
label: 'Drupal 6 field formatter'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d7_field:
type: migrate_source_sql
label: 'Drupal 7 field'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d7_field_instance:
type: migrate_source_sql
label: 'Drupal 7 field instance'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d7_field_instance_per_form_display:
type: migrate_source_sql
label: 'Drupal 7 field instance per form display'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d7_field_instance_per_view_mode:
type: migrate_source_sql
label: 'Drupal 7 field instance per view mode'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'

View file

@ -1,5 +1,10 @@
<?php
/**
* @file
* Field API documentation.
*/
/**
* @addtogroup hooks
* @{

View file

@ -68,3 +68,39 @@ function field_update_8002() {
}
}
}
/**
* Populate the new 'auto_create_bundle' setting for entity reference fields.
*/
function field_update_8003() {
$config = \Drupal::configFactory();
/** @var \Drupal\Core\Field\FieldTypePluginManager $field_type_manager */
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
// Iterate over all fields.
foreach ($config->listAll('field.field.') as $field_id) {
$field = $config->getEditable($field_id);
$class = $field_type_manager->getPluginClass($field->get('field_type'));
// Deal only with entity reference fields and descendants.
if ($class == EntityReferenceItem::class || is_subclass_of($class, EntityReferenceItem::class)) {
$handler_settings = $field->get('settings.handler_settings');
if (is_array($handler_settings) && !empty($handler_settings['auto_create'])) {
// If the field can reference multiple bundles, pick the first one
// available in order to replicate the previous behavior.
if (is_array($handler_settings['target_bundles']) && count($handler_settings['target_bundles']) > 1) {
$handler_settings['auto_create_bundle'] = reset($handler_settings['target_bundles']);
}
// Otherwise, we don't know which bundle to use for auto-creation so we
// have to disable the functionality completely.
elseif (!$handler_settings['target_bundles']) {
$handler_settings['auto_create'] = FALSE;
$handler_settings['auto_create_bundle'] = NULL;
}
}
$field->set('settings.handler_settings', $handler_settings)->save(TRUE);
}
}
}

View file

@ -250,7 +250,7 @@ function field_entity_bundle_delete($entity_type_id, $bundle) {
$field_config->save();
// In case we deleted the only target bundle allowed by the field we
// have to log a warning message because the field will not function
// have to log a critical message because the field will not function
// correctly anymore.
if ($handler_settings['target_bundles'] === []) {
\Drupal::logger('entity_reference')->critical('The %target_bundle bundle (entity type: %target_entity_type) was deleted. As a result, the %field_name entity reference field (entity_type: %entity_type, bundle: %bundle) no longer has any valid bundle it can reference. The field is not working correctly anymore and has to be adjusted.', [
@ -292,7 +292,9 @@ function _field_create_entity_from_ids($ids) {
if (isset($ids->bundle) && $bundle_key = $entity_type->getKey('bundle')) {
$id_properties[$bundle_key] = $ids->bundle;
}
return entity_create($ids->entity_type, $id_properties);
return \Drupal::entityTypeManager()
->getStorage($ids->entity_type)
->create($id_properties);
}
/**

View file

@ -3,5 +3,5 @@ services:
class: Drupal\field\FieldUninstallValidator
tags:
- { name: module_install.uninstall_validator }
arguments: ['@entity.manager', '@string_translation']
arguments: ['@entity_type.manager', '@string_translation', '@plugin.manager.field.field_type']
lazy: true

View file

@ -2,9 +2,8 @@ id: d6_field
label: Field configuration
migration_tags:
- Drupal 6
builder:
plugin: d6_cck_migration
cck_plugin_method: processField
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processField
source:
plugin: d6_field
constants:

View file

@ -2,9 +2,8 @@ id: d6_field_formatter_settings
label: Field formatter configuration
migration_tags:
- Drupal 6
builder:
plugin: d6_cck_migration
cck_plugin_method: processFieldFormatter
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldFormatter
source:
plugin: d6_field_instance_per_view_mode
constants:

View file

@ -2,9 +2,8 @@ id: d6_field_instance
label: Field instance configuration
migration_tags:
- Drupal 6
builder:
plugin: d6_cck_migration
cck_plugin_method: processFieldInstance
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldInstance
source:
plugin: d6_field_instance
constants:

View file

@ -2,9 +2,8 @@ id: d6_field_instance_widget_settings
label: Field instance widget configuration
migration_tags:
- Drupal 6
builder:
plugin: d6_cck_migration
cck_plugin_method: processFieldWidget
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldWidget
source:
plugin: d6_field_instance_per_form_display
constants:

0
core/modules/field/migration_templates/d7_field.yml Executable file → Normal file
View file

View file

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\ConfigImporterFieldPurger.
*/
namespace Drupal\field;
use Drupal\Core\Config\ConfigImporter;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Entity\FieldConfig.
*/
namespace Drupal\field\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
@ -72,7 +67,7 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface {
* Constructs a FieldConfig object.
*
* In most cases, Field entities are created via
* entity_create('field_config', $values), where $values is the same
* FieldConfig::create($values), where $values is the same
* parameter as in this constructor.
*
* @param array $values

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Entity\FieldStorageConfig.
*/
namespace Drupal\field\Entity;
use Drupal\Component\Utility\Unicode;
@ -238,7 +233,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
* - type: required.
*
* In most cases, Field entities are created via
* entity_create('field_storage_config', $values)), where $values is the same
* FieldStorageConfig::create($values)), where $values is the same
* parameter as in this constructor.
*
* @see entity_create()
@ -649,7 +644,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
// If the field item class implements the interface, create an orphaned
// runtime item object, so that it can be used as the options provider
// without modifying the entity being worked on.
if (is_subclass_of($this->getFieldItemClass(), '\Drupal\Core\TypedData\OptionsProviderInterface')) {
if (is_subclass_of($this->getFieldItemClass(), OptionsProviderInterface::class)) {
$items = $entity->get($this->getName());
return \Drupal::service('plugin.manager.field.field_type')->createFieldItem($items, 0);
}

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\FieldConfigAccessControlHandler.
*/
namespace Drupal\field;
use Drupal\Core\Access\AccessResult;
@ -26,10 +21,10 @@ class FieldConfigAccessControlHandler extends EntityAccessControlHandler {
if ($operation == 'delete') {
$field_storage_entity = $entity->getFieldStorageDefinition();
if ($field_storage_entity->isLocked()) {
return AccessResult::forbidden()->cacheUntilEntityChanges($field_storage_entity);
return AccessResult::forbidden()->addCacheableDependency($field_storage_entity);
}
else {
return AccessResult::allowedIfHasPermission($account, 'administer ' . $entity->getTargetEntityTypeId() . ' fields')->cacheUntilEntityChanges($field_storage_entity);
return AccessResult::allowedIfHasPermission($account, 'administer ' . $entity->getTargetEntityTypeId() . ' fields')->addCacheableDependency($field_storage_entity);
}
}
return AccessResult::allowedIfHasPermission($account, 'administer ' . $entity->getTargetEntityTypeId() . ' fields');

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\FieldConfigInterface.
*/
namespace Drupal\field;
use Drupal\Core\Config\Entity\ConfigEntityInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\FieldConfigStorage.
*/
namespace Drupal\field;
use Drupal\Core\Config\Config;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\FieldStorageConfigInterface.
*/
namespace Drupal\field;
use Drupal\Core\Config\Entity\ConfigEntityInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\FieldStorageConfigStorage.
*/
namespace Drupal\field;
use Drupal\Component\Uuid\UuidInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\FieldStorageConfigUpdateForbiddenException.
*/
namespace Drupal\field;
use Drupal\Core\Field\FieldException;

View file

@ -1,14 +1,10 @@
<?php
/**
* @file
* Contains \Drupal\field\FieldUninstallValidator.
*/
namespace Drupal\field;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleUninstallValidatorInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
@ -26,17 +22,27 @@ class FieldUninstallValidator implements ModuleUninstallValidatorInterface {
*/
protected $fieldStorageConfigStorage;
/**
* The field type plugin manager.
*
* @var \Drupal\Core\Field\FieldTypePluginManagerInterface
*/
protected $fieldTypeManager;
/**
* Constructs a new FieldUninstallValidator.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
* The field type plugin manager.
*/
public function __construct(EntityManagerInterface $entity_manager, TranslationInterface $string_translation) {
$this->fieldStorageConfigStorage = $entity_manager->getStorage('field_storage_config');
public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation, FieldTypePluginManagerInterface $field_type_manager) {
$this->fieldStorageConfigStorage = $entity_type_manager->getStorage('field_storage_config');
$this->stringTranslation = $string_translation;
$this->fieldTypeManager = $field_type_manager;
}
/**
@ -47,15 +53,17 @@ class FieldUninstallValidator implements ModuleUninstallValidatorInterface {
if ($field_storages = $this->getFieldStoragesByModule($module)) {
// Provide an explanation message (only mention pending deletions if there
// remain no actual, non-deleted fields.)
$non_deleted = FALSE;
$fields_in_use = [];
foreach ($field_storages as $field_storage) {
if (!$field_storage->isDeleted()) {
$non_deleted = TRUE;
break;
$fields_in_use[$field_storage->getType()][] = $field_storage->getLabel();
}
}
if ($non_deleted) {
$reasons[] = $this->t('Fields type(s) in use');
if (!empty($fields_in_use)) {
foreach ($fields_in_use as $field_type => $field_storages) {
$field_type_label = $this->getFieldTypeLabel($field_type);
$reasons[] = $this->formatPlural(count($fields_in_use[$field_type]), 'The %field_type_label field type is used in the following field: @fields', 'The %field_type_label field type is used in the following fields: @fields', ['%field_type_label' => $field_type_label, '@fields' => implode(', ', $field_storages)]);
}
}
else {
$reasons[] = $this->t('Fields pending deletion');
@ -77,4 +85,18 @@ class FieldUninstallValidator implements ModuleUninstallValidatorInterface {
return $this->fieldStorageConfigStorage->loadByProperties(['module' => $module, 'include_deleted' => TRUE]);
}
/**
* Returns the label for a specified field type.
*
* @param string $field_type
* The field type.
*
* @return string
* The field type label.
*/
protected function getFieldTypeLabel($field_type) {
return $this->fieldTypeManager->getDefinitions()[$field_type]['label'];
}
}

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldFormatterSettingsDefaults.
*/
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\ProcessPluginBase;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldInstanceDefaults.
*/
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\MigrateExecutableInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldInstanceSettings.
*/
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\MigrateExecutableInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldInstanceWidgetSettings.
*/
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\MigrateExecutableInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldSettings.
*/
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\MigrateExecutableInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldType.
*/
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldTypeDefaults.
*/
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\MigrateException;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\process\d7\FieldInstanceDefaults.
*/
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\migrate\MigrateExecutableInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\process\d7\FieldInstanceSettings.
*/
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\migrate\MigrateExecutableInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\process\d7\FieldSettings.
*/
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\migrate\MigrateExecutableInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d6\Field.
*/
namespace Drupal\field\Plugin\migrate\source\d6;
use Drupal\migrate\Row;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d6\FieldInstance.
*/
namespace Drupal\field\Plugin\migrate\source\d6;
use Drupal\migrate\Row;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d6\FieldInstancePerFormDisplay.
*/
namespace Drupal\field\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d6\FieldInstancePerViewMode.
*/
namespace Drupal\field\Plugin\migrate\source\d6;
use Drupal\node\Plugin\migrate\source\d6\ViewModeBase;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d7\Field.
*/
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate\Row;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d7\FieldInstance.
*/
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
@ -15,6 +10,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
*
* @MigrateSource(
* id = "d7_field_instance",
* source_provider = "field"
* )
*/
class FieldInstance extends DrupalSqlBase {

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d7\FieldInstancePerFormDisplay.
*/
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate\Row;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d7\FieldInstancePerViewMode.
*/
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d7\ViewMode.
*/
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;

View file

@ -1,9 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\ProxyClass\FieldUninstallValidator.
*/
// @codingStandardsIgnoreFile
/**
* This file was generated via php core/scripts/generate-proxy-class.php 'Drupal\field\FieldUninstallValidator' "core/modules/field/src".

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Boolean\BooleanFieldTest.
*/
namespace Drupal\field\Tests\Boolean;
use Drupal\Component\Utility\Unicode;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Boolean\BooleanFormatterSettingsTest.
*/
namespace Drupal\field\Tests\Boolean;
use Drupal\Component\Utility\Unicode;
@ -125,6 +120,12 @@ class BooleanFormatterSettingsTest extends WebTestBase {
}
$this->assertText(SafeMarkup::format($default, array('@on' => $values[0], '@off' => $values[1])));
}
foreach ($settings as $values) {
$this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display');
$result = $this->xpath('//div[contains(@class, :class) and contains(text(), :text)]', [':class' => 'field-plugin-summary', ':text' => 'Display: TRUE / FALSE']);
$this->assertEqual(count($result), 1, "Boolean formatter settings summary exist.");
}
}
}

View file

@ -1,14 +1,11 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Email\EmailFieldTest.
*/
namespace Drupal\field\Tests\Email;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests email field functionality.
@ -54,16 +51,16 @@ class EmailFieldTest extends WebTestBase {
function testEmailField() {
// Create a field with settings to validate.
$field_name = Unicode::strtolower($this->randomMachineName());
$this->fieldStorage = entity_create('field_storage_config', array(
$this->fieldStorage = FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'email',
));
$this->fieldStorage->save();
$this->field = entity_create('field_config', array(
$this->field = FieldConfig::create([
'field_storage' => $this->fieldStorage,
'bundle' => 'entity_test',
));
]);
$this->field->save();
// Create a form display for the default form mode.

View file

@ -1,13 +1,9 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\EntityReference\EntityReferenceAdminTest.
*/
namespace Drupal\field\Tests\EntityReference;
use Drupal\Core\Entity\Entity;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\node\Entity\Node;
@ -315,7 +311,7 @@ class EntityReferenceAdminTest extends WebTestBase {
// Tests adding default values to autocomplete widgets.
Vocabulary::create(array('vid' => 'tags', 'name' => 'tags'))->save();
$taxonomy_term_field_name = $this->createEntityReferenceField('taxonomy_term', 'tags');
$taxonomy_term_field_name = $this->createEntityReferenceField('taxonomy_term', ['tags']);
$field_path = 'node.' . $this->type . '.field_' . $taxonomy_term_field_name;
$this->drupalGet($bundle_path . '/fields/' . $field_path . '/storage');
$edit = [
@ -348,13 +344,13 @@ class EntityReferenceAdminTest extends WebTestBase {
Vocabulary::create(array('vid' => 'tags', 'name' => 'tags'))->save();
// Create entity reference field with taxonomy term as a target.
$taxonomy_term_field_name = $this->createEntityReferenceField('taxonomy_term', 'tags');
$taxonomy_term_field_name = $this->createEntityReferenceField('taxonomy_term', ['tags']);
// Create entity reference field with user as a target.
$user_field_name = $this->createEntityReferenceField('user');
// Create entity reference field with node as a target.
$node_field_name = $this->createEntityReferenceField('node', $this->type);
$node_field_name = $this->createEntityReferenceField('node', [$this->type]);
// Create entity reference field with date format as a target.
$date_format_field_name = $this->createEntityReferenceField('date_format');
@ -402,18 +398,79 @@ class EntityReferenceAdminTest extends WebTestBase {
));
}
/**
* Tests field settings for an entity reference field when the field has
* multiple target bundles and is set to auto-create the target entity.
*/
public function testMultipleTargetBundles() {
/** @var \Drupal\taxonomy\Entity\Vocabulary[] $vocabularies */
$vocabularies = [];
for ($i = 0; $i < 2; $i++) {
$vid = Unicode::strtolower($this->randomMachineName());
$vocabularies[$i] = Vocabulary::create([
'name' => $this->randomString(),
'vid' => $vid,
]);
$vocabularies[$i]->save();
}
// Create a new field pointing to the first vocabulary.
$field_name = $this->createEntityReferenceField('taxonomy_term', [$vocabularies[0]->id()]);
$field_name = "field_$field_name";
$field_id = 'node.' . $this->type . '.' . $field_name;
$path = 'admin/structure/types/manage/' . $this->type . '/fields/' . $field_id;
$this->drupalGet($path);
// Expect that there's no 'auto_create_bundle' selected.
$this->assertNoFieldByName('settings[handler_settings][auto_create_bundle]');
$edit = [
'settings[handler_settings][target_bundles][' . $vocabularies[1]->id() . ']' => TRUE,
];
// Enable the second vocabulary as a target bundle.
$this->drupalPostAjaxForm($path, $edit, key($edit));
// Expect a select element with the two vocabularies as options.
$this->assertFieldByXPath("//select[@name='settings[handler_settings][auto_create_bundle]']/option[@value='" . $vocabularies[0]->id() . "']");
$this->assertFieldByXPath("//select[@name='settings[handler_settings][auto_create_bundle]']/option[@value='" . $vocabularies[1]->id() . "']");
$edit = [
'settings[handler_settings][auto_create]' => TRUE,
'settings[handler_settings][auto_create_bundle]' => $vocabularies[1]->id(),
];
$this->drupalPostForm(NULL, $edit, t('Save settings'));
/** @var \Drupal\field\Entity\FieldConfig $field_config */
$field_config = FieldConfig::load($field_id);
// Expect that the target bundle has been saved in the backend.
$this->assertEqual($field_config->getSetting('handler_settings')['auto_create_bundle'], $vocabularies[1]->id());
// Delete the other bundle. Field config should not be affected.
$vocabularies[0]->delete();
$field_config = FieldConfig::load($field_id);
$this->assertTrue($field_config->getSetting('handler_settings')['auto_create']);
$this->assertIdentical($field_config->getSetting('handler_settings')['auto_create_bundle'], $vocabularies[1]->id());
// Delete the bundle set for entity auto-creation. Auto-created settings
// should be reset (no auto-creation).
$vocabularies[1]->delete();
$field_config = FieldConfig::load($field_id);
$this->assertFalse($field_config->getSetting('handler_settings')['auto_create']);
$this->assertFalse(isset($field_config->getSetting('handler_settings')['auto_create_bundle']));
}
/**
* Creates a new Entity Reference fields with a given target type.
*
* @param $target_type
* @param string $target_type
* The name of the target type
* @param $bundle
* Name of the bundle
* Default = NULL
* @param string[] $bundles
* A list of bundle IDs. Defaults to [].
*
* @return string
* Returns the generated field name
*/
public function createEntityReferenceField($target_type, $bundle = NULL) {
protected function createEntityReferenceField($target_type, $bundles = []) {
// Generates a bundle path for the newly created content type.
$bundle_path = 'admin/structure/types/manage/' . $this->type;
@ -422,7 +479,7 @@ class EntityReferenceAdminTest extends WebTestBase {
$storage_edit = $field_edit = array();
$storage_edit['settings[target_type]'] = $target_type;
if ($bundle) {
foreach ($bundles as $bundle) {
$field_edit['settings[handler_settings][target_bundles][' . $bundle . ']'] = TRUE;
}
@ -432,7 +489,6 @@ class EntityReferenceAdminTest extends WebTestBase {
return $field_name;
}
/**
* Checks if a select element contains the specified options.
*

View file

@ -1,15 +1,14 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\EntityReference\EntityReferenceAutoCreateTest.
*/
namespace Drupal\field\Tests\EntityReference;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\node\Entity\Node;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests creating new entity (e.g. taxonomy-term) from an autocomplete widget.
@ -18,7 +17,9 @@ use Drupal\node\Entity\Node;
*/
class EntityReferenceAutoCreateTest extends WebTestBase {
public static $modules = ['node'];
use EntityReferenceTestTrait;
public static $modules = ['node', 'taxonomy'];
/**
* The name of a content type that will reference $referencedType.
@ -44,7 +45,7 @@ class EntityReferenceAutoCreateTest extends WebTestBase {
$referenced = $this->drupalCreateContentType();
$this->referencedType = $referenced->id();
entity_create('field_storage_config', array(
FieldStorageConfig::create(array(
'field_name' => 'test_field',
'entity_type' => 'node',
'translatable' => FALSE,
@ -56,7 +57,7 @@ class EntityReferenceAutoCreateTest extends WebTestBase {
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
))->save();
entity_create('field_config', array(
FieldConfig::create([
'label' => 'Entity reference field',
'field_name' => 'test_field',
'entity_type' => 'node',
@ -72,7 +73,7 @@ class EntityReferenceAutoCreateTest extends WebTestBase {
'auto_create' => TRUE,
),
),
))->save();
])->save();
entity_get_display('node', $referencing->id(), 'default')
->setComponent('test_field')
@ -82,6 +83,9 @@ class EntityReferenceAutoCreateTest extends WebTestBase {
'type' => 'entity_reference_autocomplete',
))
->save();
$account = $this->drupalCreateUser(['access content', "create $this->referencingType content"]);
$this->drupalLogin($account);
}
/**
@ -89,9 +93,6 @@ class EntityReferenceAutoCreateTest extends WebTestBase {
* entity.
*/
public function testAutoCreate() {
$user1 = $this->drupalCreateUser(array('access content', "create $this->referencingType content"));
$this->drupalLogin($user1);
$this->drupalGet('node/add/' . $this->referencingType);
$this->assertFieldByXPath('//input[@id="edit-test-field-0-target-id" and contains(@class, "form-autocomplete")]', NULL, 'The autocomplete input element appears.');
@ -134,4 +135,94 @@ class EntityReferenceAutoCreateTest extends WebTestBase {
$this->assertText($referencing_node->label(), 'Referencing node label found.');
$this->assertText($referenced_node->label(), 'Referenced node label found.');
}
/**
* Tests if an entity reference field having multiple target bundles is
* storing the auto-created entity in the right destination.
*/
public function testMultipleTargetBundles() {
/** @var \Drupal\taxonomy\Entity\Vocabulary[] $vocabularies */
$vocabularies = [];
for ($i = 0; $i < 2; $i++) {
$vid = Unicode::strtolower($this->randomMachineName());
$vocabularies[$i] = Vocabulary::create([
'name' => $this->randomMachineName(),
'vid' => $vid,
]);
$vocabularies[$i]->save();
}
// Create a taxonomy term entity reference field that saves the auto-created
// taxonomy terms in the second vocabulary from the two that were configured
// as targets.
$field_name = Unicode::strtolower($this->randomMachineName());
$handler_settings = [
'target_bundles' => [
$vocabularies[0]->id() => $vocabularies[0]->id(),
$vocabularies[1]->id() => $vocabularies[1]->id(),
],
'auto_create' => TRUE,
'auto_create_bundle' => $vocabularies[1]->id(),
];
$this->createEntityReferenceField('node', $this->referencingType, $field_name, $this->randomString(), 'taxonomy_term', 'default', $handler_settings);
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $fd */
entity_get_form_display('node', $this->referencingType, 'default')
->setComponent($field_name, ['type' => 'entity_reference_autocomplete'])
->save();
$term_name = $this->randomString();
$edit = [
$field_name . '[0][target_id]' => $term_name,
'title[0][value]' => $this->randomString(),
];
$this->drupalPostForm('node/add/' . $this->referencingType, $edit, 'Save');
/** @var \Drupal\taxonomy\Entity\Term $term */
$term = taxonomy_term_load_multiple_by_name($term_name);
$term = reset($term);
// The new term is expected to be stored in the second vocabulary.
$this->assertEqual($vocabularies[1]->id(), $term->bundle());
/** @var \Drupal\field\Entity\FieldConfig $field_config */
$field_config = FieldConfig::loadByName('node', $this->referencingType, $field_name);
$handler_settings = $field_config->getSetting('handler_settings');
// Change the field setting to store the auto-created terms in the first
// vocabulary and test again.
$handler_settings['auto_create_bundle'] = $vocabularies[0]->id();
$field_config->setSetting('handler_settings', $handler_settings);
$field_config->save();
$term_name = $this->randomString();
$edit = [
$field_name . '[0][target_id]' => $term_name,
'title[0][value]' => $this->randomString(),
];
$this->drupalPostForm('node/add/' . $this->referencingType, $edit, 'Save');
/** @var \Drupal\taxonomy\Entity\Term $term */
$term = taxonomy_term_load_multiple_by_name($term_name);
$term = reset($term);
// The second term is expected to be stored in the first vocabulary.
$this->assertEqual($vocabularies[0]->id(), $term->bundle());
// @todo Re-enable this test when WebTestBase::curlHeaderCallback() provides
// a way to catch and assert user-triggered errors.
// Test the case when the field config settings are inconsistent.
//unset($handler_settings['auto_create_bundle']);
//$field_config->setSetting('handler_settings', $handler_settings);
//$field_config->save();
//
//$this->drupalGet('node/add/' . $this->referencingType);
//$error_message = sprintf(
// "Create referenced entities if they don't already exist option is enabled but a specific destination bundle is not set. You should re-visit and fix the settings of the '%s' (%s) field.",
// $field_config->getLabel(),
// $field_config->getName()
//);
//$this->assertErrorLogged($error_message);
}
}

View file

@ -1,15 +1,12 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\EntityReference\EntityReferenceFieldDefaultValueTest.
*/
namespace Drupal\field\Tests\EntityReference;
use Drupal\Component\Utility\Unicode;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\Node;
use Drupal\simpletest\WebTestBase;
/**
@ -55,14 +52,14 @@ class EntityReferenceFieldDefaultValueTest extends WebTestBase {
$referenced_node = $this->drupalCreateNode(array('type' => 'referenced_content'));
$field_name = Unicode::strtolower($this->randomMachineName());
$field_storage = entity_create('field_storage_config', array(
$field_storage = FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'entity_reference',
'settings' => array('target_type' => 'node'),
));
$field_storage->save();
$field = entity_create('field_config', array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'reference_content',
'settings' => array(
@ -72,7 +69,7 @@ class EntityReferenceFieldDefaultValueTest extends WebTestBase {
'sort' => array('field' => '_none'),
),
),
));
]);
$field->save();
// Set created node as default_value.
@ -97,7 +94,7 @@ class EntityReferenceFieldDefaultValueTest extends WebTestBase {
\Drupal::entityManager()->clearCachedFieldDefinitions();
// Create a new node to check that UUID has been converted to numeric ID.
$new_node = entity_create('node', array('type' => 'reference_content'));
$new_node = Node::create(['type' => 'reference_content']);
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->target_id, $referenced_node->id());
// Ensure that the entity reference config schemas are correct.
@ -118,7 +115,7 @@ class EntityReferenceFieldDefaultValueTest extends WebTestBase {
$referenced_node_type2 = $this->drupalCreateContentType(array('type' => 'referenced_config_to_preserve'));
$field_name = Unicode::strtolower($this->randomMachineName());
$field_storage = entity_create('field_storage_config', array(
$field_storage = FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'entity_reference',
@ -126,7 +123,7 @@ class EntityReferenceFieldDefaultValueTest extends WebTestBase {
'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED,
));
$field_storage->save();
$field = entity_create('field_config', array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'reference_content',
'settings' => array(
@ -135,7 +132,7 @@ class EntityReferenceFieldDefaultValueTest extends WebTestBase {
'sort' => array('field' => '_none'),
),
),
));
]);
$field->save();
// Set created node as default_value.

View file

@ -1,15 +1,12 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\EntityReference\EntityReferenceFieldTranslatedReferenceViewTest.
*/
namespace Drupal\field\Tests\EntityReference;
use Drupal\field\Entity\FieldConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests the translation of entity reference field display on nodes.
@ -206,7 +203,7 @@ class EntityReferenceFieldTranslatedReferenceViewTest extends WebTestBase {
* Adds term reference field for the article content type.
*/
protected function setUpEntityReferenceField() {
entity_create('field_storage_config', array(
FieldStorageConfig::create(array(
'field_name' => $this->referenceFieldName,
'entity_type' => $this->testEntityTypeName,
'type' => 'entity_reference',
@ -221,11 +218,11 @@ class EntityReferenceFieldTranslatedReferenceViewTest extends WebTestBase {
),
))->save();
entity_create('field_config', array(
FieldConfig::create([
'field_name' => $this->referenceFieldName,
'bundle' => $this->referrerType->id(),
'entity_type' => $this->testEntityTypeName,
))
])
->save();
entity_get_form_display($this->testEntityTypeName, $this->referrerType->id(), 'default')
->setComponent($this->referenceFieldName, array(

View file

@ -1,14 +1,11 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\EntityReference\EntityReferenceFileUploadTest.
*/
namespace Drupal\field\Tests\EntityReference;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests an autocomplete widget with file upload.
@ -51,7 +48,7 @@ class EntityReferenceFileUploadTest extends WebTestBase {
$this->referencedType = $referenced->id();
$this->nodeId = $this->drupalCreateNode(array('type' => $referenced->id()))->id();
entity_create('field_storage_config', array(
FieldStorageConfig::create(array(
'field_name' => 'test_field',
'entity_type' => 'node',
'translatable' => FALSE,
@ -63,7 +60,7 @@ class EntityReferenceFileUploadTest extends WebTestBase {
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
))->save();
entity_create('field_config', array(
FieldConfig::create([
'label' => 'Entity reference field',
'field_name' => 'test_field',
'entity_type' => 'node',
@ -78,23 +75,23 @@ class EntityReferenceFileUploadTest extends WebTestBase {
),
),
),
))->save();
])->save();
// Create a file field.
$file_field_name = 'file_field';
$field_storage = entity_create('field_storage_config', array(
$field_storage = FieldStorageConfig::create(array(
'field_name' => $file_field_name,
'entity_type' => 'node',
'type' => 'file'
));
$field_storage->save();
entity_create('field_config', array(
FieldConfig::create([
'entity_type' => 'node',
'field_storage' => $field_storage,
'bundle' => $referencing->id(),
'label' => $this->randomMachineName() . '_label',
))->save();
])->save();
entity_get_display('node', $referencing->id(), 'default')
->setComponent('test_field')

View file

@ -1,14 +1,10 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\EntityReference\EntityReferenceIntegrationTest.
*/
namespace Drupal\field\Tests\EntityReference;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\config\Tests\AssertConfigEntityImportTrait;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
@ -202,9 +198,9 @@ class EntityReferenceIntegrationTest extends WebTestBase {
$config_entity_2 = entity_create('config_test', array('id' => $this->randomMachineName(), 'label' => $this->randomMachineName()));
$config_entity_2->save();
$content_entity_1 = entity_create('entity_test', array('name' => $this->randomMachineName()));
$content_entity_1 = EntityTest::create(array('name' => $this->randomMachineName()));
$content_entity_1->save();
$content_entity_2 = entity_create('entity_test', array('name' => $this->randomMachineName()));
$content_entity_2 = EntityTest::create(array('name' => $this->randomMachineName()));
$content_entity_2->save();
return array(

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\EntityReference\EntityReferenceTestTrait.
*/
namespace Drupal\field\Tests\EntityReference;
use Drupal\field\Entity\FieldConfig;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\EntityReference\EntityReferenceXSSTest.
*/
namespace Drupal\field\Tests\EntityReference;
use Drupal\Core\Entity\Entity\EntityFormDisplay;

View file

@ -1,14 +1,11 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\EntityReference\Views\SelectionTest.
*/
namespace Drupal\field\Tests\EntityReference\Views;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\views\Views;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests entity reference selection handler.
@ -50,7 +47,7 @@ class SelectionTest extends WebTestBase {
}
// Create a field.
$field_storage = entity_create('field_storage_config', array(
$field_storage = FieldStorageConfig::create(array(
'field_name' => 'test_field',
'entity_type' => 'entity_test',
'translatable' => FALSE,
@ -61,7 +58,7 @@ class SelectionTest extends WebTestBase {
'cardinality' => '1',
));
$field_storage->save();
$field = entity_create('field_config', array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'test_bundle',
'settings' => array(
@ -74,7 +71,7 @@ class SelectionTest extends WebTestBase {
),
),
),
));
]);
$field->save();
$this->field = $field;
}

View file

@ -1,12 +1,10 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\FieldAccessTest.
*/
namespace Drupal\field\Tests;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests Field access.
*
@ -50,13 +48,13 @@ class FieldAccessTest extends FieldTestBase {
'entity_type' => 'node',
'type' => 'text',
);
entity_create('field_storage_config', $field_storage)->save();
FieldStorageConfig::create($field_storage)->save();
$field = array(
'field_name' => $field_storage['field_name'],
'entity_type' => 'node',
'bundle' => $content_type,
);
entity_create('field_config', $field)->save();
FieldConfig::create($field)->save();
// Assign display properties for the 'default' and 'teaser' view modes.
foreach (array('default', 'teaser') as $view_mode) {

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\FieldDefaultValueCallbackProvider.
*/
namespace Drupal\field\Tests;
/**

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\FieldDefaultValueCallbackTest.
*/
namespace Drupal\field\Tests;
use Drupal\field\Entity\FieldConfig;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\FieldHelpTest.
*/
namespace Drupal\field\Tests;
use Drupal\simpletest\WebTestBase;

View file

@ -1,12 +1,11 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\FieldImportDeleteUninstallUiTest.
*/
namespace Drupal\field\Tests;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Delete field storages and fields during config synchronization and uninstall
* module that provides the field type through the UI.
@ -36,31 +35,31 @@ class FieldImportDeleteUninstallUiTest extends FieldTestBase {
*/
public function testImportDeleteUninstall() {
// Create a telephone field.
$field_storage = entity_create('field_storage_config', array(
$field_storage = FieldStorageConfig::create(array(
'field_name' => 'field_tel',
'entity_type' => 'entity_test',
'type' => 'telephone',
));
$field_storage->save();
entity_create('field_config', array(
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
))->save();
])->save();
// Create a text field.
$date_field_storage = entity_create('field_storage_config', array(
$date_field_storage = FieldStorageConfig::create(array(
'field_name' => 'field_date',
'entity_type' => 'entity_test',
'type' => 'datetime',
));
$date_field_storage->save();
entity_create('field_config', array(
FieldConfig::create([
'field_storage' => $date_field_storage,
'bundle' => 'entity_test',
))->save();
])->save();
// Create an entity which has values for the telephone and text field.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$value = '+0123456789';
$entity->field_tel = $value;
$entity->field_date = time();

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\FieldTestBase.
*/
namespace Drupal\field\Tests;
use Drupal\Core\Entity\EntityInterface;

View file

@ -10,10 +10,15 @@ namespace Drupal\field\Tests;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\simpletest\KernelTestBase;
/**
* Parent class for Field API unit tests.
*
* @deprecated in Drupal 8.1.x, will be removed before Drupal 8.2.x. Use
* \Drupal\Tests\field\Kernel\FieldKernelTestBase instead.
*/
abstract class FieldUnitTestBase extends KernelTestBase {
@ -50,7 +55,7 @@ abstract class FieldUnitTestBase extends KernelTestBase {
$this->installEntitySchema('entity_test');
$this->installEntitySchema('user');
$this->installSchema('system', ['router', 'sequences', 'key_value']);
$this->installSchema('system', ['sequences', 'key_value']);
// Set default storage backend and configure the theme system.
$this->installConfig(array('field', 'system'));
@ -91,7 +96,7 @@ abstract class FieldUnitTestBase extends KernelTestBase {
$field_definition = 'field_definition' . $suffix;
$this->fieldTestData->$field_name = Unicode::strtolower($this->randomMachineName() . '_field_name' . $suffix);
$this->fieldTestData->$field_storage = entity_create('field_storage_config', array(
$this->fieldTestData->$field_storage = FieldStorageConfig::create(array(
'field_name' => $this->fieldTestData->$field_name,
'entity_type' => $entity_type,
'type' => 'test_field',
@ -108,7 +113,7 @@ abstract class FieldUnitTestBase extends KernelTestBase {
'test_field_setting' => $this->randomMachineName(),
),
);
$this->fieldTestData->$field = entity_create('field_config', $this->fieldTestData->$field_definition);
$this->fieldTestData->$field = FieldConfig::create($this->fieldTestData->$field_definition);
$this->fieldTestData->$field->save();
entity_get_form_display($entity_type, $bundle, 'default')

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\FormTest.
*/
namespace Drupal\field\Tests;
use Drupal\Component\Utility\Html;
@ -99,8 +94,8 @@ class FormTest extends FieldTestBase {
$field_storage = $this->fieldStorageSingle;
$field_name = $field_storage['field_name'];
$this->field['field_name'] = $field_name;
entity_create('field_storage_config', $field_storage)->save();
entity_create('field_config', $this->field)->save();
FieldStorageConfig::create($field_storage)->save();
FieldConfig::create($this->field)->save();
entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
->setComponent($field_name)
->save();
@ -175,8 +170,8 @@ class FormTest extends FieldTestBase {
$this->field['field_name'] = $field_name;
$default = rand(1, 127);
$this->field['default_value'] = array(array('value' => $default));
entity_create('field_storage_config', $field_storage)->save();
entity_create('field_config', $this->field)->save();
FieldStorageConfig::create($field_storage)->save();
FieldConfig::create($this->field)->save();
entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
->setComponent($field_name)
->save();
@ -203,8 +198,8 @@ class FormTest extends FieldTestBase {
$field_name = $field_storage['field_name'];
$this->field['field_name'] = $field_name;
$this->field['required'] = TRUE;
entity_create('field_storage_config', $field_storage)->save();
entity_create('field_config', $this->field)->save();
FieldStorageConfig::create($field_storage)->save();
FieldConfig::create($this->field)->save();
entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
->setComponent($field_name)
->save();
@ -239,16 +234,16 @@ class FormTest extends FieldTestBase {
// $this->field = $this->field_multiple;
// $field_name = $this->field['field_name'];
// $this->instance['field_name'] = $field_name;
// entity_create('field_storage_config', $this->field)->save();
// entity_create('field_config', $this->instance)->save();
// FieldStorageConfig::create($this->field)->save();
// FieldConfig::create($this->instance)->save();
// }
function testFieldFormUnlimited() {
$field_storage = $this->fieldStorageUnlimited;
$field_name = $field_storage['field_name'];
$this->field['field_name'] = $field_name;
entity_create('field_storage_config', $field_storage)->save();
entity_create('field_config', $this->field)->save();
FieldStorageConfig::create($field_storage)->save();
FieldConfig::create($this->field)->save();
entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
->setComponent($field_name)
->save();
@ -358,14 +353,14 @@ class FormTest extends FieldTestBase {
$field_storage = $this->fieldStorageUnlimited;
$field_name = $field_storage['field_name'];
$this->field['field_name'] = $field_name;
entity_create('field_storage_config', $field_storage)->save();
entity_create('field_config', $this->field)->save();
FieldStorageConfig::create($field_storage)->save();
FieldConfig::create($this->field)->save();
entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
->setComponent($field_name)
->save();
// Add a required radio field.
entity_create('field_storage_config', array(
FieldStorageConfig::create(array(
'field_name' => 'required_radio_test',
'entity_type' => 'entity_test',
'type' => 'list_string',
@ -379,7 +374,7 @@ class FormTest extends FieldTestBase {
'bundle' => 'entity_test',
'required' => TRUE,
);
entity_create('field_config', $field)->save();
FieldConfig::create($field)->save();
entity_get_form_display($field['entity_type'], $field['bundle'], 'default')
->setComponent($field['field_name'], array(
'type' => 'options_buttons',
@ -405,8 +400,8 @@ class FormTest extends FieldTestBase {
$field_storage = $this->fieldStorageUnlimited;
$field_name = $field_storage['field_name'];
$this->field['field_name'] = $field_name;
entity_create('field_storage_config', $field_storage)->save();
entity_create('field_config', $this->field)->save();
FieldStorageConfig::create($field_storage)->save();
FieldConfig::create($this->field)->save();
entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
->setComponent($field_name)
->save();
@ -466,8 +461,8 @@ class FormTest extends FieldTestBase {
$field_storage = $this->fieldStorageMultiple;
$field_name = $field_storage['field_name'];
$this->field['field_name'] = $field_name;
entity_create('field_storage_config', $field_storage)->save();
entity_create('field_config', $this->field)->save();
FieldStorageConfig::create($field_storage)->save();
FieldConfig::create($this->field)->save();
entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
->setComponent($field_name, array(
'type' => 'test_field_widget_multiple',
@ -515,8 +510,8 @@ class FormTest extends FieldTestBase {
$field['field_name'] = $field_name;
$field['entity_type'] = $entity_type;
$field['bundle'] = $entity_type;
entity_create('field_storage_config', $field_storage)->save();
entity_create('field_config', $field)->save();
FieldStorageConfig::create($field_storage)->save();
FieldConfig::create($field)->save();
entity_get_form_display($entity_type, $entity_type, 'default')
->setComponent($field_name)
->save();
@ -535,15 +530,17 @@ class FormTest extends FieldTestBase {
'bundle' => $entity_type,
'default_value' => array(0 => array('value' => 99)),
);
entity_create('field_storage_config', $field_storage_no_access)->save();
entity_create('field_config', $field_no_access)->save();
FieldStorageConfig::create($field_storage_no_access)->save();
FieldConfig::create($field_no_access)->save();
entity_get_form_display($field_no_access['entity_type'], $field_no_access['bundle'], 'default')
->setComponent($field_name_no_access)
->save();
// Test that the form structure includes full information for each delta
// apart from #access.
$entity = entity_create($entity_type, array('id' => 0, 'revision_id' => 0));
$entity = $this->container->get('entity_type.manager')
->getStorage($entity_type)
->create(array('id' => 0, 'revision_id' => 0));
$display = entity_get_form_display($entity_type, $entity_type, 'default');
$form = array();
@ -600,8 +597,8 @@ class FormTest extends FieldTestBase {
$this->field['default_value'] = array(0 => array('value' => 99));
$this->field['entity_type'] = $entity_type;
$this->field['bundle'] = $entity_type;
entity_create('field_storage_config', $field_storage)->save();
$this->field = entity_create('field_config', $this->field);
FieldStorageConfig::create($field_storage)->save();
$this->field = FieldConfig::create($this->field);
$this->field->save();
// We explicitly do not assign a widget in a form display, so the field
// stays hidden in forms.

View file

@ -1,12 +1,9 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\NestedFormTest.
*/
namespace Drupal\field\Tests;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests field elements in nested forms.
@ -57,30 +54,34 @@ class NestedFormTest extends FieldTestBase {
*/
function testNestedFieldForm() {
// Add two fields on the 'entity_test'
entity_create('field_storage_config', $this->fieldStorageSingle)->save();
entity_create('field_storage_config', $this->fieldStorageUnlimited)->save();
FieldStorageConfig::create($this->fieldStorageSingle)->save();
FieldStorageConfig::create($this->fieldStorageUnlimited)->save();
$this->field['field_name'] = 'field_single';
$this->field['label'] = 'Single field';
entity_create('field_config', $this->field)->save();
FieldConfig::create($this->field)->save();
entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
->setComponent($this->field['field_name'])
->save();
$this->field['field_name'] = 'field_unlimited';
$this->field['label'] = 'Unlimited field';
entity_create('field_config', $this->field)->save();
FieldConfig::create($this->field)->save();
entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
->setComponent($this->field['field_name'])
->save();
// Create two entities.
$entity_type = 'entity_test';
$entity_1 = entity_create($entity_type, array('id' => 1));
$entity_1 = $this->container->get('entity_type.manager')
->getStorage($entity_type)
->create(array('id' => 1));
$entity_1->enforceIsNew();
$entity_1->field_single->value = 0;
$entity_1->field_unlimited->value = 1;
$entity_1->save();
$entity_2 = entity_create($entity_type, array('id' => 2));
$entity_2 = $this->container->get('entity_type.manager')
->getStorage($entity_type)
->create(array('id' => 2));
$entity_2->enforceIsNew();
$entity_2->field_single->value = 10;
$entity_2->field_unlimited->value = 11;

View file

@ -1,14 +1,12 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Number\NumberFieldTest.
*/
namespace Drupal\field\Tests\Number;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\Node;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests the creation of numeric fields.
@ -43,7 +41,7 @@ class NumberFieldTest extends WebTestBase {
function testNumberDecimalField() {
// Create a field with settings to validate.
$field_name = Unicode::strtolower($this->randomMachineName());
entity_create('field_storage_config', array(
FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'decimal',
@ -51,11 +49,11 @@ class NumberFieldTest extends WebTestBase {
'precision' => 8, 'scale' => 4,
)
))->save();
entity_create('field_config', array(
FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
))->save();
])->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, array(
@ -133,21 +131,21 @@ class NumberFieldTest extends WebTestBase {
// Create a field with settings to validate.
$field_name = Unicode::strtolower($this->randomMachineName());
$storage = entity_create('field_storage_config', array(
$storage = FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'integer',
));
$storage->save();
entity_create('field_config', array(
FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'settings' => array(
'min' => $minimum, 'max' => $maximum, 'prefix' => 'ThePrefix',
)
))->save();
])->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, array(
@ -276,17 +274,17 @@ class NumberFieldTest extends WebTestBase {
function testNumberFloatField() {
// Create a field with settings to validate.
$field_name = Unicode::strtolower($this->randomMachineName());
entity_create('field_storage_config', array(
FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'float',
))->save();
entity_create('field_config', array(
FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
))->save();
])->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, array(
@ -377,19 +375,19 @@ class NumberFieldTest extends WebTestBase {
// Create a content type containing float and integer fields.
$this->drupalCreateContentType(array('type' => $type));
entity_create('field_storage_config', array(
FieldStorageConfig::create(array(
'field_name' => $float_field,
'entity_type' => 'node',
'type' => 'float',
))->save();
entity_create('field_storage_config', array(
FieldStorageConfig::create(array(
'field_name' => $integer_field,
'entity_type' => 'node',
'type' => 'integer',
))->save();
entity_create('field_config', array(
FieldConfig::create([
'field_name' => $float_field,
'entity_type' => 'node',
'bundle' => $type,
@ -397,9 +395,9 @@ class NumberFieldTest extends WebTestBase {
'prefix' => $prefix,
'suffix' => $suffix
),
))->save();
])->save();
entity_create('field_config', array(
FieldConfig::create([
'field_name' => $integer_field,
'entity_type' => 'node',
'bundle' => $type,
@ -407,7 +405,7 @@ class NumberFieldTest extends WebTestBase {
'prefix' => $prefix,
'suffix' => $suffix
),
))->save();
])->save();
entity_get_form_display('node', $type, 'default')
->setComponent($float_field, array(
@ -434,16 +432,12 @@ class NumberFieldTest extends WebTestBase {
->save();
// Create a node to test formatters.
$node = entity_create('node', array(
$node = Node::create([
'type' => $type,
'title' => $this->randomMachineName(),
$float_field => array(
'value' => $random_float,
),
$integer_field => array(
'value' => $random_integer,
),
));
$float_field => ['value' => $random_float],
$integer_field => ['value' => $random_integer],
]);
$node->save();
// Go to manage display page.
@ -501,17 +495,17 @@ class NumberFieldTest extends WebTestBase {
function testCreateNumberFloatField() {
// Create a float field.
$field_name = Unicode::strtolower($this->randomMachineName());
entity_create('field_storage_config', array(
FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'float',
))->save();
$field = entity_create('field_config', array(
$field = FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
));
]);
$field->save();
// Set the minimum value to a float value.
@ -526,17 +520,17 @@ class NumberFieldTest extends WebTestBase {
function testCreateNumberDecimalField() {
// Create a decimal field.
$field_name = Unicode::strtolower($this->randomMachineName());
entity_create('field_storage_config', array(
FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'decimal',
))->save();
$field = entity_create('field_config', array(
$field = FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
));
]);
$field->save();
// Set the minimum value to a decimal value.

View file

@ -1,14 +1,11 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\String\StringFieldTest.
*/
namespace Drupal\field\Tests\String;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests the creation of string fields.
@ -54,17 +51,17 @@ class StringFieldTest extends WebTestBase {
function _testTextfieldWidgets($field_type, $widget_type) {
// Create a field.
$field_name = Unicode::strtolower($this->randomMachineName());
$field_storage = entity_create('field_storage_config', array(
$field_storage = FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => $field_type
));
$field_storage->save();
entity_create('field_config', array(
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
'label' => $this->randomMachineName() . '_label',
))->save();
])->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, array(
'type' => $widget_type,

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\TranslationWebTest.
*/
namespace Drupal\field\Tests;
use Drupal\Component\Utility\Unicode;
@ -65,14 +60,14 @@ class TranslationWebTest extends FieldTestBase {
'type' => 'test_field',
'cardinality' => 4,
);
entity_create('field_storage_config', $field_storage)->save();
FieldStorageConfig::create($field_storage)->save();
$this->fieldStorage = FieldStorageConfig::load($this->entityTypeId . '.' . $this->fieldName);
$field = array(
'field_storage' => $this->fieldStorage,
'bundle' => $this->entityTypeId,
);
entity_create('field_config', $field)->save();
FieldConfig::create($field)->save();
$this->field = FieldConfig::load($this->entityTypeId . '.' . $field['bundle'] . '.' . $this->fieldName);
entity_get_form_display($this->entityTypeId, $this->entityTypeId, 'default')
@ -96,7 +91,9 @@ class TranslationWebTest extends FieldTestBase {
// Prepare the field translations.
field_test_entity_info_translatable($this->entityTypeId, TRUE);
$entity = entity_create($this->entityTypeId);
$entity = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId)
->create();
$available_langcodes = array_flip(array_keys($this->container->get('language_manager')->getLanguages()));
$field_name = $this->fieldStorage->getName();

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Update\EmailWidgetSizeSettingUpdateTest.
*/
namespace Drupal\field\Tests\Update;
use Drupal\system\Tests\Update\UpdatePathTestBase;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Update\EntityReferenceHandlerSettingUpdateTest.
*/
namespace Drupal\field\Tests\Update;
use Drupal\system\Tests\Update\UpdatePathTestBase;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Update\FieldUpdateTest.
*/
namespace Drupal\field\Tests\Update;
use Drupal\Core\Config\Config;
@ -111,6 +106,26 @@ class FieldUpdateTest extends UpdatePathTestBase {
$this->assertEqual(array_keys($referencable['article']), [$node_1->id()]);
}
/**
* Tests field_update_8003().
*
* @see field_update_8003()
*/
public function testFieldUpdate8003() {
// Run updates.
$this->runUpdates();
// Check that the new 'auto_create_bundle' setting is populated correctly.
$field = $this->configFactory->get('field.field.node.article.field_ref_autocreate_2412569');
$handler_settings = $field->get('settings.handler_settings');
$expected_target_bundles = ['tags' => 'tags', 'test' => 'test'];
$this->assertEqual($handler_settings['target_bundles'], $expected_target_bundles);
$this->assertTrue($handler_settings['auto_create']);
$this->assertEqual($handler_settings['auto_create_bundle'], 'tags');
}
/**
* Asserts that a config depends on 'entity_reference' or not
*

View file

@ -1,30 +1,23 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Views\FieldTestBase.
*/
namespace Drupal\field\Tests\Views;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\field\Entity\FieldStorageConfig;
/**
* @TODO
* - Test on a generic entity not on a node.
* Provides some helper methods for testing fieldapi integration into views.
*
* What has to be tested:
* @todo Test on a generic entity not on a node. What has to be tested:
* - Make sure that every wanted field is added to the according entity type.
* - Make sure the joins are done correctly.
* - Use basic fields and make sure that the full wanted object is built.
* - Use relationships between different entity types, for example node and
* the node author(user).
*/
namespace Drupal\field\Tests\Views;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Provides some helper methods for testing fieldapi integration into views.
*/
abstract class FieldTestBase extends ViewTestBase {
/**
@ -53,10 +46,10 @@ abstract class FieldTestBase extends ViewTestBase {
parent::setUp();
// Ensure the page node type exists.
entity_create('node_type', array(
NodeType::create([
'type' => 'page',
'name' => 'page',
))->save();
])->save();
ViewTestData::createTestViews(get_class($this), array('field_test_views'));
}
@ -66,7 +59,7 @@ abstract class FieldTestBase extends ViewTestBase {
$field_names = array();
for ($i = 0; $i < $amount; $i++) {
$field_names[$i] = 'field_name_' . $i;
$this->fieldStorages[$i] = entity_create('field_storage_config', array(
$this->fieldStorages[$i] = FieldStorageConfig::create(array(
'field_name' => $field_names[$i],
'entity_type' => 'node',
'type' => $type,
@ -78,10 +71,10 @@ abstract class FieldTestBase extends ViewTestBase {
function setUpFields($bundle = 'page') {
foreach ($this->fieldStorages as $key => $field_storage) {
$this->fields[$key] = entity_create('field_config', array(
$this->fields[$key] = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $bundle,
));
]);
$this->fields[$key]->save();
}
}

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Views\FieldUITest.
*/
namespace Drupal\field\Tests\Views;
use Drupal\field\Entity\FieldConfig;

View file

@ -1,15 +1,11 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Views\HandlerFieldFieldTest.
*/
namespace Drupal\field\Tests\Views;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\Views;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests the field itself of the Field integration.
@ -52,7 +48,7 @@ class HandlerFieldFieldTest extends FieldTestBase {
$this->setUpFieldStorages(3);
// Setup a field with cardinality > 1.
$this->fieldStorages[3] = entity_create('field_storage_config', array(
$this->fieldStorages[3] = FieldStorageConfig::create(array(
'field_name' => 'field_name_3',
'entity_type' => 'node',
'type' => 'string',
@ -60,7 +56,7 @@ class HandlerFieldFieldTest extends FieldTestBase {
));
$this->fieldStorages[3]->save();
// Setup a field that will have no value.
$this->fieldStorages[4] = entity_create('field_storage_config', array(
$this->fieldStorages[4] = FieldStorageConfig::create(array(
'field_name' => 'field_name_4',
'entity_type' => 'node',
'type' => 'string',
@ -69,7 +65,7 @@ class HandlerFieldFieldTest extends FieldTestBase {
$this->fieldStorages[4]->save();
// Setup a text field.
$this->fieldStorages[5] = entity_create('field_storage_config', array(
$this->fieldStorages[5] = FieldStorageConfig::create(array(
'field_name' => 'field_name_5',
'entity_type' => 'node',
'type' => 'text',
@ -78,7 +74,7 @@ class HandlerFieldFieldTest extends FieldTestBase {
// Setup a text field with access control.
// @see field_test_entity_field_access()
$this->fieldStorages[6] = entity_create('field_storage_config', array(
$this->fieldStorages[6] = FieldStorageConfig::create(array(
'field_name' => 'field_no_view_access',
'entity_type' => 'node',
'type' => 'text',

View file

@ -1,13 +1,10 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\reEnableModuleFieldTest.
*/
namespace Drupal\field\Tests;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests the behavior of a field module after being disabled and re-enabled.
@ -47,17 +44,17 @@ class reEnableModuleFieldTest extends WebTestBase {
function testReEnabledField() {
// Add a telephone field to the article content type.
$field_storage = entity_create('field_storage_config', array(
$field_storage = FieldStorageConfig::create(array(
'field_name' => 'field_telephone',
'entity_type' => 'node',
'type' => 'telephone',
));
$field_storage->save();
entity_create('field_config', array(
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'article',
'label' => 'Telephone Number',
))->save();
])->save();
entity_get_form_display('node', 'article', 'default')
->setComponent('field_telephone', array(
@ -93,14 +90,35 @@ class reEnableModuleFieldTest extends WebTestBase {
$admin_user = $this->drupalCreateUser(array('access administration pages', 'administer modules'));
$this->drupalLogin($admin_user);
$this->drupalGet('admin/modules/uninstall');
$this->assertText('Fields type(s) in use');
$this->assertText("The Telephone number field type is used in the following field: node.field_telephone");
// Add another telephone field to a different entity type in order to test
// the message for the case when multiple fields are blocking the
// uninstallation of a module.
$field_storage2 = entity_create('field_storage_config', array(
'field_name' => 'field_telephone_2',
'entity_type' => 'user',
'type' => 'telephone',
));
$field_storage2->save();
FieldConfig::create([
'field_storage' => $field_storage2,
'bundle' => 'user',
'label' => 'User Telephone Number',
])->save();
$this->drupalGet('admin/modules/uninstall');
$this->assertText("The Telephone number field type is used in the following fields: node.field_telephone, user.field_telephone_2");
// Delete both fields.
$field_storage->delete();
$field_storage2->delete();
$this->drupalGet('admin/modules/uninstall');
$this->assertText('Fields pending deletion');
$this->cronRun();
$this->assertNoText('Fields type(s) in use');
$this->assertNoText("The Telephone number field type is used in the following field: node.field_telephone");
$this->assertNoText('Fields pending deletion');
}
}

View file

@ -26,8 +26,14 @@ $connection->insert('config')
])
->execute();
// Configuration for an entity_reference field storage.
$config = Yaml::decode(file_get_contents(__DIR__ . '/field.storage.node.field_ref_views_select_2429191.yml'));
// Configuration for an entity_reference field storage using the View for
// selection.
$field_ref_views_select_2429191 = Yaml::decode(file_get_contents(__DIR__ . '/field.storage.node.field_ref_views_select_2429191.yml'));
// Configuration for an entity_reference field storage using the auto-create
// feature.
$field_ref_autocreate_2412569 = Yaml::decode(file_get_contents(__DIR__ . '/field.storage.node.field_ref_autocreate_2412569.yml'));
$connection->insert('config')
->fields([
'collection',
@ -36,8 +42,13 @@ $connection->insert('config')
])
->values([
'collection' => '',
'name' => 'field.storage.' . $config['id'],
'data' => serialize($config),
'name' => 'field.storage.' . $field_ref_views_select_2429191['id'],
'data' => serialize($field_ref_views_select_2429191),
])
->values([
'collection' => '',
'name' => 'field.storage.' . $field_ref_autocreate_2412569['id'],
'data' => serialize($field_ref_autocreate_2412569),
])
->execute();
// We need to Update the registry of "last installed" field definitions.
@ -48,7 +59,8 @@ $installed = $connection->select('key_value')
->execute()
->fetchField();
$installed = unserialize($installed);
$installed['field_ref_views_select_2429191'] = new \Drupal\field\Entity\FieldStorageConfig($config);
$installed['field_ref_views_select_2429191'] = new \Drupal\field\Entity\FieldStorageConfig($field_ref_views_select_2429191);
$installed['field_ref_autocreate_2412569'] = new \Drupal\field\Entity\FieldStorageConfig($field_ref_autocreate_2412569);
$connection->update('key_value')
->condition('collection', 'entity.definitions.installed')
->condition('name', 'node.field_storage_definitions')
@ -58,7 +70,11 @@ $connection->update('key_value')
->execute();
// Configuration for an entity_reference field using the View for selection.
$config = Yaml::decode(file_get_contents(__DIR__ . '/field.field.node.article.field_ref_views_select_2429191.yml'));
$field_ref_views_select_2429191 = Yaml::decode(file_get_contents(__DIR__ . '/field.field.node.article.field_ref_views_select_2429191.yml'));
// Configuration for an entity_reference field using the auto-create feature.
$field_ref_autocreate_2412569 = Yaml::decode(file_get_contents(__DIR__ . '/field.field.node.article.field_ref_autocreate_2412569.yml'));
$connection->insert('config')
->fields([
'collection',
@ -67,7 +83,12 @@ $connection->insert('config')
])
->values([
'collection' => '',
'name' => 'field.field.' . $config['id'],
'data' => serialize($config),
'name' => 'field.field.' . $field_ref_views_select_2429191['id'],
'data' => serialize($field_ref_views_select_2429191),
])
->values([
'collection' => '',
'name' => 'field.field.' . $field_ref_autocreate_2412569['id'],
'data' => serialize($field_ref_autocreate_2412569),
])
->execute();

View file

@ -0,0 +1,29 @@
uuid: d6deba8d-073a-4572-a000-ee2a2de94de2
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_ref_autocreate_2412569
- node.type.article
- taxonomy.vocabulary.tags
- taxonomy.vocabulary.test
id: node.article.field_ref_autocreate_2412569
field_name: field_ref_autocreate_2412569
entity_type: node
bundle: article
label: 'Ref Autocreate 2412569'
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: 'default:taxonomy_term'
handler_settings:
target_bundles:
tags: tags
test: test
sort:
field: _none
auto_create: true
field_type: entity_reference

View file

@ -0,0 +1,20 @@
uuid: 5e4095a3-8f89-4d7a-b222-34bf5240b646
langcode: en
status: true
dependencies:
module:
- node
- taxonomy
id: node.field_ref_autocreate_2412569
field_name: field_ref_autocreate_2412569
entity_type: node
type: entity_reference
settings:
target_type: taxonomy_term
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_plugins_test\Plugin\Field\FieldFormatter\TestTextTrimmedFormatter.
*/
namespace Drupal\field_plugins_test\Plugin\Field\FieldFormatter;
use Drupal\text\Plugin\Field\FieldFormatter\TextTrimmedFormatter;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_plugins_test\Plugin\Field\FieldWidget\TestTextfieldWidget.
*/
namespace Drupal\field_plugins_test\Plugin\Field\FieldWidget;
use Drupal\text\Plugin\Field\FieldWidget\TextfieldWidget;

View file

@ -1,8 +1,5 @@
<?php
use Drupal\field\FieldStorageConfigInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* @file
* Helper module for the Field API tests.
@ -16,6 +13,9 @@ use Drupal\Core\Form\FormStateInterface;
* test helper functions
*/
use Drupal\field\FieldStorageConfigInterface;
use Drupal\Core\Form\FormStateInterface;
require_once __DIR__ . '/field_test.entity.inc';
require_once __DIR__ . '/field_test.field.inc';
@ -42,7 +42,7 @@ require_once __DIR__ . '/field_test.field.inc';
* field_test_memorize();
*
* // call some Field API functions that invoke field_test hooks
* entity_create('field_storage_config', $field_definition)->save();
* FieldStorageConfig::create($field_definition)->save();
*
* // retrieve and reset the memorized hook call data
* $mem = field_test_memorize();

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Form\NestedEntityTestForm.
*/
namespace Drupal\field_test\Form;
use Drupal\Core\Entity\EntityInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldApplicableFormatter.
*/
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldDefaultFormatter.
*/
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;

View file

@ -1,9 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldEmptyFormatter.
*/
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldEmptySettingFormatter.
*/
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldMultipleFormatter.
*/
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
*
* Contains \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldNoSettingsFormatter.
*/
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldPrepareViewFormatter.
*/
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\Field\FieldType\HiddenTestItem.
*/
namespace Drupal\field_test\Plugin\Field\FieldType;
/**

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\Field\FieldType\TestItem.
*/
namespace Drupal\field_test\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\Field\FieldType\TestItemWithDependencies.
*/
namespace Drupal\field_test\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldDefinitionInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\Field\FieldType\TestItemWithPreconfiguredOptions.
*/
namespace Drupal\field_test\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\Field\FieldWidget\TestFieldWidget.
*/
namespace Drupal\field_test\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\Field\FieldWidget\TestFieldWidgetMultiple.
*/
namespace Drupal\field_test\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldDefinitionInterface;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\field_test\Plugin\Validation\Constraint\TestFieldConstraint.
*/
namespace Drupal\field_test\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraints\NotEqualTo;

View file

@ -1,5 +1,10 @@
<?php
/**
* @file
* Test module.
*/
use Drupal\Core\Form\FormStateInterface;
/**

View file

@ -1,11 +1,6 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Boolean\BooleanFormatterTest.
*/
namespace Drupal\field\Tests\Boolean;
namespace Drupal\Tests\field\Kernel\Boolean;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
@ -13,7 +8,7 @@ use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests the boolean formatter.
@ -27,7 +22,7 @@ class BooleanFormatterTest extends KernelTestBase {
*
* @var array
*/
public static $modules = ['field', 'text', 'entity_test', 'user'];
public static $modules = ['field', 'text', 'entity_test', 'user', 'system'];
/**
* @var string

View file

@ -1,22 +1,20 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Boolean\BooleanItemTest.
*/
namespace Drupal\field\Tests\Boolean;
namespace Drupal\Tests\field\Kernel\Boolean;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\field\Tests\FieldUnitTestBase;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests the new entity API for the boolean field type.
*
* @group field
*/
class BooleanItemTest extends FieldUnitTestBase {
class BooleanItemTest extends FieldKernelTestBase {
/**
* {@inheritdoc}
@ -25,16 +23,16 @@ class BooleanItemTest extends FieldUnitTestBase {
parent::setUp();
// Create a boolean field and storage for validation.
entity_create('field_storage_config', array(
FieldStorageConfig::create(array(
'field_name' => 'field_boolean',
'entity_type' => 'entity_test',
'type' => 'boolean',
))->save();
entity_create('field_config', array(
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_boolean',
'bundle' => 'entity_test',
))->save();
])->save();
// Create a form display for the default form mode.
entity_get_form_display('entity_test', 'entity_test', 'default')
@ -49,7 +47,7 @@ class BooleanItemTest extends FieldUnitTestBase {
*/
public function testBooleanItem() {
// Verify entity creation.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$value = '1';
$entity->field_boolean = $value;
$entity->name->value = $this->randomMachineName();
@ -74,7 +72,7 @@ class BooleanItemTest extends FieldUnitTestBase {
$this->assertEqual($entity->field_boolean->value, $new_value);
// Test sample item generation.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->field_boolean->generateSampleItems();
$this->entityValidateAndSave($entity);
}

View file

@ -1,21 +1,17 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\BulkDeleteTest.
*/
namespace Drupal\field\Tests;
namespace Drupal\Tests\field\Kernel;
use Drupal\Core\Entity\EntityInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Bulk delete storages and fields, and clean up afterwards.
*
* @group field
*/
class BulkDeleteTest extends FieldUnitTestBase {
class BulkDeleteTest extends FieldKernelTestBase {
/**
* The fields to use in this test.
@ -105,7 +101,7 @@ class BulkDeleteTest extends FieldUnitTestBase {
}
// Create two field storages.
$field_storage = entity_create('field_storage_config', array(
$field_storage = FieldStorageConfig::create(array(
'field_name' => 'bf_1',
'entity_type' => $this->entityTypeId,
'type' => 'test_field',
@ -113,7 +109,7 @@ class BulkDeleteTest extends FieldUnitTestBase {
));
$field_storage->save();
$this->fieldStorages[] = $field_storage;
$field_storage = entity_create('field_storage_config', array(
$field_storage = FieldStorageConfig::create(array(
'field_name' => 'bf_2',
'entity_type' => $this->entityTypeId,
'type' => 'test_field',
@ -126,13 +122,15 @@ class BulkDeleteTest extends FieldUnitTestBase {
// fields.
foreach ($this->bundles as $bundle) {
foreach ($this->fieldStorages as $field_storage) {
entity_create('field_config', array(
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $bundle,
))->save();
])->save();
}
for ($i = 0; $i < 10; $i++) {
$entity = entity_create($this->entityTypeId, array('type' => $bundle));
$entity = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId)
->create(array('type' => $bundle));
foreach ($this->fieldStorages as $field_storage) {
$entity->{$field_storage->getName()}->setValue($this->_generateTestFieldValues($field_storage->getCardinality()));
}

View file

@ -1,11 +1,6 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\ConfigFieldDefinitionTest.
*/
namespace Drupal\field\Tests;
namespace Drupal\Tests\field\Kernel;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
@ -15,7 +10,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
*
* @group field
*/
class ConfigFieldDefinitionTest extends FieldUnitTestBase {
class ConfigFieldDefinitionTest extends FieldKernelTestBase {
/**
* The entity manager service.

View file

@ -1,20 +1,18 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\DisplayApiTest.
*/
namespace Drupal\field\Tests;
namespace Drupal\Tests\field\Kernel;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests the field display API.
*
* @group field
*/
class DisplayApiTest extends FieldUnitTestBase {
class DisplayApiTest extends FieldKernelTestBase {
/**
* The field name to use in this test.
@ -58,6 +56,11 @@ class DisplayApiTest extends FieldUnitTestBase {
*/
protected $values;
/**
* {@inheritdoc}
*/
public static $modules = ['system'];
protected function setUp() {
parent::setUp();
@ -94,8 +97,8 @@ class DisplayApiTest extends FieldUnitTestBase {
),
);
entity_create('field_storage_config', $field_storage)->save();
entity_create('field_config', $field)->save();
FieldStorageConfig::create($field_storage)->save();
FieldConfig::create($field)->save();
// Create a display for the default view mode.
entity_get_display($field['entity_type'], $field['bundle'], 'default')
->setComponent($this->fieldName, $this->displayOptions['default'])
@ -108,7 +111,7 @@ class DisplayApiTest extends FieldUnitTestBase {
// Create an entity with values.
$this->values = $this->_generateTestFieldValues($this->cardinality);
$this->entity = entity_create('entity_test');
$this->entity = EntityTest::create();
$this->entity->{$this->fieldName}->setValue($this->values);
$this->entity->save();
}
@ -120,7 +123,7 @@ class DisplayApiTest extends FieldUnitTestBase {
$items = $this->entity->get($this->fieldName);
\Drupal::service('theme_handler')->install(['classy']);
$this->config('system.theme')->set('default', 'classy')->save();
\Drupal::service('theme_handler')->setDefault('classy');
// No display settings: check that default display settings are used.
$build = $items->view();

Some files were not shown because too many files have changed in this diff Show more