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')
......
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