Commit 52e3eec6 authored by xjm's avatar xjm
Browse files

Issue #2776975 by joelpittet, dawehner, tim.plunkett, xjm, pfrenssen: March 3,...

Issue #2776975 by joelpittet, dawehner, tim.plunkett, xjm, pfrenssen: March 3, 2017: Convert core to array syntax coding standards for Drupal 8.3.x RC phase
parent 3aba956a
......@@ -116,10 +116,10 @@ function authorize_access_allowed(Request $request) {
drupal_set_message($results['page_message']['message'], $results['page_message']['type']);
}
$content['authorize_report'] = array(
$content['authorize_report'] = [
'#theme' => 'authorize_report',
'#messages' => $results['messages'],
);
];
if (is_array($results['tasks'])) {
$links = $results['tasks'];
......@@ -148,11 +148,11 @@ function authorize_access_allowed(Request $request) {
];
}
$content['next_steps'] = array(
$content['next_steps'] = [
'#theme' => 'item_list',
'#items' => $links,
'#title' => t('Next steps'),
);
];
}
// If a batch is running, let it run.
elseif ($request->query->has('batch')) {
......@@ -189,9 +189,9 @@ function authorize_access_allowed(Request $request) {
}
$bare_html_page_renderer = \Drupal::service('bare_html_page_renderer');
$response = $bare_html_page_renderer->renderBarePage($content, $page_title, 'maintenance_page', array(
$response = $bare_html_page_renderer->renderBarePage($content, $page_title, 'maintenance_page', [
'#show_messages' => $show_messages,
));
]);
if (!$is_allowed) {
$response->setStatusCode(403);
}
......
......@@ -2103,39 +2103,39 @@ function hook_mail_alter(&$message) {
function hook_mail($key, &$message, $params) {
$account = $params['account'];
$context = $params['context'];
$variables = array(
$variables = [
'%site_name' => \Drupal::config('system.site')->get('name'),
'%username' => $account->getDisplayName(),
);
];
if ($context['hook'] == 'taxonomy') {
$entity = $params['entity'];
$vocabulary = Vocabulary::load($entity->id());
$variables += array(
$variables += [
'%term_name' => $entity->name,
'%term_description' => $entity->description,
'%term_id' => $entity->id(),
'%vocabulary_name' => $vocabulary->label(),
'%vocabulary_description' => $vocabulary->getDescription(),
'%vocabulary_id' => $vocabulary->id(),
);
];
}
// Node-based variable translation is only available if we have a node.
if (isset($params['node'])) {
/** @var \Drupal\node\NodeInterface $node */
$node = $params['node'];
$variables += array(
$variables += [
'%uid' => $node->getOwnerId(),
'%url' => $node->url('canonical', array('absolute' => TRUE)),
'%url' => $node->url('canonical', ['absolute' => TRUE]),
'%node_type' => node_get_type_label($node),
'%title' => $node->getTitle(),
'%teaser' => $node->teaser,
'%body' => $node->body,
);
];
}
$subject = strtr($context['subject'], $variables);
$body = strtr($context['message'], $variables);
$message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
$message['subject'] .= str_replace(["\r", "\n"], '', $subject);
$message['body'][] = MailFormatHelper::htmlToText($body);
}
......
......@@ -50,7 +50,7 @@ function _batch_page(Request $request) {
// Register database update for the end of processing.
drupal_register_shutdown_function('_batch_shutdown');
$build = array();
$build = [];
// Add batch-specific libraries.
foreach ($batch['sets'] as $batch_set) {
......@@ -94,7 +94,7 @@ function _batch_do() {
// Perform actual processing.
list($percentage, $message, $label) = _batch_process();
return new JsonResponse(array('status' => TRUE, 'percentage' => $percentage, 'message' => $message, 'label' => $label));
return new JsonResponse(['status' => TRUE, 'percentage' => $percentage, 'message' => $message, 'label' => $label]);
}
/**
......@@ -130,9 +130,9 @@ function _batch_progress_page() {
// it. While this causes invalid HTML, the same would be true if we didn't,
// as content is not allowed to appear after </html> anyway.
$bare_html_page_renderer = \Drupal::service('bare_html_page_renderer');
$response = $bare_html_page_renderer->renderBarePage(['#markup' => $fallback], $current_set['title'], 'maintenance_page', array(
$response = $bare_html_page_renderer->renderBarePage(['#markup' => $fallback], $current_set['title'], 'maintenance_page', [
'#show_messages' => FALSE,
));
]);
// Just use the content of the response.
$fallback = $response->getContent();
......@@ -159,26 +159,26 @@ function _batch_progress_page() {
$url = $batch['url']->toString(TRUE)->getGeneratedUrl();
$build = array(
$build = [
'#theme' => 'progress_bar',
'#percent' => $percentage,
'#message' => array('#markup' => $message),
'#message' => ['#markup' => $message],
'#label' => $label,
'#attached' => array(
'html_head' => array(
array(
array(
'#attached' => [
'html_head' => [
[
[
// Redirect through a 'Refresh' meta tag if JavaScript is disabled.
'#tag' => 'meta',
'#noscript' => TRUE,
'#attributes' => array(
'#attributes' => [
'http-equiv' => 'Refresh',
'content' => '0; URL=' . $url,
),
),
],
],
'batch_progress_meta_refresh',
),
),
],
],
// Adds JavaScript code and settings for clients where JavaScript is enabled.
'drupalSettings' => [
'batch' => [
......@@ -187,11 +187,11 @@ function _batch_progress_page() {
'uri' => $url,
],
],
'library' => array(
'library' => [
'core/drupal.batch',
),
),
);
],
],
];
return $build;
}
......@@ -243,13 +243,13 @@ function _batch_process() {
list($callback, $args) = $item->data;
// Build the 'context' array and execute the function call.
$batch_context = array(
$batch_context = [
'sandbox' => &$current_set['sandbox'],
'results' => &$current_set['results'],
'finished' => &$finished,
'message' => &$task_message,
);
call_user_func_array($callback, array_merge($args, array(&$batch_context)));
];
call_user_func_array($callback, array_merge($args, [&$batch_context]));
if ($finished >= 1) {
// Make sure this step is not counted twice when computing $current.
......@@ -257,7 +257,7 @@ function _batch_process() {
// Remove the processed operation and clear the sandbox.
$queue->deleteItem($item);
$current_set['count']--;
$current_set['sandbox'] = array();
$current_set['sandbox'] = [];
}
}
......@@ -312,7 +312,7 @@ function _batch_process() {
$current = $total - $remaining + $finished;
$percentage = _batch_api_percentage($total, $current);
$elapsed = isset($current_set['elapsed']) ? $current_set['elapsed'] : 0;
$values = array(
$values = [
'@remaining' => $remaining,
'@total' => $total,
'@current' => floor($current),
......@@ -320,13 +320,13 @@ function _batch_process() {
'@elapsed' => \Drupal::service('date.formatter')->formatInterval($elapsed / 1000),
// If possible, estimate remaining processing time.
'@estimate' => ($current > 0) ? \Drupal::service('date.formatter')->formatInterval(($elapsed * ($total - $current) / $current) / 1000) : '-',
);
];
$message = strtr($progress_message, $values);
if (!empty($task_message)) {
$label = $task_message;
}
return array($percentage, $message, $label);
return [$percentage, $message, $label];
}
else {
// If we are not in progressive mode, the entire batch has been processed.
......@@ -385,7 +385,7 @@ function _batch_next_set() {
// We use our stored copies of $form and $form_state to account for
// possible alterations by previous form submit handlers.
$complete_form = &$batch['form_state']->getCompleteForm();
call_user_func_array($callback, array(&$complete_form, &$batch['form_state']));
call_user_func_array($callback, [&$complete_form, &$batch['form_state']]);
}
return TRUE;
}
......@@ -411,7 +411,7 @@ function _batch_finished() {
if (is_callable($batch_set['finished'])) {
$queue = _batch_queue($batch_set);
$operations = $queue->getAllItems();
$batch_set_result = call_user_func_array($batch_set['finished'], array($batch_set['success'], $batch_set['results'], $operations, \Drupal::service('date.formatter')->formatInterval($batch_set['elapsed'] / 1000)));
$batch_set_result = call_user_func_array($batch_set['finished'], [$batch_set['success'], $batch_set['results'], $operations, \Drupal::service('date.formatter')->formatInterval($batch_set['elapsed'] / 1000)]);
// If a batch 'finished' callback requested a redirect after the batch
// is complete, save that for later use. If more than one batch set
// returned a redirect, the last one is used.
......
......@@ -197,7 +197,7 @@ function config_get_config_directory($type) {
function drupal_get_filename($type, $name, $filename = NULL) {
// The location of files will not change during the request, so do not use
// drupal_static().
static $files = array();
static $files = [];
// Type 'core' only exists to simplify application-level logic; it always maps
// to the /core directory, whereas $name is ignored. It is only requested via
......@@ -213,7 +213,7 @@ function drupal_get_filename($type, $name, $filename = NULL) {
$type = 'module';
}
if (!isset($files[$type])) {
$files[$type] = array();
$files[$type] = [];
}
if (isset($filename)) {
......@@ -233,11 +233,11 @@ function drupal_get_filename($type, $name, $filename = NULL) {
// system_rebuild_module_data() and
// \Drupal\Core\Extension\ThemeHandlerInterface::rebuildThemeData().
if (!isset($files[$type][$name]) && \Drupal::hasService('state')) {
$files[$type] += \Drupal::state()->get('system.' . $type . '.files', array());
$files[$type] += \Drupal::state()->get('system.' . $type . '.files', []);
}
// If still unknown, create a user-level error message.
if (!isset($files[$type][$name])) {
trigger_error(SafeMarkup::format('The following @type is missing from the file system: @name', array('@type' => $type, '@name' => $name)), E_USER_WARNING);
trigger_error(SafeMarkup::format('The following @type is missing from the file system: @name', ['@type' => $type, '@name' => $name]), E_USER_WARNING);
}
}
......@@ -301,7 +301,7 @@ function drupal_get_path($type, $name) {
*
* @ingroup sanitization
*/
function t($string, array $args = array(), array $options = array()) {
function t($string, array $args = [], array $options = []) {
return new TranslatableMarkup($string, $args, $options);
}
......@@ -376,7 +376,7 @@ function drupal_validate_utf8($text) {
*
* @see \Drupal\Core\Utility\Error::decodeException()
*/
function watchdog_exception($type, Exception $exception, $message = NULL, $variables = array(), $severity = RfcLogLevel::ERROR, $link = NULL) {
function watchdog_exception($type, Exception $exception, $message = NULL, $variables = [], $severity = RfcLogLevel::ERROR, $link = NULL) {
// Use a default value if $message is not set.
if (empty($message)) {
......@@ -447,7 +447,7 @@ function watchdog_exception($type, Exception $exception, $message = NULL, $varia
function drupal_set_message($message = NULL, $type = 'status', $repeat = FALSE) {
if (isset($message)) {
if (!isset($_SESSION['messages'][$type])) {
$_SESSION['messages'][$type] = array();
$_SESSION['messages'][$type] = [];
}
// Convert strings which are safe to the simplest Markup objects.
......@@ -501,7 +501,7 @@ function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
unset($_SESSION['messages'][$type]);
}
if (isset($messages[$type])) {
return array($type => $messages[$type]);
return [$type => $messages[$type]];
}
}
else {
......@@ -511,7 +511,7 @@ function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
return $messages;
}
}
return array();
return [];
}
/**
......@@ -899,7 +899,7 @@ function drupal_classloader_register($name, $path) {
* @see drupal_static_reset()
*/
function &drupal_static($name, $default_value = NULL, $reset = FALSE) {
static $data = array(), $default = array();
static $data = [], $default = [];
// First check if dealing with a previously defined static variable.
if (isset($data[$name]) || array_key_exists($name, $data)) {
// Non-NULL $name and both $data[$name] and $default[$name] statics exist.
......@@ -978,7 +978,7 @@ function drupal_placeholder($text) {
function &drupal_register_shutdown_function($callback = NULL) {
// We cannot use drupal_static() here because the static cache is reset during
// batch processing, which breaks batch handling.
static $callbacks = array();
static $callbacks = [];
if (isset($callback)) {
// Only register the internal shutdown function once.
......@@ -989,7 +989,7 @@ function &drupal_register_shutdown_function($callback = NULL) {
// Remove $callback from the arguments.
unset($args[0]);
// Save callback and arguments
$callbacks[] = array('callback' => $callback, 'arguments' => $args);
$callbacks[] = ['callback' => $callback, 'arguments' => $args];
}
return $callbacks;
}
......
......@@ -249,7 +249,7 @@ function check_url($uri) {
*/
function format_size($size, $langcode = NULL) {
if ($size < Bytes::KILOBYTE) {
return \Drupal::translation()->formatPlural($size, '1 byte', '@count bytes', array(), array('langcode' => $langcode));
return \Drupal::translation()->formatPlural($size, '1 byte', '@count bytes', [], ['langcode' => $langcode]);
}
else {
$size = $size / Bytes::KILOBYTE; // Convert bytes to kilobytes.
......@@ -352,7 +352,7 @@ function date_iso8601($date) {
* A ; separated string ready for insertion in a HTTP header. No escaping is
* performed for HTML entities, so this string is not safe to be printed.
*/
function drupal_http_header_attributes(array $attributes = array()) {
function drupal_http_header_attributes(array $attributes = []) {
foreach ($attributes as $attribute => &$data) {
if (is_array($data)) {
$data = implode(' ', $data);
......@@ -433,18 +433,18 @@ function drupal_clear_css_cache() {
* @see hook_js_alter()
*/
function drupal_js_defaults($data = NULL) {
return array(
return [
'type' => 'file',
'group' => JS_DEFAULT,
'weight' => 0,
'scope' => 'header',
'cache' => TRUE,
'preprocess' => TRUE,
'attributes' => array(),
'attributes' => [],
'version' => NULL,
'data' => $data,
'browsers' => array(),
);
'browsers' => [],
];
}
/**
......@@ -704,12 +704,12 @@ function drupal_process_states(&$elements) {
*/
function drupal_attach_tabledrag(&$element, array $options) {
// Add default values to elements.
$options = $options + array(
$options = $options + [
'subgroup' => NULL,
'source' => NULL,
'hidden' => TRUE,
'limit' => 0
);
];
$group = $options['group'];
......@@ -719,14 +719,14 @@ function drupal_attach_tabledrag(&$element, array $options) {
// If a subgroup or source isn't set, assume it is the same as the group.
$target = isset($options['subgroup']) ? $options['subgroup'] : $group;
$source = isset($options['source']) ? $options['source'] : $target;
$element['#attached']['drupalSettings']['tableDrag'][$options['table_id']][$group][$tabledrag_id] = array(
$element['#attached']['drupalSettings']['tableDrag'][$options['table_id']][$group][$tabledrag_id] = [
'target' => $target,
'source' => $source,
'relationship' => $options['relationship'],
'action' => $options['action'],
'hidden' => $options['hidden'],
'limit' => $options['limit'],
);
];
$element['#attached']['library'][] = 'core/drupal.tabledrag';
}
......@@ -827,7 +827,7 @@ function drupal_pre_render_link($element) {
* properties of the parent are used.
*/
function drupal_pre_render_links($element) {
$element += array('#links' => array(), '#attached' => array());
$element += ['#links' => [], '#attached' => []];
foreach (Element::children($element) as $key) {
$child = &$element[$key];
// If the child has links which have not been printed yet and the user has
......@@ -1115,7 +1115,7 @@ function drupal_flush_all_caches() {
// Rebuild and reboot a new kernel. A simple DrupalKernel reboot is not
// sufficient, since the list of enabled modules might have been adjusted
// above due to changed code.
$files = array();
$files = [];
foreach ($module_data as $name => $extension) {
if ($extension->status) {
$files[$name] = $extension;
......@@ -1217,7 +1217,7 @@ function drupal_check_incompatibility($v, $current_version) {
* validation system.
*/
function archiver_get_extensions() {
$valid_extensions = array();
$valid_extensions = [];
foreach (\Drupal::service('plugin.manager.archiver')->getDefinitions() as $archive) {
foreach ($archive['extensions'] as $extension) {
foreach (explode('.', $extension) as $part) {
......@@ -1246,9 +1246,9 @@ function archiver_get_archiver($file) {
// Archivers can only work on local paths
$filepath = drupal_realpath($file);
if (!is_file($filepath)) {
throw new Exception(t('Archivers can only operate on local files: %file not supported', array('%file' => $file)));
throw new Exception(t('Archivers can only operate on local files: %file not supported', ['%file' => $file]));
}
return \Drupal::service('plugin.manager.archiver')->getInstance(array('filepath' => $filepath));
return \Drupal::service('plugin.manager.archiver')->getInstance(['filepath' => $filepath]);
}
/**
......@@ -1270,7 +1270,7 @@ function drupal_get_updaters() {
if (!isset($updaters)) {
$updaters = \Drupal::moduleHandler()->invokeAll('updater_info');
\Drupal::moduleHandler()->alter('updater_info', $updaters);
uasort($updaters, array(SortArray::class, 'sortByWeightElement'));
uasort($updaters, [SortArray::class, 'sortByWeightElement']);
}
return $updaters;
}
......@@ -1290,7 +1290,7 @@ function drupal_get_filetransfer_info() {
if (!isset($info)) {
$info = \Drupal::moduleHandler()->invokeAll('filetransfer_info');
\Drupal::moduleHandler()->alter('filetransfer_info', $info);
uasort($info, array(SortArray::class, 'sortByWeightElement'));
uasort($info, [SortArray::class, 'sortByWeightElement']);
}
return $info;
}
......@@ -53,7 +53,7 @@
* @see \Drupal\Core\Database\Connection::query()
* @see \Drupal\Core\Database\Connection::defaultOptions()
*/
function db_query($query, array $args = array(), array $options = array()) {
function db_query($query, array $args = [], array $options = []) {
if (empty($options['target'])) {
$options['target'] = 'default';
}
......@@ -91,7 +91,7 @@ function db_query($query, array $args = array(), array $options = array()) {
* @see \Drupal\Core\Database\Connection::queryRange()
* @see \Drupal\Core\Database\Connection::defaultOptions()
*/
function db_query_range($query, $from, $count, array $args = array(), array $options = array()) {
function db_query_range($query, $from, $count, array $args = [], array $options = []) {
if (empty($options['target'])) {
$options['target'] = 'default';
}
......@@ -127,7 +127,7 @@ function db_query_range($query, $from, $count, array $args = array(), array $opt
* @see \Drupal\Core\Database\Connection::queryTemporary()
* @see \Drupal\Core\Database\Connection::defaultOptions()
*/
function db_query_temporary($query, array $args = array(), array $options = array()) {
function db_query_temporary($query, array $args = [], array $options = []) {
if (empty($options['target'])) {
$options['target'] = 'default';
}
......@@ -154,7 +154,7 @@ function db_query_temporary($query, array $args = array(), array $options = arra
* @see \Drupal\Core\Database\Connection::insert()
* @see \Drupal\Core\Database\Connection::defaultOptions()
*/
function db_insert($table, array $options = array()) {
function db_insert($table, array $options = []) {
if (empty($options['target']) || $options['target'] == 'replica') {
$options['target'] = 'default';
}
......@@ -180,7 +180,7 @@ function db_insert($table, array $options = array()) {
* @see \Drupal\Core\Database\Connection::merge()
* @see \Drupal\Core\Database\Connection::defaultOptions()
*/
function db_merge($table, array $options = array()) {
function db_merge($table, array $options = []) {
if (empty($options['target']) || $options['target'] == 'replica') {
$options['target'] = 'default';
}
......@@ -206,7 +206,7 @@ function db_merge($table, array $options = array()) {
* @see \Drupal\Core\Database\Connection::update()
* @see \Drupal\Core\Database\Connection::defaultOptions()
*/
function db_update($table, array $options = array()) {
function db_update($table, array $options = []) {
if (empty($options['target']) || $options['target'] == 'replica') {
$options['target'] = 'default';
}
......@@ -232,7 +232,7 @@ function db_update($table, array $options = array()) {
* @see \Drupal\Core\Database\Connection::delete()
* @see \Drupal\Core\Database\Connection::defaultOptions()
*/
function db_delete($table, array $options = array()) {
function db_delete($table, array $options = []) {
if (empty($options['target']) || $options['target'] == 'replica') {
$options['target'] = 'default';
}
......@@ -258,7 +258,7 @@ function db_delete($table, array $options = array()) {
* @see \Drupal\Core\Database\Connection::truncate()
* @see \Drupal\Core\Database\Connection::defaultOptions()
*/
function db_truncate($table, array $options = array()) {
function db_truncate($table, array $options = []) {
if (empty($options['target']) || $options['target'] == 'replica') {
$options['target'] = 'default';
}
......@@ -288,7 +288,7 @@ function db_truncate($table, array $options = array()) {
* @see \Drupal\Core\Database\Connection::select()
* @see \Drupal\Core\Database\Connection::defaultOptions()
*/
function db_select($table, $alias = NULL, array $options = array()) {
function db_select($table, $alias = NULL, array $options = []) {
if (empty($options['target'])) {
$options['target'] = 'default';
}
......@@ -315,7 +315,7 @@ function db_select($table, $alias = NULL, array $options = array()) {
* @see \Drupal\Core\Database\Connection::startTransaction()
* @see \Drupal\Core\Database\Connection::defaultOptions()
*/
function db_transaction($name = NULL, array $options = array()) {
function db_transaction($name = NULL, array $options = []) {
if (empty($options['target'])) {
$options['target'] = 'default';
}
......@@ -451,7 +451,7 @@ function db_driver() {
*
* @see \Drupal\Core\Database\Database::closeConnection()
*/
function db_close(array $options = array()) {
function db_close(array $options = []) {
if (empty($options['target'])) {
$options['target'] = NULL;
}
......@@ -752,7 +752,7 @@ function db_drop_table($table) {
* @see \Drupal\Core\Database\Schema::addField()
* @see db_change_field()
*/
function db_add_field($table, $field, $spec, $keys_new = array()) {
function db_add_field($table, $field, $spec, $keys_new = []) {
return Database::getConnection()->schema()->addField($table, $field, $spec, $keys_new);
}
......@@ -1020,7 +1020,7 @@ function db_drop_index($table, $name) {
*
* @see \Drupal\Core\Database\Schema::changeField()
*/
function db_change_field($table, $field, $field_new, $spec, $keys_new = array()) {
function db_change_field($table, $field, $field_new, $spec, $keys_new = []) {
return Database::getConnection()->schema()->changeField($table, $field, $field_new, $spec, $keys_new);
}
......
......@@ -80,7 +80,7 @@ function entity_get_bundles($entity_type = NULL) {
function entity_load($entity_type, $id, $reset = FALSE) {
$controller = \Drupal::entityManager()->getStorage($entity_type);
if ($reset) {
$controller->resetCache(array($id));
$controller->resetCache([$id]);
}
return $controller->load($id);
}
......@@ -305,7 +305,7 @@ function entity_delete_multiple($entity_type, array $ids) {
* @see \Drupal\Core\Entity\EntityTypeManagerInterface::getStorage()
* @see \Drupal\Core\Entity\EntityStorageInterface::create()
*/
function entity_create($entity_type, array $values = array()) {
function entity_create($entity_type, array $values = []) {
return \Drupal::entityManager()
->getStorage($entity_type)
->create($values);
......@@ -483,12 +483,12 @@ function entity_get_display($entity_type, $bundle, $view_mode) {
// configuration entries are only created when a display object is explicitly
// configured and saved.
if (!$display) {
$display = EntityViewDisplay::create(array(
$display = EntityViewDisplay::create([
'targetEntityType' => $entity_type,
'bundle' => $bundle,
'mode' => $view_mode,
'status' => TRUE,
));
]);
}
return $display;
......@@ -563,12 +563,12 @@ function entity_get_form_display($entity_type, $bundle, $form_mode) {
// configuration entries are only created when an entity form display is
// explicitly configured and saved.
if (!$entity_form_display) {
$entity_form_display = EntityFormDisplay::create(array(
$entity_form_display = EntityFormDisplay::create([
'targetEntityType' => $entity_type,
'bundle' => $bundle,
'mode' => $form_mode,
'status' => TRUE,