Unverified Commit 6b54e953 authored by alexpott's avatar alexpott
Browse files

Issue #2778917 by kiamlaluno, jungle, elaman, dawehner, alexpott, tvb,...

Issue #2778917 by kiamlaluno, jungle, elaman, dawehner, alexpott, tvb, vadim.hirbu, ravi.shankar, quietone: Use the second parameter of \Drupal::state()->get() instead of checking the method didn't return any value
parent ed11f4f8
......@@ -1565,7 +1565,7 @@ function install_profile_modules(&$install_state) {
// as those will not be handled by the module installer.
install_core_entity_type_definitions();
$modules = \Drupal::state()->get('install_profile_modules') ?: [];
$modules = \Drupal::state()->get('install_profile_modules', []);
$files = \Drupal::service('extension.list.module')->getList();
\Drupal::state()->delete('install_profile_modules');
......
......@@ -91,7 +91,7 @@ public function optimize(array $css_assets) {
// Drupal contrib can override this default CSS aggregator to keep the same
// grouping, optimizing and dumping, but change the strategy that is used to
// determine when the aggregate should be rebuilt (e.g. mtime, HTTPS …).
$map = $this->state->get('drupal_css_cache_files') ?: [];
$map = $this->state->get('drupal_css_cache_files', []);
$css_assets = [];
foreach ($css_groups as $order => $css_group) {
// We have to return a single asset, not a group of assets. It is now up
......
......@@ -91,7 +91,7 @@ public function optimize(array $js_assets) {
// Drupal contrib can override this default JS aggregator to keep the same
// grouping, optimizing and dumping, but change the strategy that is used to
// determine when the aggregate should be rebuilt (e.g. mtime, HTTPS …).
$map = $this->state->get('system.js_cache_files') ?: [];
$map = $this->state->get('system.js_cache_files', []);
$js_assets = [];
foreach ($js_groups as $order => $js_group) {
// We have to return a single asset, not a group of assets. It is now up
......
......@@ -21,7 +21,7 @@ class TestMailCollector extends PhpMail implements MailInterface {
* {@inheritdoc}
*/
public function mail(array $message) {
$captured_emails = \Drupal::state()->get('system.test_mail_collector') ?: [];
$captured_emails = \Drupal::state()->get('system.test_mail_collector', []);
$captured_emails[] = $message;
\Drupal::state()->set('system.test_mail_collector', $captured_emails);
......
......@@ -111,7 +111,7 @@ function ckeditor_library_info_alter(&$libraries, $extension) {
// Pass Drupal's JS cache-busting string via settings along to CKEditor.
// @see http://docs.ckeditor.com/#!/api/CKEDITOR-property-timestamp
if ($extension === 'ckeditor' && isset($libraries['drupal.ckeditor'])) {
$query_string = \Drupal::state()->get('system.css_js_query_string') ?: '0';
$query_string = \Drupal::state()->get('system.css_js_query_string', '0');
$libraries['drupal.ckeditor']['drupalSettings']['ckeditor']['timestamp'] = $query_string;
}
}
......@@ -143,7 +143,7 @@ public function _testColor($theme, $test_values) {
$config->set('css.preprocess', 1);
$config->save();
$this->drupalGet('<front>');
$stylesheets = \Drupal::state()->get('drupal_css_cache_files') ?: [];
$stylesheets = \Drupal::state()->get('drupal_css_cache_files', []);
$stylesheet_content = '';
foreach ($stylesheets as $uri) {
$stylesheet_content .= implode("\n", file(\Drupal::service('file_system')->realpath($uri)));
......
......@@ -179,7 +179,7 @@ public function getRankingInfo() {
// values in as strings instead of numbers in complex expressions like
// this.
'score' => '2.0 - 2.0 / (1.0 + ces.comment_count * (ROUND(:comment_scale, 4)))',
'arguments' => [':comment_scale' => \Drupal::state()->get('comment.node_comment_statistics_scale') ?: 0],
'arguments' => [':comment_scale' => \Drupal::state()->get('comment.node_comment_statistics_scale', 0)],
],
];
}
......
......@@ -121,7 +121,7 @@ public function testImportDeleteUninstall() {
$this->rebuildContainer();
$this->assertFalse(\Drupal::moduleHandler()->moduleExists('telephone'));
$this->assertNull(\Drupal::service('entity.repository')->loadEntityByUuid('field_storage_config', $field_storage->uuid()), 'The telephone field has been deleted by the configuration synchronization');
$deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: [];
$deleted_storages = \Drupal::state()->get('field.storage.deleted', []);
$this->assertFalse(isset($deleted_storages[$field_storage->uuid()]), 'Telephone field has been completed removed from the system.');
$this->assertFalse(isset($deleted_storages[$field_storage->uuid()]), 'Text field has been completed removed from the system.');
}
......
......@@ -107,14 +107,14 @@ public function testImportDelete() {
$this->assertIdentical($active->listAll($field_config_name_2b), []);
// Check that only the first storage definition is preserved in state.
$deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: [];
$deleted_storages = \Drupal::state()->get('field.storage.deleted', []);
$this->assertTrue(isset($deleted_storages[$field_storage_uuid]));
$this->assertFalse(isset($deleted_storages[$field_storage_uuid_2]));
// Purge field data, and check that the storage definition has been
// completely removed once the data is purged.
field_purge_batch(10);
$deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: [];
$deleted_storages = \Drupal::state()->get('field.storage.deleted', []);
$this->assertTrue(empty($deleted_storages), 'Fields are deleted');
}
......
......@@ -101,7 +101,7 @@ public function testImportDeleteUninstall() {
$this->assertFalse(\Drupal::moduleHandler()->moduleExists('telephone'));
$this->assertNull(\Drupal::service('entity.repository')->loadEntityByUuid('field_storage_config', $field_storage->uuid()), 'The test field has been deleted by the configuration synchronization');
$deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: [];
$deleted_storages = \Drupal::state()->get('field.storage.deleted', []);
$this->assertFalse(isset($deleted_storages[$field_storage->uuid()]), 'Telephone field has been completed removed from the system.');
$this->assertTrue(isset($deleted_storages[$unrelated_field_storage->uuid()]), 'Unrelated field not purged by configuration synchronization.');
}
......@@ -150,7 +150,7 @@ public function testImportAlreadyDeletedUninstall() {
unset($core_extension['module']['telephone']);
$sync->write('core.extension', $core_extension);
$deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: [];
$deleted_storages = \Drupal::state()->get('field.storage.deleted', []);
$this->assertTrue(isset($deleted_storages[$field_storage_uuid]), 'Field has been deleted and needs purging before configuration synchronization.');
$steps = $this->configImporter()->initialize();
......@@ -161,7 +161,7 @@ public function testImportAlreadyDeletedUninstall() {
$this->configImporter()->import();
$this->assertFalse(\Drupal::moduleHandler()->moduleExists('telephone'));
$deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: [];
$deleted_storages = \Drupal::state()->get('field.storage.deleted', []);
$this->assertFalse(isset($deleted_storages[$field_storage_uuid]), 'Field has been completed removed from the system.');
}
......
......@@ -56,7 +56,7 @@ function file_test_reset() {
* @see file_test_reset()
*/
function file_test_get_calls($op) {
$results = \Drupal::state()->get('file_test.results') ?: [];
$results = \Drupal::state()->get('file_test.results', []);
return $results[$op];
}
......@@ -69,7 +69,7 @@ function file_test_get_calls($op) {
* passed to each call.
*/
function file_test_get_all_calls() {
return \Drupal::state()->get('file_test.results') ?: [];
return \Drupal::state()->get('file_test.results', []);
}
/**
......@@ -86,7 +86,7 @@ function file_test_get_all_calls() {
*/
function _file_test_log_call($op, $args) {
if (\Drupal::state()->get('file_test.count_hook_invocations', TRUE)) {
$results = \Drupal::state()->get('file_test.results') ?: [];
$results = \Drupal::state()->get('file_test.results', []);
$results[$op][] = $args;
\Drupal::state()->set('file_test.results', $results);
}
......@@ -105,7 +105,7 @@ function _file_test_log_call($op, $args) {
* @see file_test_reset()
*/
function _file_test_get_return($op) {
$return = \Drupal::state()->get('file_test.return') ?: [$op => NULL];
$return = \Drupal::state()->get('file_test.return', [$op => NULL]);
return $return[$op];
}
......@@ -121,7 +121,7 @@ function _file_test_get_return($op) {
* @see file_test_reset()
*/
function file_test_set_return($op, $value) {
$return = \Drupal::state()->get('file_test.return') ?: [];
$return = \Drupal::state()->get('file_test.return', []);
$return[$op] = $value;
\Drupal::state()->set('file_test.return', $return);
}
......
......@@ -8,7 +8,7 @@
use Drupal\image\ImageStyleInterface;
function image_module_test_file_download($uri) {
$default_uri = \Drupal::state()->get('image.test_file_download') ?: FALSE;
$default_uri = \Drupal::state()->get('image.test_file_download', FALSE);
if ($default_uri == $uri) {
return ['X-Image-Owned-By' => 'image_module_test'];
}
......
......@@ -32,7 +32,7 @@ function locale_uninstall() {
$locale_js_directory = 'public://' . $config->get('javascript.directory');
if (is_dir($locale_js_directory)) {
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: [];
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript', []);
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
foreach ($locale_javascripts as $langcode => $file_suffix) {
......
......@@ -537,7 +537,7 @@ function locale_js_translate(array $files = []) {
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
$dir = 'public://' . \Drupal::config('locale.settings')->get('javascript.directory');
$parsed = \Drupal::state()->get('system.javascript_parsed') ?: [];
$parsed = \Drupal::state()->get('system.javascript_parsed', []);
$new_files = FALSE;
foreach ($files as $filepath) {
......@@ -575,7 +575,7 @@ function locale_js_translate(array $files = []) {
}
// Add the translation JavaScript file to the page.
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: [];
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript', []);
$translation_file = NULL;
if (!empty($files) && !empty($locale_javascripts[$language_interface->getId()])) {
// Add the translation JavaScript file to the page.
......@@ -1195,7 +1195,7 @@ function _locale_parse_js_file($filepath) {
* New content of the 'system.javascript_parsed' variable.
*/
function _locale_invalidate_js($langcode = NULL) {
$parsed = \Drupal::state()->get('system.javascript_parsed') ?: [];
$parsed = \Drupal::state()->get('system.javascript_parsed', []);
if (empty($langcode)) {
// Invalidate all languages.
......@@ -1269,7 +1269,7 @@ function _locale_rebuild_js($langcode = NULL) {
// Delete old file, if we have no translations anymore, or a different file to
// be saved.
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: [];
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript', []);
$changed_hash = !isset($locale_javascripts[$language->getId()]) || ($locale_javascripts[$language->getId()] != $data_hash);
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
......
......@@ -158,7 +158,7 @@ public function getHeader() {
*/
public function setHeader(PoHeader $header) {
$this->header = $header;
$locale_plurals = \Drupal::state()->get('locale.translation.plurals') ?: [];
$locale_plurals = \Drupal::state()->get('locale.translation.plurals', []);
// Check for options.
$options = $this->getOptions();
......
......@@ -263,7 +263,7 @@ public function testJavaScriptTranslation() {
// Trigger JavaScript translation parsing and building.
_locale_rebuild_js($langcode);
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: [];
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript', []);
$js_file = 'public://' . $config->get('javascript.directory') . '/' . $langcode . '_' . $locale_javascripts[$langcode] . '.js';
$this->assertFileExists($js_file);
......
......@@ -999,7 +999,7 @@ function node_query_node_access_alter(AlterableInterface $query) {
*/
function node_access_needs_rebuild($rebuild = NULL) {
if (!isset($rebuild)) {
return \Drupal::state()->get('node.node_access_needs_rebuild') ?: FALSE;
return \Drupal::state()->get('node.node_access_needs_rebuild', FALSE);
}
elseif ($rebuild) {
\Drupal::state()->set('node.node_access_needs_rebuild', TRUE);
......
......@@ -56,7 +56,7 @@ function node_access_test_node_grants($account, $op) {
$grants['node_access_test'] = [8888, 8889];
}
$no_access_uid = \Drupal::state()->get('node_access_test.no_access_uid') ?: 0;
$no_access_uid = \Drupal::state()->get('node_access_test.no_access_uid', 0);
if ($op == 'view' && $account->id() == $no_access_uid) {
$grants['node_access_all'] = [0];
}
......
......@@ -155,7 +155,7 @@ function node_test_node_update(NodeInterface $node) {
*/
function node_test_entity_view_mode_alter(&$view_mode, EntityInterface $entity, $context) {
// Only alter the view mode if we are on the test callback.
$change_view_mode = \Drupal::state()->get('node_test_change_view_mode') ?: '';
$change_view_mode = \Drupal::state()->get('node_test_change_view_mode', '');
if ($change_view_mode) {
$view_mode = $change_view_mode;
}
......
......@@ -116,7 +116,7 @@ public function deleteViews($id) {
* {@inheritdoc}
*/
public function resetDayCount() {
$statistics_timestamp = $this->state->get('statistics.day_timestamp') ?: 0;
$statistics_timestamp = $this->state->get('statistics.day_timestamp', 0);
if (($this->getRequestTime() - $statistics_timestamp) >= 86400) {
$this->state->set('statistics.day_timestamp', $this->getRequestTime());
$this->connection->update('node_counter')
......
......@@ -106,7 +106,7 @@ function statistics_ranking() {
// values in as strings instead of numbers in complex expressions like
// this.
'score' => '2.0 - 2.0 / (1.0 + node_counter.totalcount * (ROUND(:statistics_scale, 4)))',
'arguments' => [':statistics_scale' => \Drupal::state()->get('statistics.node_counter_scale') ?: 0],
'arguments' => [':statistics_scale' => \Drupal::state()->get('statistics.node_counter_scale', 0)],
],
];
}
......
......@@ -194,7 +194,7 @@ function entity_test_entity_base_field_info_alter(&$fields, EntityTypeInterface
* 'entity_test'.
*/
function entity_test_create_bundle($bundle, $text = NULL, $entity_type = 'entity_test') {
$bundles = \Drupal::state()->get($entity_type . '.bundles') ?: [$entity_type => ['label' => 'Entity Test Bundle']];
$bundles = \Drupal::state()->get($entity_type . '.bundles', [$entity_type => ['label' => 'Entity Test Bundle']]);
$bundles += [$bundle => ['label' => $text ? $text : $bundle]];
\Drupal::state()->set($entity_type . '.bundles', $bundles);
......@@ -211,7 +211,7 @@ function entity_test_create_bundle($bundle, $text = NULL, $entity_type = 'entity
* 'entity_test'.
*/
function entity_test_delete_bundle($bundle, $entity_type = 'entity_test') {
$bundles = \Drupal::state()->get($entity_type . '.bundles') ?: [$entity_type => ['label' => 'Entity Test Bundle']];
$bundles = \Drupal::state()->get($entity_type . '.bundles', [$entity_type => ['label' => 'Entity Test Bundle']]);
unset($bundles[$bundle]);
\Drupal::state()->set($entity_type . '.bundles', $bundles);
......@@ -226,7 +226,7 @@ function entity_test_entity_bundle_info() {
$entity_types = \Drupal::entityTypeManager()->getDefinitions();
foreach ($entity_types as $entity_type_id => $entity_type) {
if ($entity_type->getProvider() == 'entity_test' && $entity_type_id != 'entity_test_with_bundle') {
$bundles[$entity_type_id] = \Drupal::state()->get($entity_type_id . '.bundles') ?: [$entity_type_id => ['label' => 'Entity Test Bundle']];
$bundles[$entity_type_id] = \Drupal::state()->get($entity_type_id . '.bundles', [$entity_type_id => ['label' => 'Entity Test Bundle']]);
}
}
return $bundles;
......
......@@ -114,7 +114,7 @@ protected function mustResave() {
*/
public function delete() {
parent::delete();
$deleted_languages = \Drupal::state()->get('entity_test.delete.' . $this->getFieldDefinition()->getName()) ?: [];
$deleted_languages = \Drupal::state()->get('entity_test.delete.' . $this->getFieldDefinition()->getName(), []);
$deleted_languages[] = $this->getLangcode();
\Drupal::state()->set('entity_test.delete.' . $this->getFieldDefinition()->getName(), $deleted_languages);
}
......
......@@ -164,7 +164,7 @@ public function save($destination) {
* @see \Drupal\Tests\system\Functional\Image\ToolkitTestBase::imageTestGetAllCalls()
*/
protected function logCall($op, $args) {
$results = $this->state->get('image_test.results') ?: [];
$results = $this->state->get('image_test.results', []);
$results[$op][] = $args;
// A call to apply is also logged under its operation name whereby the
// array of arguments are logged as separate arguments, this because at the
......
......@@ -87,7 +87,7 @@ function system_test_system_info_alter(&$info, Extension $file, $type) {
function system_test_page_attachments(array &$page) {
// Used by FrontPageTestCase to get the results of
// \Drupal::service('path.matcher')->isFrontPage().
$frontpage = \Drupal::state()->get('system_test.front_page_output') ?: 0;
$frontpage = \Drupal::state()->get('system_test.front_page_output', 0);
if ($frontpage && \Drupal::service('path.matcher')->isFrontPage()) {
\Drupal::messenger()->addStatus(t('On front page.'));
}
......
......@@ -185,7 +185,7 @@ public function testModuleEnableOrder() {
$this->assertModules(['color', 'config', 'help'], TRUE);
// Check the actual order which is saved by module_test_modules_enabled().
$module_order = \Drupal::state()->get('module_test.install_order') ?: [];
$module_order = \Drupal::state()->get('module_test.install_order', []);
$this->assertIdentical($module_order, $expected_order);
}
......
......@@ -115,7 +115,7 @@ public function testDependencyResolution() {
$this->assertTrue($this->moduleHandler()->moduleExists('color'), 'Module installation with dependencies succeeded.');
// Verify that the modules were enabled in the correct order.
$module_order = \Drupal::state()->get('module_test.install_order') ?: [];
$module_order = \Drupal::state()->get('module_test.install_order', []);
$this->assertEqual($module_order, ['help', 'config', 'color']);
// Uninstall all three modules explicitly, but in the incorrect order,
......@@ -127,7 +127,7 @@ public function testDependencyResolution() {
foreach (['color', 'config', 'help'] as $module) {
$this->assertEqual(drupal_get_installed_schema_version($module), SCHEMA_UNINSTALLED, "$module module was uninstalled.");
}
$uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order') ?: [];
$uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order', []);
$this->assertEqual($uninstalled_modules, ['color', 'config', 'help'], 'Modules were uninstalled in the correct order.');
// Enable Color module again, which should enable both the Config module and
......@@ -146,7 +146,7 @@ public function testDependencyResolution() {
$this->assertTrue($this->moduleHandler()->moduleExists('color'), 'Module installation with version dependencies succeeded.');
// Finally, verify that the modules were enabled in the correct order.
$enable_order = \Drupal::state()->get('module_test.install_order') ?: [];
$enable_order = \Drupal::state()->get('module_test.install_order', []);
$this->assertIdentical($enable_order, ['help', 'config', 'color']);
}
......@@ -180,7 +180,7 @@ public function testUninstallProfileDependency() {
$this->assertEquals(drupal_get_installed_schema_version($non_dependency), SCHEMA_UNINSTALLED, "$non_dependency module was uninstalled.");
// Verify that the installation profile itself was not uninstalled.
$uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order') ?: [];
$uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order', []);
$this->assertContains($non_dependency, $uninstalled_modules, "$non_dependency module is in the list of uninstalled modules.");
$this->assertNotContains($profile, $uninstalled_modules, 'The installation profile is not in the list of uninstalled modules.');
......
......@@ -72,7 +72,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$last_markup = [
'#theme' => 'update_last_check',
'#last' => $this->state->get('update.last_check') ?: 0,
'#last' => $this->state->get('update.last_check', 0),
];
$form['last_check'] = [
'#markup' => \Drupal::service('renderer')->render($last_markup),
......
......@@ -171,7 +171,7 @@ function update_cron() {
$update_config = \Drupal::config('update.settings');
$frequency = $update_config->get('check.interval_days');
$interval = 60 * 60 * 24 * $frequency;
$last_check = \Drupal::state()->get('update.last_check') ?: 0;
$last_check = \Drupal::state()->get('update.last_check', 0);
if ((REQUEST_TIME - $last_check) > $interval) {
// If the configured update interval has elapsed, we want to invalidate
// the data for all projects, attempt to re-fetch, and trigger any
......@@ -184,7 +184,7 @@ function update_cron() {
// missing data, and if so, try to fetch the data.
update_get_available(TRUE);
}
$last_email_notice = \Drupal::state()->get('update.last_email_notification') ?: 0;
$last_email_notice = \Drupal::state()->get('update.last_email_notification', 0);
if ((REQUEST_TIME - $last_email_notice) > $interval) {
// If configured time between notifications elapsed, send email about
// updates possibly available.
......
......@@ -22,7 +22,7 @@
function template_preprocess_update_report(&$variables) {
$data = $variables['data'];
$last = \Drupal::state()->get('update.last_check') ?: 0;
$last = \Drupal::state()->get('update.last_check', 0);
$variables['last_checked'] = [
'#theme' => 'update_last_check',
......
......@@ -554,7 +554,7 @@ public function getRouteName() {
* {@inheritdoc}
*/
public function getAlteredRouteNames() {
return $this->state->get('views.view_route_names') ?: [];
return $this->state->get('views.view_route_names', []);
}
/**
......
......@@ -152,7 +152,7 @@ protected function imageTestReset() {
* parameters passed to each call.
*/
protected function imageTestGetAllCalls() {
return \Drupal::state()->get('image_test.results') ?: [];
return \Drupal::state()->get('image_test.results', []);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment