Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KernelTestBaseNG™ #1

Closed
wants to merge 102 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
67c051d
Issue #2300015 by olli | anavarre: Fixed PluginNotFoundException on u…
alexpott Jul 21, 2014
49f4fdd
Issue #1962846 by andypost, Wim Leers, InternetDevels: Use field inst…
alexpott Jul 21, 2014
ef4e932
Issue #2301313 by pwolanin, dawehner, Wim Leers, effulgentsia, kgoel,…
alexpott Jul 21, 2014
7c226d1
Issue #2289183 by anavarre, xjm: Fixed Temporarily increase D8 memory…
Jul 22, 2014
d526f0d
Issue #2212081 by dawehner: Remove views optional handler handling.
Jul 22, 2014
dc7a542
Issue #2300297 by er.pushpinderrana, joshi.rohit100 | lmeurs: Hook_fi…
alexpott Jul 22, 2014
d29adc8
Issue #2297947 by amitgoyal, andrewmacpherson: Clean up API docs for …
alexpott Jul 22, 2014
f959ce8
Issue #733054 followup by lussoluca: Fixed Watchdog logging of all se…
alexpott Jul 22, 2014
afd7cf9
Issue #2307481 by cs_shadow: Fix typos and add missing properties in …
alexpott Jul 22, 2014
77b6167
Issue #2305807 by amitgoyal, olli | jhodgdon: Fixed Clicking "Add" fi…
alexpott Jul 22, 2014
ceb595d
Issue #2305293 by olli: Fixed Wrong #states for "Restrict to the sele…
alexpott Jul 22, 2014
b38632b
Issue #2287031 by lokeoke | hass: Change lcase translatable strings t…
alexpott Jul 23, 2014
8b9d600
Issue #2230997 by dinarcon, jiv_e, StevenPatz, jstoller, cs_shadow, L…
alexpott Jul 23, 2014
fad8529
Issue #2298923 by mparker17, er.pushpinderrana: Fixed Bartik's field-…
alexpott Jul 23, 2014
f1ed247
Issue #2293773 by Gábor Hojtsy, alexpott, effulgentsia, penyaskito, h…
Jul 23, 2014
7ff4e73
Issue #2305827 by pwolanin: Fixed doc fixes for LockBackendInterface.
alexpott Jul 23, 2014
d7f03d3
Issue #1986418 followup by LewisNyman: Update textfield & textarea st…
alexpott Jul 23, 2014
6fb3b61
Issue #2307231 by olli | Charles Belov: Fixed Deleted views display n…
alexpott Jul 23, 2014
5776d98
Issue #2279395 by alexpott, mradcliffe, bzrudi71: Fixed The PostgreSQ…
dbuytaert Jul 23, 2014
808098a
Issue #2279395 by alexpott, mradcliffe, plach, bzrudi71: Fixed The Po…
Jul 24, 2014
77a9ea0
Issue #1800614 by falcon03, mgifford, LinL | jessebeach: Improve the …
alexpott Jul 24, 2014
1ddfac8
Issue #2112247 by sihv, dgroene, aalamaki, Dennis Walgaard, mErilaine…
alexpott Jul 24, 2014
0872feb
Issue #2308545 by penyaskito: Typo in LanguageNegotiationUrlTest.
alexpott Jul 24, 2014
5783e08
Issue #2149197 by penyaskito, mikey_p, vijaycs85, herom: Replace form…
alexpott Jul 24, 2014
64387e5
Issue #2078473 by blueminds | Berdir: Added Use entity access API for…
alexpott Jul 24, 2014
36faf4e
Issue #2302617 by dawehner, chx | Crell: Define a standard mechaism f…
alexpott Jul 24, 2014
16a429e
Issue #2307125 by webchick: Fixed HTML double-escaping in EditorImage…
alexpott Jul 24, 2014
baacf9d
Issue #2306515 by lokeoke | yukare: Fixed HTML double-escaping in CKE…
alexpott Jul 24, 2014
b2c4388
Issue #2308971 by herom: Fixed Quickfix: Two schema files are not nam…
alexpott Jul 24, 2014
2691c42
Issue #2299699 by lokeoke | jhodgdon: Some classes need @ingroup adde…
alexpott Jul 24, 2014
13ed88f
Issue #2308967 by martin107: Fix spelling errors
jhodgdon-drp Jul 24, 2014
c3f272d
Issue #2308707 by eojthebrave: Fix annotation class reference in fiel…
jhodgdon-drp Jul 24, 2014
5b2361c
Issue #2308699 by eojthebrave: Fix documentation of WidgetBaseInterfa…
jhodgdon-drp Jul 24, 2014
f4d8d09
Issue #2308695 by eojthebrave: Fix typo
jhodgdon-drp Jul 24, 2014
2909a5d
Issue #2290275 by chx: Add information to migrate plugin classes and …
jhodgdon-drp Jul 24, 2014
ef50f95
Issue #2306455 by hussainweb, alexpott, er.pushpinderrana: Fixed Conf…
Jul 25, 2014
f0c9d00
Issue #2033211 by jwilson3, LewisNyman, sqndr, tim.plunkett, JamesLef…
alexpott Jul 25, 2014
4e84738
Issue #2300347 by vijaycs85, joshi.rohit100 | robertdbailey: Fixed Re…
alexpott Jul 25, 2014
032757a
Issue #2309175 by Wim Leers: Fixed HTML double-escaping in Text Edito…
alexpott Jul 25, 2014
59c3c97
Issue #2305023 by dawehner: Fixed Rename getCancelRoute to getCancelUrl.
alexpott Jul 25, 2014
900784f
Issue #2217943 by jhodgdon, Wim Leers: Views cannot be filtered by la…
dbuytaert Jul 25, 2014
d1f6df1
Issue #2281443 by ultimike, TommyK: Fixed D6 Workflow settings -> D8 …
dbuytaert Jul 25, 2014
a678efd
Issue #2308707 by eojthebrave: Field widget @defgroup references wron…
dbuytaert Jul 25, 2014
4b69e23
Issue #2304461 by sun: KernelTestBaseNG™.
sun Jul 16, 2014
aaddd49
Performance: Use shared fixtures for all tests in a class.
sun Jul 16, 2014
eec4019
Fixed $this->container is not synced across kernel rebuilds.
sun Jul 17, 2014
0a77284
Fixed container rebuild does not persist request stack.
sun Jul 17, 2014
51b0624
Added tearDownAfterClass() + assert enableModules() post-conditions.
sun Jul 17, 2014
0a91639
Reverted shared fixtures approach; leverage compiled container instead.
sun Jul 17, 2014
319b4ee
Relocated KernelTestBase methods.
sun Jul 17, 2014
edbf457
Replaced cloned ContainerBuilder copy with actually compiled Container.
sun Jul 18, 2014
b874572
Added alternative setUp() variant of cloned, empty ContainerBuilder.
sun Jul 18, 2014
04a7415
Enable drupal_render() + _theme().
sun Jul 18, 2014
d1aa142
Make Drupal\simpletest\Tests\KernelTestBaseTest pass against new Kern…
sun Jul 18, 2014
1b8cdce
Performance: Enable public static $modules only once per test class.
sun Jul 19, 2014
cff2b38
Added random generator utility methods via new RandomGeneratorTrait.
sun Jul 19, 2014
0613382
Updated extension/config/schema test helper methods for PHPUnit.
sun Jul 19, 2014
19e2657
DrupalKernel::setContainer() should be compatible with ContainerAware…
sun Jul 20, 2014
3a5586b
Fixed DependencySerializationTrait breaks if there is no container.
sun Jul 20, 2014
f4b08da
Added missing TestBase methods.
sun Jul 20, 2014
8fcead2
Added second Kernel test suite.
sun Jul 20, 2014
222d148
Fixed various kernel tests.
sun Jul 20, 2014
c053b75
Removed $configDirectories. (to be reimplemented as opt-in)
sun Jul 20, 2014
a5e758f
Fixed error handling for non-existing public static $modules.
sun Jul 20, 2014
cec6f23
Fixed precompiled container leaks into tests.
sun Jul 20, 2014
135c7e8
Performance: Only use precompiled container if there are > 1 test met…
sun Jul 20, 2014
44a51e9
Added Travis-CI configuration. Limited to unit tests.
sun Jul 20, 2014
d78f445
Added Kernel test suite.
sun Jul 21, 2014
3289147
Implemented vfsStream.
sun Jul 22, 2014
d4e7f2c
Temporarily use process isolation for Kernel test suite.
sun Jul 22, 2014
9842332
Fixed PHP Notice: Undefined index: $GLOBALS['base_url'].
sun Jul 22, 2014
7b5013b
[interim] Fix process isolation infinitely blocks on Windows.
sun Jul 24, 2014
874edcb
[interim] Fix standard IO streams are not defined in process isolation.
sun Jul 24, 2014
8e7f17d
Avoid namespace discovery for tests running in isolation.
sun Jul 24, 2014
a9a3c95
[interim] Fix isolated child process leaks into parent process.
sun Jul 26, 2014
e9ba4ff
Issue #2306539 by sun: Fixed FieldUnitTestBase::createFieldWithInstan…
sun Jul 21, 2014
21df5d5
Fixed stream wrapper registration + cleanup.
sun Jul 26, 2014
47640aa
Limit process isolation to fixed list of fatal tests.
sun Jul 26, 2014
e852d3e
Fixed bogus tests.
sun Jul 26, 2014
9a2a959
[BC] Fixed former containerBuild() is not invoked.
sun Jul 26, 2014
7f0d80c
[interim-fixup] PDOException::getCode() string vs. int mismatch.
sun Jul 26, 2014
4689be3
Fixed bogus visibility of test methods.
sun Jul 27, 2014
af45b2f
Trigger deprecation warnings instead of halting tests.
sun Jul 27, 2014
f13dded
Fixed stream wrapper registration in File API tests.
sun Jul 27, 2014
cf41f6a
Removed obsolete --debug option. ♥
sun Jul 27, 2014
179a4d1
Fixed bogus tests.
sun Jul 28, 2014
cbc28a1
Fixed legacy assertTrue() should pass for non-empty non-Boolean values.
sun Jul 28, 2014
2a4d30f
[fixup] Better registerStreamWrapper() deprecated warning message.
sun Jul 28, 2014
c0bf92c
Temporarily re-enable $configImporter.
sun Jul 28, 2014
e1c4d84
Fixed Flood database storage is no longer magically available.
sun Jul 28, 2014
7e1e2f2
[fixup] file_get_stream_wrappers() static can get reset during a test.
sun Jul 31, 2014
8f0257f
Warn if a test defeats performance optimizations.
sun Jul 31, 2014
e955376
Use Queue Memory backend by default.
sun Jul 31, 2014
4a9f4d1
[FIXME] system_cron() hard-codes database queries on 'queue'.
sun Jul 31, 2014
15917f7
[debug] ConfigImporter hides errors.
sun Jul 31, 2014
52990f7
[FIXME] PhpStorageFactory does not support stream wrappers.
sun Jul 31, 2014
4cfb725
Fixed Database tests require multiple connections.
sun Jul 31, 2014
a2962d0
[fixup] Added @todo for APC(u).
sun Jul 31, 2014
1d8576a
Fixed bogus tests.
sun Jul 31, 2014
b6dc957
[FIXME] drupal_rewrite_settings() does not support stream wrappers.
sun Jul 31, 2014
4f00f4c
Fixed bogus expectations in ModuleHandlerTest.
sun Jul 31, 2014
b7a9018
[fixup] Disable XDebug for Kernel test suite.
sun Jul 31, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: php

php:
- 5.4

#before_script:
# - composer self-update
# # @todo Enable APC(u) extension.

script:
# @todo Re-enable. For now, we know that it works.
#- phpunit -v -c core --testsuite Unit
# Disable XDebug after running unit tests.
- phpenv config-rm xdebug.ini
- php --version
# @todo Update to new stable once all fixes are in upstream.
- ./core/vendor/phpunit/phpunit/phpunit -v -c core --testsuite Kernel
1 change: 1 addition & 0 deletions core/config/install/menu_link.static.overrides.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
definitions: []
27 changes: 27 additions & 0 deletions core/config/schema/core.menu.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

menu_link.static.overrides:
type: mapping
label: 'Menu link overrides'
mapping:
definitions:
type: sequence
label: Definitions
sequence:
- type: mapping
label: Definition
mapping:
menu_name:
type: string
label: 'Menu name'
parent:
type: string
label: 'Parent'
weight:
type: integer
label: 'Weight'
expanded:
type: boolean
label: 'Expanded'
hidden:
type: boolean
label: 'Hidden'
5 changes: 5 additions & 0 deletions core/core.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ services:
parent: default_plugin_manager
plugin.cache_clearer:
class: Drupal\Core\Plugin\CachedDiscoveryClearer
paramconverter.menu_link:
class: Drupal\Core\ParamConverter\MenuLinkPluginConverter
tags:
- { name: paramconverter }
arguments: ['@plugin.manager.menu.link']
menu.tree_storage:
class: Drupal\Core\Menu\MenuTreeStorage
arguments: ['@database', '@cache.menu', 'menu_tree']
Expand Down
6 changes: 3 additions & 3 deletions core/includes/batch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ function _batch_process() {
'@total' => $total,
'@current' => floor($current),
'@percentage' => $percentage,
'@elapsed' => format_interval($elapsed / 1000),
'@elapsed' => \Drupal::service('date')->formatInterval($elapsed / 1000),
// If possible, estimate remaining processing time.
'@estimate' => ($current > 0) ? format_interval(($elapsed * ($total - $current) / $current) / 1000) : '-',
'@estimate' => ($current > 0) ? \Drupal::service('date')->formatInterval(($elapsed * ($total - $current) / $current) / 1000) : '-',
);
$message = strtr($progress_message, $values);
if (!empty($task_message)) {
Expand Down Expand Up @@ -410,7 +410,7 @@ function _batch_finished() {
if (is_callable($batch_set['finished'])) {
$queue = _batch_queue($batch_set);
$operations = $queue->getAllItems();
call_user_func_array($batch_set['finished'], array($batch_set['success'], $batch_set['results'], $operations, format_interval($batch_set['elapsed'] / 1000)));
call_user_func_array($batch_set['finished'], array($batch_set['success'], $batch_set['results'], $operations, \Drupal::service('date')->formatInterval($batch_set['elapsed'] / 1000)));
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions core/includes/bootstrap.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ const DRUPAL_MINIMUM_PHP = '5.4.2';

/**
* Minimum recommended value of PHP memory_limit.
*
* @todo Reduce the memory required to install on some environments in
* https://www.drupal.org/node/2289201 and then decrease this limit.
*/
const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = '32M';
const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = '64M';

/**
* Error reporting level: display no errors.
Expand Down Expand Up @@ -173,7 +176,9 @@ const DRUPAL_EXTENSION_NAME_MAX_LENGTH = 50;
* @see http://php.net/manual/reserved.variables.server.php
* @see http://php.net/manual/function.time.php
*/
define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
if (!defined('REQUEST_TIME')) {
define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
}

/**
* Regular expression to match PHP function names.
Expand Down Expand Up @@ -201,7 +206,9 @@ const CONFIG_STAGING_DIRECTORY = 'staging';
*
* This strips two levels of directories off the current directory.
*/
define('DRUPAL_ROOT', dirname(dirname(__DIR__)));
if (!defined('DRUPAL_ROOT')) {
define('DRUPAL_ROOT', dirname(dirname(__DIR__)));
}

/**
* Returns the appropriate configuration directory.
Expand Down
1 change: 1 addition & 0 deletions core/includes/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ function drupal_get_feeds() {
* not available, the current path.
*
* @see current_path()
* @ingroup form_api
*/
function drupal_get_destination() {
$destination = &drupal_static(__FUNCTION__);
Expand Down
17 changes: 10 additions & 7 deletions core/includes/file.inc
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ function file_munge_filename($filename, $extensions, $alerts = TRUE) {
// Remove any null bytes. See http://php.net/manual/en/security.filesystem.nullbytes.php
$filename = str_replace(chr(0), '', $filename);

$whitelist = array_unique(explode(' ', trim($extensions)));
$whitelist = array_unique(explode(' ', strtolower(trim($extensions))));

// Split the filename up by periods. The first part becomes the basename
// the last part the final extension.
Expand All @@ -893,7 +893,7 @@ function file_munge_filename($filename, $extensions, $alerts = TRUE) {
// of allowed extensions.
foreach ($filename_parts as $filename_part) {
$new_filename .= '.' . $filename_part;
if (!in_array($filename_part, $whitelist) && preg_match("/^[a-zA-Z]{2,5}\d?$/", $filename_part)) {
if (!in_array(strtolower($filename_part), $whitelist) && preg_match("/^[a-zA-Z]{2,5}\d?$/", $filename_part)) {
$new_filename .= '_';
}
}
Expand Down Expand Up @@ -1297,16 +1297,19 @@ function file_upload_max_size() {
* @param $mapping
* An optional map of extensions to their mimetypes, in the form:
* - 'mimetypes': a list of mimetypes, keyed by an identifier,
* - 'extensions': the mapping itself, an associative array in which
* the key is the extension (lowercase) and the value is the mimetype
* identifier. If $mapping is NULL file_mimetype_mapping() is called.
* - 'extensions': the mapping itself, an associative array in which the key
* is the extension (lowercase) and the value is the mimetype identifier.
*
* @return
* The internet media type registered for the extension or
* application/octet-stream for unknown extensions.
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal::service('file.mime_type.guesser')->guess($uri).
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. Calls are
* passed on to a new file.mime_type.guesser service, and the $mapping
* parameter is ignored. Use
* \Drupal::service('file.mime_type.guesser')->guess($uri).
*
* @see \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::guess()
*/
function file_get_mimetype($uri, $mapping = NULL) {
return \Drupal::service('file.mime_type.guesser')->guess($uri);
Expand Down
4 changes: 2 additions & 2 deletions core/includes/install.inc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) {
}
$variable_names['$'. $setting] = $setting;
}
$contents = file_get_contents(DRUPAL_ROOT . '/' . $settings_file);
$contents = file_get_contents($settings_file);
if ($contents !== FALSE) {
// Initialize the contents for the settings.php file if it is empty.
if (trim($contents) === '') {
Expand Down Expand Up @@ -314,7 +314,7 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) {
}

// Write the new settings file.
if (file_put_contents(DRUPAL_ROOT . '/' . $settings_file, $buffer) === FALSE) {
if (file_put_contents($settings_file, $buffer) === FALSE) {
throw new Exception(t('Failed to modify %settings. Verify the file permissions.', array('%settings' => $settings_file)));
}
else {
Expand Down
15 changes: 13 additions & 2 deletions core/lib/Drupal/Component/Discovery/YamlDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ class YamlDiscovery implements DiscoverableInterface {
*/
protected $directories = array();

/**
* Array of all parsed files, keyed by filename.
*
* Especially during kernel tests, YAML files are re-parsed often.
*
* @var array
*/
protected static $parsedFiles = array();

/**
* Constructs a YamlDiscovery object.
*
Expand All @@ -48,9 +57,11 @@ public function __construct($name, array $directories) {
public function findAll() {
$all = array();
foreach ($this->findFiles() as $provider => $file) {
$all[$provider] = Yaml::decode(file_get_contents($file));
if (!isset(static::$parsedFiles[$file])) {
static::$parsedFiles[$file] = Yaml::decode(file_get_contents($file));
}
$all[$provider] = static::$parsedFiles[$file];
}

return $all;
}

Expand Down
2 changes: 1 addition & 1 deletion core/lib/Drupal/Core/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function get($key = '') {
* {@inheritdoc}
*/
public function setData(array $data) {
$this->data = $data;
parent::setData($data);
$this->resetOverriddenData();
return $this;
}
Expand Down
32 changes: 32 additions & 0 deletions core/lib/Drupal/Core/Config/ConfigBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ public function get($key = '') {
*
* @return $this
* The configuration object.
*
* @throws \Drupal\Core\Config\ConfigValueException
* If any key in $data in any depth contains a dot.
*/
public function setData(array $data) {
$this->validateKeys($data);
$this->data = $data;
return $this;
}
Expand All @@ -176,10 +180,16 @@ public function setData(array $data) {
*
* @return $this
* The configuration object.
*
* @throws \Drupal\Core\Config\ConfigValueException
* If $value is an array and any of its keys in any depth contains a dot.
*/
public function set($key, $value) {
// The dot/period is a reserved character; it may appear between keys, but
// not within keys.
if (is_array($value)) {
$this->validateKeys($value);
}
$parts = explode('.', $key);
if (count($parts) == 1) {
$this->data[$key] = $value;
Expand All @@ -190,6 +200,28 @@ public function set($key, $value) {
return $this;
}

/**
* Validates all keys in a passed in config array structure.
*
* @param array $data
* Configuration array structure.
*
* @return null
*
* @throws \Drupal\Core\Config\ConfigValueException
* If any key in $data in any depth contains a dot.
*/
protected function validateKeys(array $data) {
foreach ($data as $key => $value) {
if (strpos($key, '.') !== FALSE) {
throw new ConfigValueException(String::format('@key key contains a dot which is not supported.', array('@key' => $key)));
}
if (is_array($value)) {
$this->validateKeys($value);
}
}
}

/**
* Unsets a value in this configuration object.
*
Expand Down
1 change: 1 addition & 0 deletions core/lib/Drupal/Core/Config/ConfigImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public function __construct(StorageComparerInterface $storage_comparer, EventDis
* The message to log.
*/
public function logError($message) {
trigger_error($message, E_USER_ERROR);
$this->errors[] = $message;
}

Expand Down
13 changes: 13 additions & 0 deletions core/lib/Drupal/Core/Config/ConfigValueException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* @file
* Contains \Drupal\Core\Config\ConfigValueException.
*/

namespace Drupal\Core\Config;

/**
* Exception thrown when config object values are invalid.
*/
class ConfigValueException extends ConfigException {}
34 changes: 27 additions & 7 deletions core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,15 @@ public function deleteRevision($revision_id) {
}

/**
* {@inheritdoc}
* Returns the prefix used to create the configuration name.
*
* The prefix consists of the config prefix from the entity type plus a dot
* for separating from the ID.
*
* @return string
* The full configuration prefix, for example 'views.view.'.
*/
public function getConfigPrefix() {
protected function getPrefix() {
return $this->entityType->getConfigPrefix() . '.';
}

Expand All @@ -149,7 +155,7 @@ public static function getIDFromConfigName($config_name, $config_prefix) {
* {@inheritdoc}
*/
protected function doLoadMultiple(array $ids = NULL) {
$prefix = $this->getConfigPrefix();
$prefix = $this->getPrefix();

// Get the names of the configuration entities we are going to load.
if ($ids === NULL) {
Expand Down Expand Up @@ -187,7 +193,7 @@ protected function doCreate(array $values) {
*/
protected function doDelete($entities) {
foreach ($entities as $entity) {
$config = $this->configFactory->get($this->getConfigPrefix() . $entity->id());
$config = $this->configFactory->get($this->getPrefix() . $entity->id());
$config->delete();
}
}
Expand Down Expand Up @@ -224,7 +230,7 @@ public function save(EntityInterface $entity) {
*/
protected function doSave($id, EntityInterface $entity) {
$is_new = $entity->isNew();
$prefix = $this->getConfigPrefix();
$prefix = $this->getPrefix();
if ($id !== $entity->id()) {
// Renaming a config object needs to cater for:
// - Storage needs to access the original object.
Expand All @@ -237,19 +243,33 @@ protected function doSave($id, EntityInterface $entity) {
}

// Retrieve the desired properties and set them in config.
foreach ($entity->toArray() as $key => $value) {
$record = $this->mapToStorageRecord($entity);
foreach ($record as $key => $value) {
$config->set($key, $value);
}
$config->save();

return $is_new ? SAVED_NEW : SAVED_UPDATED;
}

/**
* Maps from an entity object to the storage record.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object.
*
* @return array
* The record to store.
*/
protected function mapToStorageRecord(EntityInterface $entity) {
return $entity->toArray();
}

/**
* {@inheritdoc}
*/
protected function has($id, EntityInterface $entity) {
$prefix = $this->getConfigPrefix();
$prefix = $this->getPrefix();
$config = $this->configFactory->get($prefix . $id);
return !$config->isNew();
}
Expand Down
Loading