updated core from 8.4 to 8.5 : bug with login_destination
This commit is contained in:
@@ -39,7 +39,7 @@ class ConfigImporterFieldPurger {
|
||||
$field_storage->delete();
|
||||
}
|
||||
}
|
||||
field_purge_batch($context['sandbox']['field']['purge_batch_size'], $field_storage->uuid());
|
||||
field_purge_batch($context['sandbox']['field']['purge_batch_size'], $field_storage->getUniqueStorageIdentifier());
|
||||
$context['sandbox']['field']['current_progress']++;
|
||||
$fields_to_delete_count = count(static::getFieldStoragesToPurge($context['sandbox']['field']['extensions'], $config_importer->getUnprocessedConfiguration('delete')));
|
||||
if ($fields_to_delete_count == 0) {
|
||||
@@ -133,11 +133,11 @@ class ConfigImporterFieldPurger {
|
||||
}
|
||||
|
||||
// Gather deleted fields from modules that are being uninstalled.
|
||||
/** @var \Drupal\field\FieldStorageConfigInterface[] $field_storages */
|
||||
$field_storages = entity_load_multiple_by_properties('field_storage_config', ['deleted' => TRUE, 'include_deleted' => TRUE]);
|
||||
foreach ($field_storages as $field_storage) {
|
||||
if (!in_array($field_storage->getTypeProvider(), $providers)) {
|
||||
$storages_to_delete[$field_storage->id()] = $field_storage;
|
||||
/** @var \Drupal\field\FieldStorageConfigInterface[] $deleted_storage_definitions */
|
||||
$deleted_storage_definitions = \Drupal::service('entity_field.deleted_fields_repository')->getFieldStorageDefinitions();
|
||||
foreach ($deleted_storage_definitions as $field_storage_definition) {
|
||||
if ($field_storage_definition instanceof FieldStorageConfigInterface && !in_array($field_storage_definition->getTypeProvider(), $providers)) {
|
||||
$storages_to_delete[$field_storage_definition->id()] = $field_storage_definition;
|
||||
}
|
||||
}
|
||||
return $storages_to_delete;
|
||||
|
||||
@@ -189,27 +189,26 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function preDelete(EntityStorageInterface $storage, array $fields) {
|
||||
$state = \Drupal::state();
|
||||
/** @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository */
|
||||
$deleted_fields_repository = \Drupal::service('entity_field.deleted_fields_repository');
|
||||
$entity_type_manager = \Drupal::entityTypeManager();
|
||||
|
||||
parent::preDelete($storage, $fields);
|
||||
// Keep the field definitions in the state storage so we can use them
|
||||
// later during field_purge_batch().
|
||||
$deleted_fields = $state->get('field.field.deleted') ?: [];
|
||||
|
||||
// Keep the field definitions in the deleted fields repository so we can use
|
||||
// them later during field_purge_batch().
|
||||
/** @var \Drupal\field\FieldConfigInterface $field */
|
||||
foreach ($fields as $field) {
|
||||
// Only mark a field for purging if there is data. Otherwise, just remove
|
||||
// it.
|
||||
$target_entity_storage = $entity_type_manager->getStorage($field->getTargetEntityTypeId());
|
||||
if (!$field->deleted && $target_entity_storage instanceof FieldableEntityStorageInterface && $target_entity_storage->countFieldData($field->getFieldStorageDefinition(), TRUE)) {
|
||||
$config = $field->toArray();
|
||||
$config['deleted'] = TRUE;
|
||||
$config['field_storage_uuid'] = $field->getFieldStorageDefinition()->uuid();
|
||||
$deleted_fields[$field->uuid()] = $config;
|
||||
$field = clone $field;
|
||||
$field->deleted = TRUE;
|
||||
$field->fieldStorage = NULL;
|
||||
$deleted_fields_repository->addFieldDefinition($field);
|
||||
}
|
||||
}
|
||||
$state->set('field.field.deleted', $deleted_fields);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -288,14 +287,30 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface {
|
||||
*/
|
||||
public function getFieldStorageDefinition() {
|
||||
if (!$this->fieldStorage) {
|
||||
$fields = $this->entityManager()->getFieldStorageDefinitions($this->entity_type);
|
||||
if (!isset($fields[$this->field_name])) {
|
||||
$field_storage_definition = NULL;
|
||||
|
||||
$field_storage_definitions = $this->entityManager()->getFieldStorageDefinitions($this->entity_type);
|
||||
if (isset($field_storage_definitions[$this->field_name])) {
|
||||
$field_storage_definition = $field_storage_definitions[$this->field_name];
|
||||
}
|
||||
// If this field has been deleted, try to find its field storage
|
||||
// definition in the deleted fields repository.
|
||||
elseif ($this->deleted) {
|
||||
$deleted_storage_definitions = \Drupal::service('entity_field.deleted_fields_repository')->getFieldStorageDefinitions();
|
||||
foreach ($deleted_storage_definitions as $deleted_storage_definition) {
|
||||
if ($deleted_storage_definition->getName() === $this->field_name) {
|
||||
$field_storage_definition = $deleted_storage_definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$field_storage_definition) {
|
||||
throw new FieldException("Attempt to create a field {$this->field_name} that does not exist on entity type {$this->entity_type}.");
|
||||
}
|
||||
if (!$fields[$this->field_name] instanceof FieldStorageConfigInterface) {
|
||||
if (!$field_storage_definition instanceof FieldStorageConfigInterface) {
|
||||
throw new FieldException("Attempt to create a configurable field of non-configurable field storage {$this->field_name}.");
|
||||
}
|
||||
$this->fieldStorage = $fields[$this->field_name];
|
||||
$this->fieldStorage = $field_storage_definition;
|
||||
}
|
||||
|
||||
return $this->fieldStorage;
|
||||
@@ -330,6 +345,13 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getUniqueIdentifier() {
|
||||
return $this->uuid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a field config entity based on the entity type and field name.
|
||||
*
|
||||
|
||||
@@ -398,7 +398,8 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function preDelete(EntityStorageInterface $storage, array $field_storages) {
|
||||
$state = \Drupal::state();
|
||||
/** @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository */
|
||||
$deleted_fields_repository = \Drupal::service('entity_field.deleted_fields_repository');
|
||||
|
||||
// Set the static flag so that we don't delete field storages whilst
|
||||
// deleting fields.
|
||||
@@ -407,23 +408,19 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
|
||||
// Delete or fix any configuration that is dependent, for example, fields.
|
||||
parent::preDelete($storage, $field_storages);
|
||||
|
||||
// Keep the field definitions in the state storage so we can use them later
|
||||
// during field_purge_batch().
|
||||
$deleted_storages = $state->get('field.storage.deleted') ?: [];
|
||||
// Keep the field storage definitions in the deleted fields repository so we
|
||||
// can use them later during field_purge_batch().
|
||||
/** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
|
||||
foreach ($field_storages as $field_storage) {
|
||||
// Only mark a field for purging if there is data. Otherwise, just remove
|
||||
// it.
|
||||
$target_entity_storage = \Drupal::entityTypeManager()->getStorage($field_storage->getTargetEntityTypeId());
|
||||
if (!$field_storage->deleted && $target_entity_storage instanceof FieldableEntityStorageInterface && $target_entity_storage->countFieldData($field_storage, TRUE)) {
|
||||
$config = $field_storage->toArray();
|
||||
$config['deleted'] = TRUE;
|
||||
$config['bundles'] = $field_storage->getBundles();
|
||||
$deleted_storages[$field_storage->uuid()] = $config;
|
||||
$storage_definition = clone $field_storage;
|
||||
$storage_definition->deleted = TRUE;
|
||||
$deleted_fields_repository->addFieldStorageDefinition($storage_definition);
|
||||
}
|
||||
}
|
||||
|
||||
$state->set('field.storage.deleted', $deleted_storages);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,16 +5,16 @@ namespace Drupal\field;
|
||||
use Drupal\Core\Config\Config;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\DeletedFieldsRepositoryInterface;
|
||||
use Drupal\Core\Field\FieldConfigStorageBase;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Component\Uuid\UuidInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
|
||||
/**
|
||||
* Controller class for fields.
|
||||
* Storage handler for field config.
|
||||
*/
|
||||
class FieldConfigStorage extends FieldConfigStorageBase {
|
||||
|
||||
@@ -25,13 +25,6 @@ class FieldConfigStorage extends FieldConfigStorageBase {
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The state keyvalue collection.
|
||||
*
|
||||
* @var \Drupal\Core\State\StateInterface
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* The field type plugin manager.
|
||||
*
|
||||
@@ -39,6 +32,13 @@ class FieldConfigStorage extends FieldConfigStorageBase {
|
||||
*/
|
||||
protected $fieldTypeManager;
|
||||
|
||||
/**
|
||||
* The deleted fields repository.
|
||||
*
|
||||
* @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface
|
||||
*/
|
||||
protected $deletedFieldsRepository;
|
||||
|
||||
/**
|
||||
* Constructs a FieldConfigStorage object.
|
||||
*
|
||||
@@ -52,16 +52,16 @@ class FieldConfigStorage extends FieldConfigStorageBase {
|
||||
* The language manager.
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\State\StateInterface $state
|
||||
* The state key value store.
|
||||
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
|
||||
* The field type plugin manager.
|
||||
* @param \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository
|
||||
* The deleted fields repository.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, StateInterface $state, FieldTypePluginManagerInterface $field_type_manager) {
|
||||
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, DeletedFieldsRepositoryInterface $deleted_fields_repository) {
|
||||
parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager);
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->state = $state;
|
||||
$this->fieldTypeManager = $field_type_manager;
|
||||
$this->deletedFieldsRepository = $deleted_fields_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,8 +74,8 @@ class FieldConfigStorage extends FieldConfigStorageBase {
|
||||
$container->get('uuid'),
|
||||
$container->get('language_manager'),
|
||||
$container->get('entity.manager'),
|
||||
$container->get('state'),
|
||||
$container->get('plugin.manager.field.field_type')
|
||||
$container->get('plugin.manager.field.field_type'),
|
||||
$container->get('entity_field.deleted_fields_repository')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ class FieldConfigStorage extends FieldConfigStorageBase {
|
||||
|
||||
// Get fields stored in configuration. If we are explicitly looking for
|
||||
// deleted fields only, this can be skipped, because they will be
|
||||
// retrieved from state below.
|
||||
// retrieved from the deleted fields repository below.
|
||||
if (empty($conditions['deleted'])) {
|
||||
if (isset($conditions['entity_type']) && isset($conditions['bundle']) && isset($conditions['field_name'])) {
|
||||
// Optimize for the most frequent case where we do have a specific ID.
|
||||
@@ -117,16 +117,13 @@ class FieldConfigStorage extends FieldConfigStorageBase {
|
||||
}
|
||||
}
|
||||
|
||||
// Merge deleted fields (stored in state) if needed.
|
||||
// Merge deleted fields from the deleted fields repository if needed.
|
||||
if ($include_deleted || !empty($conditions['deleted'])) {
|
||||
$deleted_fields = $this->state->get('field.field.deleted') ?: [];
|
||||
$deleted_storages = $this->state->get('field.storage.deleted') ?: [];
|
||||
foreach ($deleted_fields as $id => $config) {
|
||||
// If the field storage itself is deleted, inject it directly in the field.
|
||||
if (isset($deleted_storages[$config['field_storage_uuid']])) {
|
||||
$config['field_storage'] = $this->entityManager->getStorage('field_storage_config')->create($deleted_storages[$config['field_storage_uuid']]);
|
||||
$deleted_field_definitions = $this->deletedFieldsRepository->getFieldDefinitions();
|
||||
foreach ($deleted_field_definitions as $id => $field_definition) {
|
||||
if ($field_definition instanceof FieldConfigInterface) {
|
||||
$fields[$id] = $field_definition;
|
||||
}
|
||||
$fields[$id] = $this->create($config);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,14 +34,6 @@ interface FieldStorageConfigInterface extends ConfigEntityInterface, FieldStorag
|
||||
*/
|
||||
public function getBundles();
|
||||
|
||||
/**
|
||||
* Returns whether the field is deleted or not.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the field is deleted.
|
||||
*/
|
||||
public function isDeleted();
|
||||
|
||||
/**
|
||||
* Checks if the field storage can be deleted.
|
||||
*
|
||||
|
||||
@@ -7,15 +7,15 @@ use Drupal\Core\Config\Entity\ConfigEntityStorage;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\DeletedFieldsRepositoryInterface;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
|
||||
/**
|
||||
* Controller class for "field storage" configuration entities.
|
||||
* Storage handler for "field storage" configuration entities.
|
||||
*/
|
||||
class FieldStorageConfigStorage extends ConfigEntityStorage {
|
||||
|
||||
@@ -33,13 +33,6 @@ class FieldStorageConfigStorage extends ConfigEntityStorage {
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The state keyvalue collection.
|
||||
*
|
||||
* @var \Drupal\Core\State\StateInterface
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* The field type plugin manager.
|
||||
*
|
||||
@@ -47,6 +40,13 @@ class FieldStorageConfigStorage extends ConfigEntityStorage {
|
||||
*/
|
||||
protected $fieldTypeManager;
|
||||
|
||||
/**
|
||||
* The deleted fields repository.
|
||||
*
|
||||
* @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface
|
||||
*/
|
||||
protected $deletedFieldsRepository;
|
||||
|
||||
/**
|
||||
* Constructs a FieldStorageConfigStorage object.
|
||||
*
|
||||
@@ -62,17 +62,17 @@ class FieldStorageConfigStorage extends ConfigEntityStorage {
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\State\StateInterface $state
|
||||
* The state key value store.
|
||||
* @param \Drupal\Component\Plugin\PluginManagerInterface\FieldTypePluginManagerInterface $field_type_manager
|
||||
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
|
||||
* The field type plugin manager.
|
||||
* @param \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository
|
||||
* The deleted fields repository.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, StateInterface $state, FieldTypePluginManagerInterface $field_type_manager) {
|
||||
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, FieldTypePluginManagerInterface $field_type_manager, DeletedFieldsRepositoryInterface $deleted_fields_repository) {
|
||||
parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager);
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->state = $state;
|
||||
$this->fieldTypeManager = $field_type_manager;
|
||||
$this->deletedFieldsRepository = $deleted_fields_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,8 +86,8 @@ class FieldStorageConfigStorage extends ConfigEntityStorage {
|
||||
$container->get('language_manager'),
|
||||
$container->get('entity.manager'),
|
||||
$container->get('module_handler'),
|
||||
$container->get('state'),
|
||||
$container->get('plugin.manager.field.field_type')
|
||||
$container->get('plugin.manager.field.field_type'),
|
||||
$container->get('entity_field.deleted_fields_repository')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ class FieldStorageConfigStorage extends ConfigEntityStorage {
|
||||
|
||||
// Get field storages living in configuration. If we are explicitly looking
|
||||
// for deleted storages only, this can be skipped, because they will be
|
||||
// retrieved from state below.
|
||||
// retrieved from the deleted fields repository below.
|
||||
if (empty($conditions['deleted'])) {
|
||||
if (isset($conditions['entity_type']) && isset($conditions['field_name'])) {
|
||||
// Optimize for the most frequent case where we do have a specific ID.
|
||||
@@ -117,11 +117,14 @@ class FieldStorageConfigStorage extends ConfigEntityStorage {
|
||||
}
|
||||
}
|
||||
|
||||
// Merge deleted field storages (living in state) if needed.
|
||||
// Merge deleted field storage definitions from the deleted fields
|
||||
// repository if needed.
|
||||
if ($include_deleted || !empty($conditions['deleted'])) {
|
||||
$deleted_storages = $this->state->get('field.storage.deleted') ?: [];
|
||||
foreach ($deleted_storages as $id => $config) {
|
||||
$storages[$id] = $this->create($config);
|
||||
$deleted_storage_definitions = $this->deletedFieldsRepository->getFieldStorageDefinitions();
|
||||
foreach ($deleted_storage_definitions as $id => $field_storage_definition) {
|
||||
if ($field_storage_definition instanceof FieldStorageConfigInterface) {
|
||||
$storages[$id] = $field_storage_definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process;
|
||||
|
||||
@trigger_error('The field_type_defaults process plugin is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use d6_field_type_defaults or d7_field_type_defaults instead. See https://www.drupal.org/node/2944589.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\field\Plugin\migrate\process\d6\FieldTypeDefaults as D6FieldTypeDefaults;
|
||||
|
||||
/**
|
||||
* BC Layer.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "field_type_defaults"
|
||||
* )
|
||||
*
|
||||
* @deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.x.
|
||||
* Use d6_field_type_defaults or d7_field_type_defaults instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2944589
|
||||
*/
|
||||
class FieldTypeDefaults extends D6FieldTypeDefaults {}
|
||||
@@ -11,7 +11,7 @@ use Drupal\migrate\Row;
|
||||
* Gives us a chance to set per field defaults.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "field_type_defaults"
|
||||
* id = "d6_field_type_defaults"
|
||||
* )
|
||||
*/
|
||||
class FieldTypeDefaults extends ProcessPluginBase {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process\d7;
|
||||
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Gives us a chance to set per field defaults.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "d7_field_type_defaults"
|
||||
* )
|
||||
*/
|
||||
class FieldTypeDefaults extends ProcessPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
if (is_array($value) && isset($value[1])) {
|
||||
return $value[1];
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_field",
|
||||
* source_module = "field"
|
||||
* source_module = "field_sql_storage"
|
||||
* )
|
||||
*/
|
||||
class Field extends DrupalSqlBase {
|
||||
|
||||
@@ -1,249 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\Boolean;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests boolean field functionality.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class BooleanFieldTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = [
|
||||
'entity_test',
|
||||
'field_ui',
|
||||
'options',
|
||||
'field_test_boolean_access_denied',
|
||||
];
|
||||
|
||||
/**
|
||||
* A field to use in this test class.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldStorageConfig
|
||||
*/
|
||||
protected $fieldStorage;
|
||||
|
||||
/**
|
||||
* The field used in this test class.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldConfig
|
||||
*/
|
||||
protected $field;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'view test entity',
|
||||
'administer entity_test content',
|
||||
'administer entity_test form display',
|
||||
'administer entity_test fields',
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests boolean field.
|
||||
*/
|
||||
public function testBooleanField() {
|
||||
$on = $this->randomMachineName();
|
||||
$off = $this->randomMachineName();
|
||||
$label = $this->randomMachineName();
|
||||
|
||||
// Create a field with settings to validate.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$this->fieldStorage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'boolean',
|
||||
]);
|
||||
$this->fieldStorage->save();
|
||||
$this->field = FieldConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'entity_test',
|
||||
'label' => $label,
|
||||
'required' => TRUE,
|
||||
'settings' => [
|
||||
'on_label' => $on,
|
||||
'off_label' => $off,
|
||||
],
|
||||
]);
|
||||
$this->field->save();
|
||||
|
||||
// Create a form display for the default form mode.
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($field_name, [
|
||||
'type' => 'boolean_checkbox',
|
||||
])
|
||||
->save();
|
||||
// Create a display for the full view mode.
|
||||
entity_get_display('entity_test', 'entity_test', 'full')
|
||||
->setComponent($field_name, [
|
||||
'type' => 'boolean',
|
||||
])
|
||||
->save();
|
||||
|
||||
// Display creation form.
|
||||
$this->drupalGet('entity_test/add');
|
||||
$this->assertFieldByName("{$field_name}[value]", '', 'Widget found.');
|
||||
$this->assertText($this->field->label(), 'Uses field label by default.');
|
||||
$this->assertNoRaw($on, 'Does not use the "On" label.');
|
||||
|
||||
// Submit and ensure it is accepted.
|
||||
$edit = [
|
||||
"{$field_name}[value]" => 1,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
|
||||
|
||||
// Verify that boolean value is displayed.
|
||||
$entity = EntityTest::load($id);
|
||||
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
|
||||
$content = $display->build($entity);
|
||||
$this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
|
||||
$this->assertRaw('<div class="field__item">' . $on . '</div>');
|
||||
|
||||
// Test with "On" label option.
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($field_name, [
|
||||
'type' => 'boolean_checkbox',
|
||||
'settings' => [
|
||||
'display_label' => FALSE,
|
||||
]
|
||||
])
|
||||
->save();
|
||||
|
||||
$this->drupalGet('entity_test/add');
|
||||
$this->assertFieldByName("{$field_name}[value]", '', 'Widget found.');
|
||||
$this->assertRaw($on);
|
||||
$this->assertNoText($this->field->label());
|
||||
|
||||
// Test if we can change the on label.
|
||||
$on = $this->randomMachineName();
|
||||
$edit = [
|
||||
'settings[on_label]' => $on,
|
||||
];
|
||||
$this->drupalPostForm('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name, $edit, t('Save settings'));
|
||||
// Check if we see the updated labels in the creation form.
|
||||
$this->drupalGet('entity_test/add');
|
||||
$this->assertRaw($on);
|
||||
|
||||
// Go to the form display page and check if the default settings works as
|
||||
// expected.
|
||||
$fieldEditUrl = 'entity_test/structure/entity_test/form-display';
|
||||
$this->drupalGet($fieldEditUrl);
|
||||
|
||||
// Click on the widget settings button to open the widget settings form.
|
||||
$this->drupalPostAjaxForm(NULL, [], $field_name . "_settings_edit");
|
||||
|
||||
$this->assertText(
|
||||
'Use field label instead of the "On label" as label',
|
||||
t('Display setting checkbox available.')
|
||||
);
|
||||
|
||||
// Enable setting.
|
||||
$edit = ['fields[' . $field_name . '][settings_edit_form][settings][display_label]' => 1];
|
||||
$this->drupalPostAjaxForm(NULL, $edit, $field_name . "_plugin_settings_update");
|
||||
$this->drupalPostForm(NULL, NULL, 'Save');
|
||||
|
||||
// Go again to the form display page and check if the setting
|
||||
// is stored and has the expected effect.
|
||||
$this->drupalGet($fieldEditUrl);
|
||||
$this->assertText('Use field label: Yes', 'Checking the display settings checkbox updated the value.');
|
||||
|
||||
$this->drupalPostAjaxForm(NULL, [], $field_name . "_settings_edit");
|
||||
$this->assertText(
|
||||
'Use field label instead of the "On label" as label',
|
||||
t('Display setting checkbox is available')
|
||||
);
|
||||
$this->assertFieldByXPath(
|
||||
'*//input[starts-with(@id, "edit-fields-' . $field_name . '-settings-edit-form-settings-display-label") and @value="1"]',
|
||||
TRUE,
|
||||
t('Display label changes label of the checkbox')
|
||||
);
|
||||
|
||||
// Test the boolean field settings.
|
||||
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name);
|
||||
$this->assertFieldById('edit-settings-on-label', $on);
|
||||
$this->assertFieldById('edit-settings-off-label', $off);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test field access.
|
||||
*/
|
||||
public function testFormAccess() {
|
||||
$on = 'boolean_on';
|
||||
$off = 'boolean_off';
|
||||
$label = 'boolean_label';
|
||||
$field_name = 'boolean_name';
|
||||
$this->fieldStorage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'boolean',
|
||||
]);
|
||||
$this->fieldStorage->save();
|
||||
$this->field = FieldConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'entity_test',
|
||||
'label' => $label,
|
||||
'settings' => [
|
||||
'on_label' => $on,
|
||||
'off_label' => $off,
|
||||
],
|
||||
]);
|
||||
$this->field->save();
|
||||
|
||||
// Create a form display for the default form mode.
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($field_name, [
|
||||
'type' => 'boolean_checkbox',
|
||||
])
|
||||
->save();
|
||||
|
||||
// Create a display for the full view mode.
|
||||
entity_get_display('entity_test', 'entity_test', 'full')
|
||||
->setComponent($field_name, [
|
||||
'type' => 'boolean',
|
||||
])
|
||||
->save();
|
||||
|
||||
// Display creation form.
|
||||
$this->drupalGet('entity_test/add');
|
||||
$this->assertFieldByName("{$field_name}[value]");
|
||||
|
||||
// Should be posted OK.
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
|
||||
|
||||
// Tell the test module to disable access to the field.
|
||||
\Drupal::state()->set('field.test_boolean_field_access_field', $field_name);
|
||||
$this->drupalGet('entity_test/add');
|
||||
// Field should not be there anymore.
|
||||
$this->assertNoFieldByName("{$field_name}[value]");
|
||||
// Should still be able to post the form.
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -94,6 +94,8 @@ class EntityReferenceAdminTest extends WebTestBase {
|
||||
|
||||
// The base handler settings should be displayed.
|
||||
$entity_type_id = 'node';
|
||||
// Check that the type label is correctly displayed.
|
||||
$this->assertText('Content type');
|
||||
$bundles = $this->container->get('entity_type.bundle.info')->getBundleInfo($entity_type_id);
|
||||
foreach ($bundles as $bundle_name => $bundle_info) {
|
||||
$this->assertFieldByName('settings[handler_settings][target_bundles][' . $bundle_name . ']');
|
||||
|
||||
@@ -114,7 +114,7 @@ class EntityReferenceFileUploadTest extends WebTestBase {
|
||||
$this->drupalLogin($user1);
|
||||
|
||||
$test_file = current($this->drupalGetTestFiles('text'));
|
||||
$edit['files[file_field_0]'] = drupal_realpath($test_file->uri);
|
||||
$edit['files[file_field_0]'] = \Drupal::service('file_system')->realpath($test_file->uri);
|
||||
$this->drupalPostForm('node/add/' . $this->referencingType, $edit, 'Upload');
|
||||
$this->assertResponse(200);
|
||||
$edit = [
|
||||
|
||||
@@ -113,6 +113,9 @@ class FormTest extends FieldTestBase {
|
||||
// Check that hook_field_widget_form_alter() does not believe this is the
|
||||
// default value form.
|
||||
$this->assertNoText('From hook_field_widget_form_alter(): Default form is true.', 'Not default value form in hook_field_widget_form_alter().');
|
||||
// Check that hook_field_widget_form_alter() does not believe this is the
|
||||
// default value form.
|
||||
$this->assertNoText('From hook_field_widget_multivalue_form_alter(): Default form is true.', 'Not default value form in hook_field_widget_form_alter().');
|
||||
|
||||
// Submit with invalid value (field-level validation).
|
||||
$edit = [
|
||||
@@ -634,4 +637,64 @@ class FormTest extends FieldTestBase {
|
||||
$this->assertEscaped("<script>alert('a configurable field');</script>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests hook_field_widget_multivalue_form_alter().
|
||||
*/
|
||||
public function testFieldFormMultipleWidgetAlter() {
|
||||
$this->widgetAlterTest('hook_field_widget_multivalue_form_alter', 'test_field_widget_multiple');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests hook_field_widget_multivalue_form_alter() with single value elements.
|
||||
*/
|
||||
public function testFieldFormMultipleWidgetAlterSingleValues() {
|
||||
$this->widgetAlterTest('hook_field_widget_multivalue_form_alter', 'test_field_widget_multiple_single_value');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests hook_field_widget_multivalue_WIDGET_TYPE_form_alter().
|
||||
*/
|
||||
public function testFieldFormMultipleWidgetTypeAlter() {
|
||||
$this->widgetAlterTest('hook_field_widget_multivalue_WIDGET_TYPE_form_alter', 'test_field_widget_multiple');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests hook_field_widget_multivalue_WIDGET_TYPE_form_alter() with single value elements.
|
||||
*/
|
||||
public function testFieldFormMultipleWidgetTypeAlterSingleValues() {
|
||||
$this->widgetAlterTest('hook_field_widget_multivalue_WIDGET_TYPE_form_alter', 'test_field_widget_multiple_single_value');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests widget alter hooks for a given hook name.
|
||||
*/
|
||||
protected function widgetAlterTest($hook, $widget) {
|
||||
// Create a field with fixed cardinality, configure the form to use a
|
||||
// "multiple" widget.
|
||||
$field_storage = $this->fieldStorageMultiple;
|
||||
$field_name = $field_storage['field_name'];
|
||||
$this->field['field_name'] = $field_name;
|
||||
FieldStorageConfig::create($field_storage)->save();
|
||||
FieldConfig::create($this->field)->save();
|
||||
|
||||
// Set a flag in state so that the hook implementations will run.
|
||||
\Drupal::state()->set("field_test.widget_alter_test", [
|
||||
'hook' => $hook,
|
||||
'field_name' => $field_name,
|
||||
'widget' => $widget,
|
||||
]);
|
||||
entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
|
||||
->setComponent($field_name, [
|
||||
'type' => $widget,
|
||||
])
|
||||
->save();
|
||||
|
||||
$this->drupalGet('entity_test/add');
|
||||
$this->assertUniqueText("From $hook(): prefix on $field_name parent element.");
|
||||
if ($widget === 'test_field_widget_multiple_single_value') {
|
||||
$suffix_text = "From $hook(): suffix on $field_name child element.";
|
||||
$this->assertEqual($field_storage['cardinality'], substr_count($this->getTextContent(), $suffix_text), "'$suffix_text' was found {$field_storage['cardinality']} times using widget $widget");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class StringFieldTest extends WebTestBase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->webUser = $this->drupalCreateUser(['view test entity', 'administer entity_test content']);
|
||||
$this->webUser = $this->drupalCreateUser(['view test entity', 'administer entity_test content', 'access content']);
|
||||
$this->drupalLogin($this->webUser);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ abstract class FieldTestBase extends ViewTestBase {
|
||||
*/
|
||||
public $fields;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
// Ensure the page node type exists.
|
||||
NodeType::create([
|
||||
|
||||
@@ -38,8 +38,8 @@ class FieldUITest extends FieldTestBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->account = $this->drupalCreateUser(['administer views']);
|
||||
$this->drupalLogin($this->account);
|
||||
|
||||
@@ -41,8 +41,8 @@ class HandlerFieldFieldTest extends FieldTestBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
// Setup basic fields.
|
||||
$this->setUpFieldStorages(3);
|
||||
|
||||
@@ -86,7 +86,7 @@ class reEnableModuleFieldTest extends WebTestBase {
|
||||
$this->assertRaw('<a href="tel:123456789">');
|
||||
|
||||
// Test that the module can't be uninstalled from the UI while there is data
|
||||
// for it's fields.
|
||||
// for its fields.
|
||||
$admin_user = $this->drupalCreateUser(['access administration pages', 'administer modules']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalGet('admin/modules/uninstall');
|
||||
|
||||
Reference in New Issue
Block a user