Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -1,3 +1,4 @@
|
|||
threshold:
|
||||
requirements_warning: 172800
|
||||
requirements_error: 1209600
|
||||
logging: 1
|
||||
|
|
|
@ -72,6 +72,9 @@ system.cron:
|
|||
requirements_error:
|
||||
type: integer
|
||||
label: 'Requirements error period'
|
||||
logging:
|
||||
type: integer
|
||||
label: 'Detailed cron logging'
|
||||
|
||||
system.date:
|
||||
type: config_object
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* @file
|
||||
* Styles for the system status counter component.
|
||||
*/
|
||||
|
||||
.system-status-counter__status-icon {
|
||||
display: inline-block;
|
||||
height: 25px;
|
||||
width: 25px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.system-status-counter__status-icon:before {
|
||||
content: "";
|
||||
background-size: 16px;
|
||||
background-position: center 2px;
|
||||
background-repeat: no-repeat;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.system-status-counter__status-icon--error:before {
|
||||
background-image: url(../../../../misc/icons/e32700/error.svg);
|
||||
}
|
||||
.system-status-counter__status-icon--warning:before {
|
||||
background-image: url(../../../../misc/icons/e29700/warning.svg);
|
||||
}
|
||||
.system-status-counter__status-icon--checked:before {
|
||||
background-image: url(../../../../misc/icons/73b355/check.svg);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* @file
|
||||
* Styles for the system status report counters.
|
||||
*/
|
||||
|
||||
.system-status-report-counters__item {
|
||||
width: 100%;
|
||||
padding: .5em 0;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
background-color: rgba(0, 0, 0, 0.063);
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
|
||||
@media screen and (min-width: 60em) {
|
||||
.system-status-report-counters {
|
||||
flex-wrap: wrap;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.system-status-report-counters__item--half-width {
|
||||
width: 49%;
|
||||
}
|
||||
.system-status-report-counters__item--third-width {
|
||||
width: 33%;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* @file
|
||||
* Default styles for the System Status general info.
|
||||
*/
|
||||
|
||||
.system-status-general-info__item {
|
||||
border: 1px solid #ccc;
|
||||
margin-top: 1em;
|
||||
padding: 0 1em 1em;
|
||||
}
|
||||
|
||||
.system-status-general-info__item-title {
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
|
@ -204,10 +204,11 @@ small .admin-link:after {
|
|||
.system-status-report__status-title {
|
||||
position: relative;
|
||||
vertical-align: top;
|
||||
width: 25%;
|
||||
width: 100%;
|
||||
padding: 10px 6px 10px 40px; /* LTR */
|
||||
box-sizing: border-box;
|
||||
font-weight: normal;
|
||||
background-color: transparent;
|
||||
}
|
||||
[dir="rtl"] .system-status-report__status-title {
|
||||
padding: 10px 40px 10px 6px;
|
||||
|
@ -232,6 +233,9 @@ small .admin-link:after {
|
|||
.system-status-report__status-icon--warning:before {
|
||||
background-image: url(../../../misc/icons/e29700/warning.svg);
|
||||
}
|
||||
.system-status-report__entry__value {
|
||||
padding: 1em .5em;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appearance page.
|
||||
|
@ -387,3 +391,6 @@ small .admin-link:after {
|
|||
[dir="rtl"] .system-themes-admin-form {
|
||||
clear: right;
|
||||
}
|
||||
.cron-description__run-cron {
|
||||
display: block;
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@ class AdminController extends ControllerBase {
|
|||
}
|
||||
|
||||
uasort($module_info, 'system_sort_modules_by_info_name');
|
||||
$menu_items = array();
|
||||
$menu_items = [];
|
||||
|
||||
foreach ($module_info as $module => $info) {
|
||||
// Only display a section if there are any available tasks.
|
||||
if ($admin_tasks = system_get_module_admin_tasks($module, $info->info)) {
|
||||
// Sort links by title.
|
||||
uasort($admin_tasks, array('\Drupal\Component\Utility\SortArray', 'sortByTitleElement'));
|
||||
uasort($admin_tasks, ['\Drupal\Component\Utility\SortArray', 'sortByTitleElement']);
|
||||
// Move 'Configure permissions' links to the bottom of each section.
|
||||
$permission_key = "user.admin_permissions.$module";
|
||||
if (isset($admin_tasks[$permission_key])) {
|
||||
|
@ -38,14 +38,14 @@ class AdminController extends ControllerBase {
|
|||
$admin_tasks[$permission_key] = $permission_task;
|
||||
}
|
||||
|
||||
$menu_items[$info->info['name']] = array($info->info['description'], $admin_tasks);
|
||||
$menu_items[$info->info['name']] = [$info->info['description'], $admin_tasks];
|
||||
}
|
||||
}
|
||||
|
||||
$output = array(
|
||||
$output = [
|
||||
'#theme' => 'system_admin_index',
|
||||
'#menu_items' => $menu_items,
|
||||
);
|
||||
];
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ class DbUpdateController extends ControllerBase {
|
|||
$_SESSION['update_ignore_warnings'] = TRUE;
|
||||
}
|
||||
|
||||
$regions = array();
|
||||
$regions = [];
|
||||
$requirements = update_check_requirements();
|
||||
$severity = drupal_requirements_severity($requirements);
|
||||
if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING && empty($_SESSION['update_ignore_warnings']))) {
|
||||
|
@ -212,32 +212,32 @@ class DbUpdateController extends ControllerBase {
|
|||
$this->keyValueExpirableFactory->get('update')->deleteAll();
|
||||
$this->keyValueExpirableFactory->get('update_available_release')->deleteAll();
|
||||
|
||||
$build['info_header'] = array(
|
||||
$build['info_header'] = [
|
||||
'#markup' => '<p>' . $this->t('Use this utility to update your database whenever a new release of Drupal or a module is installed.') . '</p><p>' . $this->t('For more detailed information, see the <a href="https://www.drupal.org/upgrade">upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.') . '</p>',
|
||||
);
|
||||
];
|
||||
|
||||
$info[] = $this->t("<strong>Back up your code</strong>. Hint: when backing up module code, do not leave that backup in the 'modules' or 'sites/*/modules' directories as this may confuse Drupal's auto-discovery mechanism.");
|
||||
$info[] = $this->t('Put your site into <a href=":url">maintenance mode</a>.', array(
|
||||
$info[] = $this->t('Put your site into <a href=":url">maintenance mode</a>.', [
|
||||
':url' => Url::fromRoute('system.site_maintenance_mode')->toString(TRUE)->getGeneratedUrl(),
|
||||
));
|
||||
]);
|
||||
$info[] = $this->t('<strong>Back up your database</strong>. This process will change your database values and in case of emergency you may need to revert to a backup.');
|
||||
$info[] = $this->t('Install your new files in the appropriate location, as described in the handbook.');
|
||||
$build['info'] = array(
|
||||
$build['info'] = [
|
||||
'#theme' => 'item_list',
|
||||
'#list_type' => 'ol',
|
||||
'#items' => $info,
|
||||
);
|
||||
$build['info_footer'] = array(
|
||||
];
|
||||
$build['info_footer'] = [
|
||||
'#markup' => '<p>' . $this->t('When you have performed the steps above, you may proceed.') . '</p>',
|
||||
);
|
||||
];
|
||||
|
||||
$build['link'] = array(
|
||||
$build['link'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Continue'),
|
||||
'#attributes' => array('class' => array('button', 'button--primary')),
|
||||
'#attributes' => ['class' => ['button', 'button--primary']],
|
||||
// @todo Revisit once https://www.drupal.org/node/2548095 is in.
|
||||
'#url' => Url::fromUri('base://selection'),
|
||||
);
|
||||
];
|
||||
return $build;
|
||||
}
|
||||
|
||||
|
@ -256,15 +256,15 @@ class DbUpdateController extends ControllerBase {
|
|||
|
||||
$count = 0;
|
||||
$incompatible_count = 0;
|
||||
$build['start'] = array(
|
||||
$build['start'] = [
|
||||
'#tree' => TRUE,
|
||||
'#type' => 'details',
|
||||
);
|
||||
];
|
||||
|
||||
// Ensure system.module's updates appear first.
|
||||
$build['start']['system'] = array();
|
||||
$build['start']['system'] = [];
|
||||
|
||||
$starting_updates = array();
|
||||
$starting_updates = [];
|
||||
$incompatible_updates_exist = FALSE;
|
||||
$updates_per_module = [];
|
||||
foreach (['update', 'post_update'] as $update_type) {
|
||||
|
@ -278,30 +278,30 @@ class DbUpdateController extends ControllerBase {
|
|||
}
|
||||
foreach ($updates as $module => $update) {
|
||||
if (!isset($update['start'])) {
|
||||
$build['start'][$module] = array(
|
||||
$build['start'][$module] = [
|
||||
'#type' => 'item',
|
||||
'#title' => $module . ' module',
|
||||
'#markup' => $update['warning'],
|
||||
'#prefix' => '<div class="messages messages--warning">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
];
|
||||
$incompatible_updates_exist = TRUE;
|
||||
continue;
|
||||
}
|
||||
if (!empty($update['pending'])) {
|
||||
$updates_per_module += [$module => []];
|
||||
$updates_per_module[$module] = array_merge($updates_per_module[$module], $update['pending']);
|
||||
$build['start'][$module] = array(
|
||||
$build['start'][$module] = [
|
||||
'#type' => 'hidden',
|
||||
'#value' => $update['start'],
|
||||
);
|
||||
];
|
||||
// Store the previous items in order to merge normal updates and
|
||||
// post_update functions together.
|
||||
$build['start'][$module] = array(
|
||||
$build['start'][$module] = [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $updates_per_module[$module],
|
||||
'#title' => $module . ' module',
|
||||
);
|
||||
];
|
||||
|
||||
if ($update_type === 'update') {
|
||||
$starting_updates[$module] = $update['start'];
|
||||
|
@ -329,7 +329,7 @@ class DbUpdateController extends ControllerBase {
|
|||
$build['start'][$module_update_key]['#items'][$data['number']] .= '<div class="warning">' . $text . '</div>';
|
||||
}
|
||||
// Move the module containing this update to the top of the list.
|
||||
$build['start'] = array($module_update_key => $build['start'][$module_update_key]) + $build['start'];
|
||||
$build['start'] = [$module_update_key => $build['start'][$module_update_key]] + $build['start'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,25 +341,25 @@ class DbUpdateController extends ControllerBase {
|
|||
if (empty($count)) {
|
||||
drupal_set_message($this->t('No pending updates.'));
|
||||
unset($build);
|
||||
$build['links'] = array(
|
||||
$build['links'] = [
|
||||
'#theme' => 'links',
|
||||
'#links' => $this->helpfulLinks($request),
|
||||
);
|
||||
];
|
||||
|
||||
// No updates to run, so caches won't get flushed later. Clear them now.
|
||||
drupal_flush_all_caches();
|
||||
}
|
||||
else {
|
||||
$build['help'] = array(
|
||||
$build['help'] = [
|
||||
'#markup' => '<p>' . $this->t('The version of Drupal you are updating from has been automatically detected.') . '</p>',
|
||||
'#weight' => -5,
|
||||
);
|
||||
];
|
||||
if ($incompatible_count) {
|
||||
$build['start']['#title'] = $this->formatPlural(
|
||||
$count,
|
||||
'1 pending update (@number_applied to be applied, @number_incompatible skipped)',
|
||||
'@count pending updates (@number_applied to be applied, @number_incompatible skipped)',
|
||||
array('@number_applied' => $count - $incompatible_count, '@number_incompatible' => $incompatible_count)
|
||||
['@number_applied' => $count - $incompatible_count, '@number_incompatible' => $incompatible_count]
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
@ -367,15 +367,15 @@ class DbUpdateController extends ControllerBase {
|
|||
}
|
||||
// @todo Simplify with https://www.drupal.org/node/2548095
|
||||
$base_url = str_replace('/update.php', '', $request->getBaseUrl());
|
||||
$url = (new Url('system.db_update', array('op' => 'run')))->setOption('base_url', $base_url);
|
||||
$build['link'] = array(
|
||||
$url = (new Url('system.db_update', ['op' => 'run']))->setOption('base_url', $base_url);
|
||||
$build['link'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Apply pending updates'),
|
||||
'#attributes' => array('class' => array('button', 'button--primary')),
|
||||
'#attributes' => ['class' => ['button', 'button--primary']],
|
||||
'#weight' => 5,
|
||||
'#url' => $url,
|
||||
'#access' => $url->access($this->currentUser()),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $build;
|
||||
|
@ -397,24 +397,24 @@ class DbUpdateController extends ControllerBase {
|
|||
// Report end result.
|
||||
$dblog_exists = $this->moduleHandler->moduleExists('dblog');
|
||||
if ($dblog_exists && $this->account->hasPermission('access site reports')) {
|
||||
$log_message = $this->t('All errors have been <a href=":url">logged</a>.', array(
|
||||
$log_message = $this->t('All errors have been <a href=":url">logged</a>.', [
|
||||
':url' => Url::fromRoute('dblog.overview')->setOption('base_url', $base_url)->toString(TRUE)->getGeneratedUrl(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
else {
|
||||
$log_message = $this->t('All errors have been logged.');
|
||||
}
|
||||
|
||||
if (!empty($_SESSION['update_success'])) {
|
||||
$message = '<p>' . $this->t('Updates were attempted. If you see no failures below, you may proceed happily back to your <a href=":url">site</a>. Otherwise, you may need to update your database manually.', array(':url' => Url::fromRoute('<front>')->setOption('base_url', $base_url)->toString(TRUE)->getGeneratedUrl())) . ' ' . $log_message . '</p>';
|
||||
$message = '<p>' . $this->t('Updates were attempted. If you see no failures below, you may proceed happily back to your <a href=":url">site</a>. Otherwise, you may need to update your database manually.', [':url' => Url::fromRoute('<front>')->setOption('base_url', $base_url)->toString(TRUE)->getGeneratedUrl()]) . ' ' . $log_message . '</p>';
|
||||
}
|
||||
else {
|
||||
$last = reset($_SESSION['updates_remaining']);
|
||||
list($module, $version) = array_pop($last);
|
||||
$message = '<p class="error">' . $this->t('The update process was aborted prematurely while running <strong>update #@version in @module.module</strong>.', array(
|
||||
$message = '<p class="error">' . $this->t('The update process was aborted prematurely while running <strong>update #@version in @module.module</strong>.', [
|
||||
'@version' => $version,
|
||||
'@module' => $module,
|
||||
)) . ' ' . $log_message;
|
||||
]) . ' ' . $log_message;
|
||||
if ($dblog_exists) {
|
||||
$message .= ' ' . $this->t('You may need to check the <code>watchdog</code> database table manually.');
|
||||
}
|
||||
|
@ -425,23 +425,23 @@ class DbUpdateController extends ControllerBase {
|
|||
$message .= '<p>' . $this->t("<strong>Reminder: don't forget to set the <code>\$settings['update_free_access']</code> value in your <code>settings.php</code> file back to <code>FALSE</code>.</strong>") . '</p>';
|
||||
}
|
||||
|
||||
$build['message'] = array(
|
||||
$build['message'] = [
|
||||
'#markup' => $message,
|
||||
);
|
||||
$build['links'] = array(
|
||||
];
|
||||
$build['links'] = [
|
||||
'#theme' => 'links',
|
||||
'#links' => $this->helpfulLinks($request),
|
||||
);
|
||||
];
|
||||
|
||||
// Output a list of info messages.
|
||||
if (!empty($_SESSION['update_results'])) {
|
||||
$all_messages = array();
|
||||
$all_messages = [];
|
||||
foreach ($_SESSION['update_results'] as $module => $updates) {
|
||||
if ($module != '#abort') {
|
||||
$module_has_message = FALSE;
|
||||
$info_messages = array();
|
||||
$info_messages = [];
|
||||
foreach ($updates as $name => $queries) {
|
||||
$messages = array();
|
||||
$messages = [];
|
||||
foreach ($queries as $query) {
|
||||
// If there is no message for this update, don't show anything.
|
||||
if (empty($query['query'])) {
|
||||
|
@ -449,16 +449,16 @@ class DbUpdateController extends ControllerBase {
|
|||
}
|
||||
|
||||
if ($query['success']) {
|
||||
$messages[] = array(
|
||||
'#wrapper_attributes' => array('class' => array('success')),
|
||||
$messages[] = [
|
||||
'#wrapper_attributes' => ['class' => ['success']],
|
||||
'#markup' => $query['query'],
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$messages[] = array(
|
||||
'#wrapper_attributes' => array('class' => array('failure')),
|
||||
$messages[] = [
|
||||
'#wrapper_attributes' => ['class' => ['failure']],
|
||||
'#markup' => '<strong>' . $this->t('Failed:') . '</strong> ' . $query['query'],
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -470,32 +470,32 @@ class DbUpdateController extends ControllerBase {
|
|||
else {
|
||||
$title = $this->t('Update @name', ['@name' => trim($name, '_')]);
|
||||
}
|
||||
$info_messages[] = array(
|
||||
$info_messages[] = [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $messages,
|
||||
'#title' => $title,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// If there were any messages then prefix them with the module name
|
||||
// and add it to the global message list.
|
||||
if ($module_has_message) {
|
||||
$all_messages[] = array(
|
||||
$all_messages[] = [
|
||||
'#type' => 'container',
|
||||
'#prefix' => '<h3>' . $this->t('@module module', array('@module' => $module)) . '</h3>',
|
||||
'#prefix' => '<h3>' . $this->t('@module module', ['@module' => $module]) . '</h3>',
|
||||
'#children' => $info_messages,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($all_messages) {
|
||||
$build['query_messages'] = array(
|
||||
$build['query_messages'] = [
|
||||
'#type' => 'container',
|
||||
'#children' => $all_messages,
|
||||
'#attributes' => array('class' => array('update-results')),
|
||||
'#attributes' => ['class' => ['update-results']],
|
||||
'#prefix' => '<h2>' . $this->t('The following updates returned messages:') . '</h2>',
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
unset($_SESSION['update_results']);
|
||||
|
@ -515,17 +515,17 @@ class DbUpdateController extends ControllerBase {
|
|||
* A render array.
|
||||
*/
|
||||
public function requirements($severity, array $requirements, Request $request) {
|
||||
$options = $severity == REQUIREMENT_WARNING ? array('continue' => 1) : array();
|
||||
$options = $severity == REQUIREMENT_WARNING ? ['continue' => 1] : [];
|
||||
// @todo Revisit once https://www.drupal.org/node/2548095 is in. Something
|
||||
// like Url::fromRoute('system.db_update')->setOptions() should then be
|
||||
// possible.
|
||||
$try_again_url = Url::fromUri($request->getUriForPath(''))->setOptions(['query' => $options])->toString(TRUE)->getGeneratedUrl();
|
||||
|
||||
$build['status_report'] = array(
|
||||
'#theme' => 'status_report',
|
||||
$build['status_report'] = [
|
||||
'#type' => 'status_report',
|
||||
'#requirements' => $requirements,
|
||||
'#suffix' => $this->t('Check the messages and <a href=":url">try again</a>.', array(':url' => $try_again_url))
|
||||
);
|
||||
'#suffix' => $this->t('Check the messages and <a href=":url">try again</a>.', [':url' => $try_again_url])
|
||||
];
|
||||
|
||||
$build['#title'] = $this->t('Requirements problem');
|
||||
return $build;
|
||||
|
@ -543,19 +543,19 @@ class DbUpdateController extends ControllerBase {
|
|||
*/
|
||||
protected function updateTasksList($active = NULL) {
|
||||
// Default list of tasks.
|
||||
$tasks = array(
|
||||
$tasks = [
|
||||
'requirements' => $this->t('Verify requirements'),
|
||||
'info' => $this->t('Overview'),
|
||||
'selection' => $this->t('Review updates'),
|
||||
'run' => $this->t('Run updates'),
|
||||
'results' => $this->t('Review log'),
|
||||
);
|
||||
];
|
||||
|
||||
$task_list = array(
|
||||
$task_list = [
|
||||
'#theme' => 'maintenance_task_list',
|
||||
'#items' => $tasks,
|
||||
'#active' => $active,
|
||||
);
|
||||
];
|
||||
return $task_list;
|
||||
}
|
||||
|
||||
|
@ -576,7 +576,7 @@ class DbUpdateController extends ControllerBase {
|
|||
$this->state->set('system.maintenance_mode', TRUE);
|
||||
}
|
||||
|
||||
$operations = array();
|
||||
$operations = [];
|
||||
|
||||
// Resolve any update dependencies to determine the actual updates that will
|
||||
// be run and the order they will be run in.
|
||||
|
@ -587,9 +587,9 @@ class DbUpdateController extends ControllerBase {
|
|||
// batch API can pass in to the batch operation each time it is called. (We
|
||||
// do not store the entire update dependency array here because it is
|
||||
// potentially very large.)
|
||||
$dependency_map = array();
|
||||
$dependency_map = [];
|
||||
foreach ($updates as $function => $update) {
|
||||
$dependency_map[$function] = !empty($update['reverse_paths']) ? array_keys($update['reverse_paths']) : array();
|
||||
$dependency_map[$function] = !empty($update['reverse_paths']) ? array_keys($update['reverse_paths']) : [];
|
||||
}
|
||||
|
||||
// Determine updates to be performed.
|
||||
|
@ -602,7 +602,7 @@ class DbUpdateController extends ControllerBase {
|
|||
drupal_set_installed_schema_version($update['module'], $update['number'] - 1);
|
||||
unset($start[$update['module']]);
|
||||
}
|
||||
$operations[] = array('update_do_one', array($update['module'], $update['number'], $dependency_map[$function]));
|
||||
$operations[] = ['update_do_one', [$update['module'], $update['number'], $dependency_map[$function]]];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -618,12 +618,12 @@ class DbUpdateController extends ControllerBase {
|
|||
}
|
||||
|
||||
$batch['operations'] = $operations;
|
||||
$batch += array(
|
||||
$batch += [
|
||||
'title' => $this->t('Updating'),
|
||||
'init_message' => $this->t('Starting updates'),
|
||||
'error_message' => $this->t('An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.'),
|
||||
'finished' => array('\Drupal\system\Controller\DbUpdateController', 'batchFinished'),
|
||||
);
|
||||
'finished' => ['\Drupal\system\Controller\DbUpdateController', 'batchFinished'],
|
||||
];
|
||||
batch_set($batch);
|
||||
|
||||
// @todo Revisit once https://www.drupal.org/node/2548095 is in.
|
||||
|
@ -673,15 +673,15 @@ class DbUpdateController extends ControllerBase {
|
|||
protected function helpfulLinks(Request $request) {
|
||||
// @todo Simplify with https://www.drupal.org/node/2548095
|
||||
$base_url = str_replace('/update.php', '', $request->getBaseUrl());
|
||||
$links['front'] = array(
|
||||
$links['front'] = [
|
||||
'title' => $this->t('Front page'),
|
||||
'url' => Url::fromRoute('<front>')->setOption('base_url', $base_url),
|
||||
);
|
||||
];
|
||||
if ($this->account->hasPermission('access administration pages')) {
|
||||
$links['admin-pages'] = array(
|
||||
$links['admin-pages'] = [
|
||||
'title' => $this->t('Administration pages'),
|
||||
'url' => Url::fromRoute('system.admin')->setOption('base_url', $base_url),
|
||||
);
|
||||
];
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
|
@ -693,7 +693,7 @@ class DbUpdateController extends ControllerBase {
|
|||
* The module updates that can be performed.
|
||||
*/
|
||||
protected function getModuleUpdates() {
|
||||
$return = array();
|
||||
$return = [];
|
||||
$updates = update_get_update_list();
|
||||
foreach ($updates as $module => $update) {
|
||||
$return[$module] = $update['start'];
|
||||
|
|
|
@ -77,7 +77,7 @@ class EntityAutocompleteController extends ControllerBase {
|
|||
* or if it does not match the stored data.
|
||||
*/
|
||||
public function handleAutocomplete(Request $request, $target_type, $selection_handler, $selection_settings_key) {
|
||||
$matches = array();
|
||||
$matches = [];
|
||||
// Get the typed string from the URL, if it exists.
|
||||
if ($input = $request->query->get('q')) {
|
||||
$typed_string = Tags::explode($input);
|
||||
|
|
|
@ -25,7 +25,7 @@ class Http4xxController extends ControllerBase {
|
|||
* The default 403 content.
|
||||
*
|
||||
* @return array
|
||||
* A render array containing the message to display for 404 pages.
|
||||
* A render array containing the message to display for 403 pages.
|
||||
*/
|
||||
public function on403() {
|
||||
return [
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace Drupal\system\Controller;
|
|||
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Extension\ThemeHandlerInterface;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Menu\MenuLinkTreeInterface;
|
||||
|
@ -19,13 +18,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
*/
|
||||
class SystemController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* The entity query factory object.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $queryFactory;
|
||||
|
||||
/**
|
||||
* System Manager Service.
|
||||
*
|
||||
|
@ -66,8 +58,6 @@ class SystemController extends ControllerBase {
|
|||
*
|
||||
* @param \Drupal\system\SystemManager $systemManager
|
||||
* System manager service.
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $queryFactory
|
||||
* The entity query object.
|
||||
* @param \Drupal\Core\Theme\ThemeAccessCheck $theme_access
|
||||
* The theme access checker service.
|
||||
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
|
||||
|
@ -77,9 +67,8 @@ class SystemController extends ControllerBase {
|
|||
* @param \Drupal\Core\Menu\MenuLinkTreeInterface $menu_link_tree
|
||||
* The menu link tree service.
|
||||
*/
|
||||
public function __construct(SystemManager $systemManager, QueryFactory $queryFactory, ThemeAccessCheck $theme_access, FormBuilderInterface $form_builder, ThemeHandlerInterface $theme_handler, MenuLinkTreeInterface $menu_link_tree) {
|
||||
public function __construct(SystemManager $systemManager, ThemeAccessCheck $theme_access, FormBuilderInterface $form_builder, ThemeHandlerInterface $theme_handler, MenuLinkTreeInterface $menu_link_tree) {
|
||||
$this->systemManager = $systemManager;
|
||||
$this->queryFactory = $queryFactory;
|
||||
$this->themeAccess = $theme_access;
|
||||
$this->formBuilder = $form_builder;
|
||||
$this->themeHandler = $theme_handler;
|
||||
|
@ -92,7 +81,6 @@ class SystemController extends ControllerBase {
|
|||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('system.manager'),
|
||||
$container->get('entity.query'),
|
||||
$container->get('access_check.theme'),
|
||||
$container->get('form_builder'),
|
||||
$container->get('theme_handler'),
|
||||
|
@ -112,19 +100,19 @@ class SystemController extends ControllerBase {
|
|||
public function overview($link_id) {
|
||||
// Check for status report errors.
|
||||
if ($this->systemManager->checkRequirements() && $this->currentUser()->hasPermission('administer site configuration')) {
|
||||
drupal_set_message($this->t('One or more problems were detected with your Drupal installation. Check the <a href=":status">status report</a> for more information.', array(':status' => $this->url('system.status'))), 'error');
|
||||
drupal_set_message($this->t('One or more problems were detected with your Drupal installation. Check the <a href=":status">status report</a> for more information.', [':status' => $this->url('system.status')]), 'error');
|
||||
}
|
||||
// Load all menu links below it.
|
||||
$parameters = new MenuTreeParameters();
|
||||
$parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
|
||||
$tree = $this->menuLinkTree->load(NULL, $parameters);
|
||||
$manipulators = array(
|
||||
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
|
||||
array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'),
|
||||
);
|
||||
$manipulators = [
|
||||
['callable' => 'menu.default_tree_manipulators:checkAccess'],
|
||||
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
|
||||
];
|
||||
$tree = $this->menuLinkTree->transform($tree, $manipulators);
|
||||
$tree_access_cacheability = new CacheableMetadata();
|
||||
$blocks = array();
|
||||
$blocks = [];
|
||||
foreach ($tree as $key => $element) {
|
||||
$tree_access_cacheability = $tree_access_cacheability->merge(CacheableMetadata::createFromObject($element->access));
|
||||
|
||||
|
@ -136,10 +124,10 @@ class SystemController extends ControllerBase {
|
|||
$link = $element->link;
|
||||
$block['title'] = $link->getTitle();
|
||||
$block['description'] = $link->getDescription();
|
||||
$block['content'] = array(
|
||||
$block['content'] = [
|
||||
'#theme' => 'admin_block_content',
|
||||
'#content' => $this->systemManager->getAdminBlock($link),
|
||||
);
|
||||
];
|
||||
|
||||
if (!empty($block['content']['#content'])) {
|
||||
$blocks[$key] = $block;
|
||||
|
@ -173,7 +161,7 @@ class SystemController extends ControllerBase {
|
|||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
public function compactPage($mode) {
|
||||
user_cookie_save(array('admin_compact_mode' => ($mode == 'on')));
|
||||
user_cookie_save(['admin_compact_mode' => ($mode == 'on')]);
|
||||
return $this->redirect('<front>');
|
||||
}
|
||||
|
||||
|
@ -199,9 +187,9 @@ class SystemController extends ControllerBase {
|
|||
uasort($themes, 'system_sort_modules_by_info_name');
|
||||
|
||||
$theme_default = $config->get('default');
|
||||
$theme_groups = array('installed' => array(), 'uninstalled' => array());
|
||||
$theme_groups = ['installed' => [], 'uninstalled' => []];
|
||||
$admin_theme = $config->get('admin');
|
||||
$admin_theme_options = array();
|
||||
$admin_theme_options = [];
|
||||
|
||||
foreach ($themes as &$theme) {
|
||||
if (!empty($theme->info['hidden'])) {
|
||||
|
@ -218,17 +206,17 @@ class SystemController extends ControllerBase {
|
|||
$theme_keys[] = $theme->getName();
|
||||
}
|
||||
else {
|
||||
$theme_keys = array($theme->getName());
|
||||
$theme_keys = [$theme->getName()];
|
||||
}
|
||||
// Look for a screenshot in the current theme or in its closest ancestor.
|
||||
foreach (array_reverse($theme_keys) as $theme_key) {
|
||||
if (isset($themes[$theme_key]) && file_exists($themes[$theme_key]->info['screenshot'])) {
|
||||
$theme->screenshot = array(
|
||||
$theme->screenshot = [
|
||||
'uri' => $themes[$theme_key]->info['screenshot'],
|
||||
'alt' => $this->t('Screenshot for @theme theme', array('@theme' => $theme->info['name'])),
|
||||
'title' => $this->t('Screenshot for @theme theme', array('@theme' => $theme->info['name'])),
|
||||
'attributes' => array('class' => array('screenshot')),
|
||||
);
|
||||
'alt' => $this->t('Screenshot for @theme theme', ['@theme' => $theme->info['name']]),
|
||||
'title' => $this->t('Screenshot for @theme theme', ['@theme' => $theme->info['name']]),
|
||||
'attributes' => ['class' => ['screenshot']],
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -245,16 +233,16 @@ class SystemController extends ControllerBase {
|
|||
// Confirm that the theme engine is available.
|
||||
$theme->incompatible_engine = isset($theme->info['engine']) && !isset($theme->owner);
|
||||
}
|
||||
$theme->operations = array();
|
||||
$theme->operations = [];
|
||||
if (!empty($theme->status) || !$theme->incompatible_core && !$theme->incompatible_php && !$theme->incompatible_base && !$theme->incompatible_engine) {
|
||||
// Create the operations links.
|
||||
$query['theme'] = $theme->getName();
|
||||
if ($this->themeAccess->checkAccess($theme->getName())) {
|
||||
$theme->operations[] = array(
|
||||
$theme->operations[] = [
|
||||
'title' => $this->t('Settings'),
|
||||
'url' => Url::fromRoute('system.theme_settings_theme', ['theme' => $theme->getName()]),
|
||||
'attributes' => array('title' => $this->t('Settings for @theme theme', array('@theme' => $theme->info['name']))),
|
||||
);
|
||||
'attributes' => ['title' => $this->t('Settings for @theme theme', ['@theme' => $theme->info['name']])],
|
||||
];
|
||||
}
|
||||
if (!empty($theme->status)) {
|
||||
if (!$theme->is_default) {
|
||||
|
@ -269,40 +257,40 @@ class SystemController extends ControllerBase {
|
|||
}
|
||||
}
|
||||
if ($theme_uninstallable) {
|
||||
$theme->operations[] = array(
|
||||
$theme->operations[] = [
|
||||
'title' => $this->t('Uninstall'),
|
||||
'url' => Url::fromRoute('system.theme_uninstall'),
|
||||
'query' => $query,
|
||||
'attributes' => array('title' => $this->t('Uninstall @theme theme', array('@theme' => $theme->info['name']))),
|
||||
);
|
||||
'attributes' => ['title' => $this->t('Uninstall @theme theme', ['@theme' => $theme->info['name']])],
|
||||
];
|
||||
}
|
||||
$theme->operations[] = array(
|
||||
$theme->operations[] = [
|
||||
'title' => $this->t('Set as default'),
|
||||
'url' => Url::fromRoute('system.theme_set_default'),
|
||||
'query' => $query,
|
||||
'attributes' => array('title' => $this->t('Set @theme as default theme', array('@theme' => $theme->info['name']))),
|
||||
);
|
||||
'attributes' => ['title' => $this->t('Set @theme as default theme', ['@theme' => $theme->info['name']])],
|
||||
];
|
||||
}
|
||||
$admin_theme_options[$theme->getName()] = $theme->info['name'];
|
||||
}
|
||||
else {
|
||||
$theme->operations[] = array(
|
||||
$theme->operations[] = [
|
||||
'title' => $this->t('Install'),
|
||||
'url' => Url::fromRoute('system.theme_install'),
|
||||
'query' => $query,
|
||||
'attributes' => array('title' => $this->t('Install @theme theme', array('@theme' => $theme->info['name']))),
|
||||
);
|
||||
$theme->operations[] = array(
|
||||
'attributes' => ['title' => $this->t('Install @theme theme', ['@theme' => $theme->info['name']])],
|
||||
];
|
||||
$theme->operations[] = [
|
||||
'title' => $this->t('Install and set as default'),
|
||||
'url' => Url::fromRoute('system.theme_set_default'),
|
||||
'query' => $query,
|
||||
'attributes' => array('title' => $this->t('Install @theme as default theme', array('@theme' => $theme->info['name']))),
|
||||
);
|
||||
'attributes' => ['title' => $this->t('Install @theme as default theme', ['@theme' => $theme->info['name']])],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Add notes to default and administration theme.
|
||||
$theme->notes = array();
|
||||
$theme->notes = [];
|
||||
if ($theme->is_default) {
|
||||
$theme->notes[] = $this->t('default theme');
|
||||
}
|
||||
|
@ -315,9 +303,9 @@ class SystemController extends ControllerBase {
|
|||
}
|
||||
|
||||
// There are two possible theme groups.
|
||||
$theme_group_titles = array(
|
||||
$theme_group_titles = [
|
||||
'installed' => $this->formatPlural(count($theme_groups['installed']), 'Installed theme', 'Installed themes'),
|
||||
);
|
||||
];
|
||||
if (!empty($theme_groups['uninstalled'])) {
|
||||
$theme_group_titles['uninstalled'] = $this->formatPlural(count($theme_groups['uninstalled']), 'Uninstalled theme', 'Uninstalled themes');
|
||||
}
|
||||
|
@ -325,12 +313,12 @@ class SystemController extends ControllerBase {
|
|||
uasort($theme_groups['installed'], 'system_sort_themes');
|
||||
$this->moduleHandler()->alter('system_themes_page', $theme_groups);
|
||||
|
||||
$build = array();
|
||||
$build[] = array(
|
||||
$build = [];
|
||||
$build[] = [
|
||||
'#theme' => 'system_themes_page',
|
||||
'#theme_groups' => $theme_groups,
|
||||
'#theme_group_titles' => $theme_group_titles,
|
||||
);
|
||||
];
|
||||
$build[] = $this->formBuilder->getForm('Drupal\system\Form\ThemeAdminForm', $admin_theme_options);
|
||||
|
||||
return $build;
|
||||
|
|
|
@ -47,7 +47,7 @@ class SystemInfoController implements ContainerInjectionInterface {
|
|||
*/
|
||||
public function status() {
|
||||
$requirements = $this->systemManager->listRequirements();
|
||||
return array('#theme' => 'status_report', '#requirements' => $requirements);
|
||||
return ['#type' => 'status_report_page', '#requirements' => $requirements];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ class SystemInfoController implements ContainerInjectionInterface {
|
|||
$output = ob_get_clean();
|
||||
}
|
||||
else {
|
||||
$output = t('The phpinfo() function has been disabled for security reasons. For more information, visit <a href=":phpinfo">Enabling and disabling phpinfo()</a> handbook page.', array(':phpinfo' => 'https://www.drupal.org/node/243993'));
|
||||
$output = t('The phpinfo() function has been disabled for security reasons. For more information, visit <a href=":phpinfo">Enabling and disabling phpinfo()</a> handbook page.', [':phpinfo' => 'https://www.drupal.org/node/243993']);
|
||||
}
|
||||
return new Response($output);
|
||||
}
|
||||
|
|
|
@ -71,15 +71,15 @@ class ThemeController extends ControllerBase {
|
|||
if (!empty($themes[$theme])) {
|
||||
// Do not uninstall the default or admin theme.
|
||||
if ($theme === $config->get('default') || $theme === $config->get('admin')) {
|
||||
drupal_set_message($this->t('%theme is the default theme and cannot be uninstalled.', array('%theme' => $themes[$theme]->info['name'])), 'error');
|
||||
drupal_set_message($this->t('%theme is the default theme and cannot be uninstalled.', ['%theme' => $themes[$theme]->info['name']]), 'error');
|
||||
}
|
||||
else {
|
||||
$this->themeHandler->uninstall(array($theme));
|
||||
drupal_set_message($this->t('The %theme theme has been uninstalled.', array('%theme' => $themes[$theme]->info['name'])));
|
||||
$this->themeHandler->uninstall([$theme]);
|
||||
drupal_set_message($this->t('The %theme theme has been uninstalled.', ['%theme' => $themes[$theme]->info['name']]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
|
||||
drupal_set_message($this->t('The %theme theme was not found.', ['%theme' => $theme]), 'error');
|
||||
}
|
||||
|
||||
return $this->redirect('system.themes_page');
|
||||
|
@ -106,12 +106,12 @@ class ThemeController extends ControllerBase {
|
|||
|
||||
if (isset($theme)) {
|
||||
try {
|
||||
if ($this->themeHandler->install(array($theme))) {
|
||||
if ($this->themeHandler->install([$theme])) {
|
||||
$themes = $this->themeHandler->listInfo();
|
||||
drupal_set_message($this->t('The %theme theme has been installed.', array('%theme' => $themes[$theme]->info['name'])));
|
||||
drupal_set_message($this->t('The %theme theme has been installed.', ['%theme' => $themes[$theme]->info['name']]));
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
|
||||
drupal_set_message($this->t('The %theme theme was not found.', ['%theme' => $theme]), 'error');
|
||||
}
|
||||
}
|
||||
catch (PreExistingConfigException $e) {
|
||||
|
@ -121,10 +121,10 @@ class ThemeController extends ControllerBase {
|
|||
count($config_objects),
|
||||
'Unable to install @extension, %config_names already exists in active configuration.',
|
||||
'Unable to install @extension, %config_names already exist in active configuration.',
|
||||
array(
|
||||
[
|
||||
'%config_names' => implode(', ', $config_objects),
|
||||
'@extension' => $theme,
|
||||
)),
|
||||
]),
|
||||
'error'
|
||||
);
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ class ThemeController extends ControllerBase {
|
|||
|
||||
// Check if the specified theme is one recognized by the system.
|
||||
// Or try to install the theme.
|
||||
if (isset($themes[$theme]) || $this->themeHandler->install(array($theme))) {
|
||||
if (isset($themes[$theme]) || $this->themeHandler->install([$theme])) {
|
||||
$themes = $this->themeHandler->listInfo();
|
||||
|
||||
// Set the default theme.
|
||||
|
@ -171,17 +171,17 @@ class ThemeController extends ControllerBase {
|
|||
// theme.
|
||||
$admin_theme = $config->get('admin');
|
||||
if ($admin_theme != 0 && $admin_theme != $theme) {
|
||||
drupal_set_message($this->t('Please note that the administration theme is still set to the %admin_theme theme; consequently, the theme on this page remains unchanged. All non-administrative sections of the site, however, will show the selected %selected_theme theme by default.', array(
|
||||
drupal_set_message($this->t('Please note that the administration theme is still set to the %admin_theme theme; consequently, the theme on this page remains unchanged. All non-administrative sections of the site, however, will show the selected %selected_theme theme by default.', [
|
||||
'%admin_theme' => $themes[$admin_theme]->info['name'],
|
||||
'%selected_theme' => $themes[$theme]->info['name'],
|
||||
)));
|
||||
]));
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('%theme is now the default theme.', array('%theme' => $themes[$theme]->info['name'])));
|
||||
drupal_set_message($this->t('%theme is now the default theme.', ['%theme' => $themes[$theme]->info['name']]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
|
||||
drupal_set_message($this->t('The %theme theme was not found.', ['%theme' => $theme]), 'error');
|
||||
}
|
||||
|
||||
return $this->redirect('system.themes_page');
|
||||
|
|
|
@ -23,7 +23,7 @@ class DateFormatAccessControlHandler extends EntityAccessControlHandler {
|
|||
return AccessResult::allowed();
|
||||
}
|
||||
// Locked date formats cannot be updated or deleted.
|
||||
elseif (in_array($operation, array('update', 'delete'))) {
|
||||
elseif (in_array($operation, ['update', 'delete'])) {
|
||||
if ($entity->isLocked()) {
|
||||
return AccessResult::forbidden()->addCacheableDependency($entity);
|
||||
}
|
||||
|
|
139
web/core/modules/system/src/Element/StatusReportPage.php
Normal file
139
web/core/modules/system/src/Element/StatusReportPage.php
Normal file
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\system\Element;
|
||||
|
||||
use Drupal\Core\Render\Element\RenderElement;
|
||||
use Drupal\Core\Render\Element\StatusReport;
|
||||
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
|
||||
|
||||
/**
|
||||
* Creates status report page element.
|
||||
*
|
||||
* @RenderElement("status_report_page")
|
||||
*/
|
||||
class StatusReportPage extends RenderElement {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getInfo() {
|
||||
$class = get_class($this);
|
||||
return [
|
||||
'#theme' => 'status_report_page',
|
||||
'#pre_render' => [
|
||||
[$class, 'preRenderCounters'],
|
||||
[$class, 'preRenderGeneralInfo'],
|
||||
[$class, 'preRenderRequirements'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* #pre_render callback to get general info out of requirements.
|
||||
*/
|
||||
public static function preRenderGeneralInfo($element) {
|
||||
$element['#general_info'] = [
|
||||
'#theme' => 'status_report_general_info',
|
||||
];
|
||||
// Loop through requirements and pull out items.
|
||||
foreach ($element['#requirements'] as $key => $requirement) {
|
||||
switch ($key) {
|
||||
case 'cron':
|
||||
foreach ($requirement['description'] as &$description_elements) {
|
||||
foreach ($description_elements as &$description_element) {
|
||||
if (isset($description_element['#url']) && $description_element['#url']->getRouteName() == 'system.run_cron') {
|
||||
$description_element['#attributes']['class'][] = 'button';
|
||||
$description_element['#attributes']['class'][] = 'button--small';
|
||||
$description_element['#attributes']['class'][] = 'button--primary';
|
||||
$description_element['#attributes']['class'][] = 'system-status-general-info__run-cron';
|
||||
}
|
||||
}
|
||||
}
|
||||
$element['#general_info']['#' . $key] = $requirement;
|
||||
unset($element['#requirements'][$key]);
|
||||
break;
|
||||
|
||||
case 'drupal':
|
||||
case 'webserver':
|
||||
case 'database_system':
|
||||
case 'database_system_version':
|
||||
case 'php':
|
||||
case 'php_memory_limit':
|
||||
$element['#general_info']['#' . $key] = $requirement;
|
||||
unset($element['#requirements'][$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* #pre_render callback to create counter elements.
|
||||
*/
|
||||
public static function preRenderCounters($element) {
|
||||
// Count number of items with different severity for summary.
|
||||
$counters = [
|
||||
'error' => [
|
||||
'amount' => 0,
|
||||
'text' => t('Error'),
|
||||
'text_plural' => t('Errors'),
|
||||
],
|
||||
'warning' => [
|
||||
'amount' => 0,
|
||||
'text' => t('Warning'),
|
||||
'text_plural' => t('Warnings'),
|
||||
],
|
||||
'checked' => [
|
||||
'amount' => 0,
|
||||
'text' => t('Checked'),
|
||||
'text_plural' => t('Checked'),
|
||||
],
|
||||
];
|
||||
|
||||
$severities = StatusReport::getSeverities();
|
||||
foreach ($element['#requirements'] as $key => &$requirement) {
|
||||
$severity = $severities[REQUIREMENT_INFO];
|
||||
if (isset($requirement['severity'])) {
|
||||
$severity = $severities[(int) $requirement['severity']];
|
||||
}
|
||||
elseif (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install') {
|
||||
$severity = $severities[REQUIREMENT_OK];
|
||||
}
|
||||
|
||||
if (isset($counters[$severity['status']])) {
|
||||
$counters[$severity['status']]['amount']++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($counters as $key => $counter) {
|
||||
if ($counter['amount'] === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$text = new PluralTranslatableMarkup($counter['amount'], $counter['text'], $counter['text_plural']);
|
||||
|
||||
$element['#counters'][$key] = [
|
||||
'#theme' => 'status_report_counter',
|
||||
'#amount' => $counter['amount'],
|
||||
'#text' => $text,
|
||||
'#severity' => $key,
|
||||
];
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* #pre_render callback to create status report requirements.
|
||||
*/
|
||||
public static function preRenderRequirements($element) {
|
||||
$element['#requirements'] = [
|
||||
'#type' => 'status_report',
|
||||
'#requirements' => $element['#requirements'],
|
||||
];
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
}
|
|
@ -57,7 +57,7 @@ class Action extends ConfigEntityBase implements ActionConfigEntityInterface, En
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $configuration = array();
|
||||
protected $configuration = [];
|
||||
|
||||
/**
|
||||
* The plugin ID of the action.
|
||||
|
@ -90,7 +90,7 @@ class Action extends ConfigEntityBase implements ActionConfigEntityInterface, En
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPluginCollections() {
|
||||
return array('configuration' => $this->getPluginCollection());
|
||||
return ['configuration' => $this->getPluginCollection()];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,7 +31,7 @@ class AdminRouteSubscriber extends RouteSubscriberBase {
|
|||
// Use a lower priority than \Drupal\field_ui\Routing\RouteSubscriber or
|
||||
// \Drupal\views\EventSubscriber\RouteSubscriber to ensure we add the option
|
||||
// to their routes.
|
||||
$events[RoutingEvents::ALTER] = array('onAlterRoutes', -200);
|
||||
$events[RoutingEvents::ALTER] = ['onAlterRoutes', -200];
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class FileDownloadController extends ControllerBase {
|
|||
|
||||
if (file_stream_wrapper_valid_scheme($scheme) && file_exists($uri)) {
|
||||
// Let other modules provide headers and controls access to the file.
|
||||
$headers = $this->moduleHandler()->invokeAll('file_download', array($uri));
|
||||
$headers = $this->moduleHandler()->invokeAll('file_download', [$uri]);
|
||||
|
||||
foreach ($headers as $result) {
|
||||
if ($result == -1) {
|
||||
|
|
|
@ -10,11 +10,13 @@ use Drupal\Core\Form\FormBase;
|
|||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Form\ConfigFormBaseTrait;
|
||||
|
||||
/**
|
||||
* Configure cron settings for this site.
|
||||
*/
|
||||
class CronForm extends FormBase {
|
||||
use ConfigFormBaseTrait;
|
||||
|
||||
/**
|
||||
* Stores the state storage service.
|
||||
|
@ -65,6 +67,13 @@ class CronForm extends FormBase {
|
|||
$this->moduleHandler = $module_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getEditableConfigNames() {
|
||||
return ['system.cron'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -89,29 +98,49 @@ class CronForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['description'] = array(
|
||||
$form['description'] = [
|
||||
'#markup' => '<p>' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>',
|
||||
);
|
||||
$form['run'] = array(
|
||||
];
|
||||
$form['run'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Run cron'),
|
||||
);
|
||||
$status = '<p>' . $this->t('Last run: %time ago.', array('%time' => $this->dateFormatter->formatTimeDiffSince($this->state->get('system.cron_last')))) . '</p>';
|
||||
$form['status'] = array(
|
||||
];
|
||||
$status = '<p>' . $this->t('Last run: %time ago.', ['%time' => $this->dateFormatter->formatTimeDiffSince($this->state->get('system.cron_last'))]) . '</p>';
|
||||
$form['status'] = [
|
||||
'#markup' => $status,
|
||||
);
|
||||
];
|
||||
|
||||
$cron_url = $this->url('system.cron', array('key' => $this->state->get('system.cron_key')), array('absolute' => TRUE));
|
||||
$form['cron_url'] = array(
|
||||
'#markup' => '<p>' . t('To run cron from outside the site, go to <a href=":cron">@cron</a>', array(':cron' => $cron_url, '@cron' => $cron_url)) . '</p>',
|
||||
);
|
||||
$cron_url = $this->url('system.cron', ['key' => $this->state->get('system.cron_key')], ['absolute' => TRUE]);
|
||||
$form['cron_url'] = [
|
||||
'#markup' => '<p>' . t('To run cron from outside the site, go to <a href=":cron">@cron</a>', [':cron' => $cron_url, '@cron' => $cron_url]) . '</p>',
|
||||
];
|
||||
|
||||
if (!$this->moduleHandler->moduleExists('automated_cron')) {
|
||||
$form['cron'] = array(
|
||||
$form['automated_cron'] = [
|
||||
'#markup' => $this->t('Enable the <em>Automated Cron</em> module to allow cron execution at the end of a server response.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$form['cron'] = [
|
||||
'#title' => t('Cron settings'),
|
||||
'#type' => 'details',
|
||||
'#open' => TRUE,
|
||||
];
|
||||
|
||||
$form['cron']['logging'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Detailed cron logging'),
|
||||
'#default_value' => $this->config('system.cron')->get('logging'),
|
||||
'#description' => 'Run times of individual cron jobs will be written to watchdog',
|
||||
];
|
||||
|
||||
$form['actions']['#type'] = 'actions';
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save configuration'),
|
||||
'#button_type' => 'primary',
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -119,6 +148,11 @@ class CronForm extends FormBase {
|
|||
* Runs cron and reloads the page.
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->config('system.cron')
|
||||
->set('logging', $form_state->getValue('logging'))
|
||||
->save();
|
||||
drupal_set_message(t('The configuration options have been saved.'));
|
||||
|
||||
// Run cron manually from Cron form.
|
||||
if ($this->cron->run()) {
|
||||
drupal_set_message(t('Cron ran successfully.'));
|
||||
|
|
|
@ -41,9 +41,9 @@ class DateFormatDeleteForm extends EntityDeleteForm {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return t('Are you sure you want to delete the format %name : %format?', array(
|
||||
return t('Are you sure you want to delete the format %name : %format?', [
|
||||
'%name' => $this->entity->label(),
|
||||
'%format' => $this->dateFormatter->format(REQUEST_TIME, $this->entity->id()))
|
||||
'%format' => $this->dateFormatter->format(REQUEST_TIME, $this->entity->id())]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class DateFormatEditForm extends DateFormatFormBase {
|
|||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::form($form, $form_state);
|
||||
|
||||
$now = t('Displayed as %date', array('%date' => $this->dateFormatter->format(REQUEST_TIME, $this->entity->id())));
|
||||
$now = t('Displayed as %date', ['%date' => $this->dateFormatter->format(REQUEST_TIME, $this->entity->id())]);
|
||||
$form['date_format_pattern']['#field_suffix'] = ' <small data-drupal-date-formatter="preview">' . $now . '</small>';
|
||||
$form['date_format_pattern']['#default_value'] = $this->entity->getPattern();
|
||||
|
||||
|
|
|
@ -76,26 +76,26 @@ abstract class DateFormatFormBase extends EntityForm {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form['label'] = array(
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Name',
|
||||
'#maxlength' => 100,
|
||||
'#description' => t('Name of the date format'),
|
||||
'#default_value' => $this->entity->label(),
|
||||
);
|
||||
];
|
||||
|
||||
$form['id'] = array(
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#description' => t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'),
|
||||
'#disabled' => !$this->entity->isNew(),
|
||||
'#default_value' => $this->entity->id(),
|
||||
'#machine_name' => array(
|
||||
'exists' => array($this, 'exists'),
|
||||
'#machine_name' => [
|
||||
'exists' => [$this, 'exists'],
|
||||
'replace_pattern' => '([^a-z0-9_]+)|(^custom$)',
|
||||
'error' => $this->t('The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".'),
|
||||
),
|
||||
);
|
||||
$form['date_format_pattern'] = array(
|
||||
],
|
||||
];
|
||||
$form['date_format_pattern'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Format string'),
|
||||
'#maxlength' => 100,
|
||||
|
@ -105,14 +105,14 @@ abstract class DateFormatFormBase extends EntityForm {
|
|||
'data-drupal-date-formatter' => 'source',
|
||||
],
|
||||
'#field_suffix' => ' <small class="js-hide" data-drupal-date-formatter="preview">' . $this->t('Displayed as %date_format', ['%date_format' => '']) . '</small>',
|
||||
);
|
||||
];
|
||||
|
||||
$form['langcode'] = array(
|
||||
$form['langcode'] = [
|
||||
'#type' => 'language_select',
|
||||
'#title' => t('Language'),
|
||||
'#languages' => LanguageInterface::STATE_ALL,
|
||||
'#default_value' => $this->entity->language()->getId(),
|
||||
);
|
||||
];
|
||||
$form['#attached']['drupalSettings']['dateFormats'] = $this->dateFormatter->getSampleDateFormats();
|
||||
$form['#attached']['library'][] = 'system/drupal.system.date';
|
||||
return parent::form($form, $form_state);
|
||||
|
|
|
@ -77,59 +77,59 @@ class FileSystemForm extends ConfigFormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$config = $this->config('system.file');
|
||||
$form['file_public_path'] = array(
|
||||
$form['file_public_path'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => t('Public file system path'),
|
||||
'#markup' => PublicStream::basePath(),
|
||||
'#description' => t('A local file system path where public files will be stored. This directory must exist and be writable by Drupal. This directory must be relative to the Drupal installation directory and be accessible over the web. This must be changed in settings.php'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['file_public_base_url'] = array(
|
||||
$form['file_public_base_url'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => t('Public file base URL'),
|
||||
'#markup' => PublicStream::baseUrl(),
|
||||
'#description' => t('The base URL that will be used for public file URLs. This can be changed in settings.php'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['file_private_path'] = array(
|
||||
$form['file_private_path'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => t('Private file system path'),
|
||||
'#markup' => (PrivateStream::basePath() ? PrivateStream::basePath() : t('Not set')),
|
||||
'#description' => t('An existing local file system path for storing private files. It should be writable by Drupal and not accessible over the web. This must be changed in settings.php'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['file_temporary_path'] = array(
|
||||
$form['file_temporary_path'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Temporary directory'),
|
||||
'#default_value' => $config->get('path.temporary'),
|
||||
'#maxlength' => 255,
|
||||
'#description' => t('A local file system path where temporary files will be stored. This directory should not be accessible over the web.'),
|
||||
'#after_build' => array('system_check_directory'),
|
||||
);
|
||||
'#after_build' => ['system_check_directory'],
|
||||
];
|
||||
// Any visible, writeable wrapper can potentially be used for the files
|
||||
// directory, including a remote file system that integrates with a CDN.
|
||||
$options = $this->streamWrapperManager->getDescriptions(StreamWrapperInterface::WRITE_VISIBLE);
|
||||
|
||||
if (!empty($options)) {
|
||||
$form['file_default_scheme'] = array(
|
||||
$form['file_default_scheme'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Default download method'),
|
||||
'#default_value' => $config->get('default_scheme'),
|
||||
'#options' => $options,
|
||||
'#description' => t('This setting is used as the preferred download method. The use of public files is more efficient, but does not provide any access control.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$intervals = array(0, 21600, 43200, 86400, 604800, 2419200, 7776000);
|
||||
$period = array_combine($intervals, array_map(array($this->dateFormatter, 'formatInterval'), $intervals));
|
||||
$intervals = [0, 21600, 43200, 86400, 604800, 2419200, 7776000];
|
||||
$period = array_combine($intervals, array_map([$this->dateFormatter, 'formatInterval'], $intervals));
|
||||
$period[0] = t('Never');
|
||||
$form['temporary_maximum_age'] = array(
|
||||
$form['temporary_maximum_age'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('Delete orphaned files after'),
|
||||
'#default_value' => $config->get('temporary_maximum_age'),
|
||||
'#options' => $period,
|
||||
'#description' => t('Orphaned files are not referenced from any content but remain in the file system and may appear in administrative listings. <strong>Warning:</strong> If enabled, orphaned files will be permanently deleted and may not be recoverable.'),
|
||||
);
|
||||
];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class ImageToolkitForm extends ConfigFormBase {
|
|||
*
|
||||
* @var \Drupal\Core\ImageToolkit\ImageToolkitInterface[]
|
||||
*/
|
||||
protected $availableToolkits = array();
|
||||
protected $availableToolkits = [];
|
||||
|
||||
/**
|
||||
* Constructs a ImageToolkitForm object.
|
||||
|
@ -66,30 +66,30 @@ class ImageToolkitForm extends ConfigFormBase {
|
|||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$current_toolkit = $this->config('system.image')->get('toolkit');
|
||||
|
||||
$form['image_toolkit'] = array(
|
||||
$form['image_toolkit'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('Select an image processing toolkit'),
|
||||
'#default_value' => $current_toolkit,
|
||||
'#options' => array(),
|
||||
);
|
||||
'#options' => [],
|
||||
];
|
||||
|
||||
// If we have more than one image toolkit, allow the user to select the one
|
||||
// to use, and load each of the toolkits' settings form.
|
||||
foreach ($this->availableToolkits as $id => $toolkit) {
|
||||
$definition = $toolkit->getPluginDefinition();
|
||||
$form['image_toolkit']['#options'][$id] = $definition['title'];
|
||||
$form['image_toolkit_settings'][$id] = array(
|
||||
$form['image_toolkit_settings'][$id] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('@toolkit settings', array('@toolkit' => $definition['title'])),
|
||||
'#title' => $this->t('@toolkit settings', ['@toolkit' => $definition['title']]),
|
||||
'#open' => TRUE,
|
||||
'#tree' => TRUE,
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':radio[name="image_toolkit"]' => array('value' => $id),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['image_toolkit_settings'][$id] += $toolkit->buildConfigurationForm(array(), $form_state);
|
||||
'#states' => [
|
||||
'visible' => [
|
||||
':radio[name="image_toolkit"]' => ['value' => $id],
|
||||
],
|
||||
],
|
||||
];
|
||||
$form['image_toolkit_settings'][$id] += $toolkit->buildConfigurationForm([], $form_state);
|
||||
}
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
|
|
|
@ -29,18 +29,18 @@ class LoggingForm extends ConfigFormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$config = $this->config('system.logging');
|
||||
$form['error_level'] = array(
|
||||
$form['error_level'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Error messages to display'),
|
||||
'#default_value' => $config->get('error_level'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
ERROR_REPORTING_HIDE => t('None'),
|
||||
ERROR_REPORTING_DISPLAY_SOME => t('Errors and warnings'),
|
||||
ERROR_REPORTING_DISPLAY_ALL => t('All messages'),
|
||||
ERROR_REPORTING_DISPLAY_VERBOSE => t('All messages, with backtrace information'),
|
||||
),
|
||||
],
|
||||
'#description' => t('It is recommended that sites running on production environments do not display any errors.'),
|
||||
);
|
||||
];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class ModulesListConfirmForm extends ConfirmFormBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modules = array();
|
||||
protected $modules = [];
|
||||
|
||||
/**
|
||||
* The module installer.
|
||||
|
@ -120,10 +120,10 @@ class ModulesListConfirmForm extends ConfirmFormBase {
|
|||
}
|
||||
|
||||
$items = $this->buildMessageList();
|
||||
$form['message'] = array(
|
||||
$form['message'] = [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $items,
|
||||
);
|
||||
];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
@ -177,10 +177,10 @@ class ModulesListConfirmForm extends ConfirmFormBase {
|
|||
count($config_objects),
|
||||
'Unable to install @extension, %config_names already exists in active configuration.',
|
||||
'Unable to install @extension, %config_names already exist in active configuration.',
|
||||
array(
|
||||
[
|
||||
'%config_names' => implode(', ', $config_objects),
|
||||
'@extension' => $this->modules['install'][$e->getExtension()]
|
||||
)),
|
||||
]),
|
||||
'error'
|
||||
);
|
||||
return;
|
||||
|
@ -194,10 +194,10 @@ class ModulesListConfirmForm extends ConfirmFormBase {
|
|||
}
|
||||
|
||||
$module_names = array_values($this->modules['install']);
|
||||
drupal_set_message($this->formatPlural(count($module_names), 'Module %name has been enabled.', '@count modules have been enabled: %names.', array(
|
||||
drupal_set_message($this->formatPlural(count($module_names), 'Module %name has been enabled.', '@count modules have been enabled: %names.', [
|
||||
'%name' => $module_names[0],
|
||||
'%names' => implode(', ', $module_names),
|
||||
)));
|
||||
]));
|
||||
}
|
||||
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
|
|
|
@ -119,26 +119,26 @@ class ModulesListForm extends FormBase {
|
|||
// Include system.admin.inc so we can use the sort callbacks.
|
||||
$this->moduleHandler->loadInclude('system', 'inc', 'system.admin');
|
||||
|
||||
$form['filters'] = array(
|
||||
$form['filters'] = [
|
||||
'#type' => 'container',
|
||||
'#attributes' => array(
|
||||
'class' => array('table-filter', 'js-show'),
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['table-filter', 'js-show'],
|
||||
],
|
||||
];
|
||||
|
||||
$form['filters']['text'] = array(
|
||||
$form['filters']['text'] = [
|
||||
'#type' => 'search',
|
||||
'#title' => $this->t('Filter modules'),
|
||||
'#title_display' => 'invisible',
|
||||
'#size' => 30,
|
||||
'#placeholder' => $this->t('Filter by name or description'),
|
||||
'#description' => $this->t('Enter a part of the module name or description'),
|
||||
'#attributes' => array(
|
||||
'class' => array('table-filter-text'),
|
||||
'#attributes' => [
|
||||
'class' => ['table-filter-text'],
|
||||
'data-table' => '#system-modules',
|
||||
'autocomplete' => 'off',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Sort all modules by their names.
|
||||
$modules = system_rebuild_module_data();
|
||||
|
@ -150,20 +150,21 @@ class ModulesListForm extends FormBase {
|
|||
if (empty($module->info['hidden'])) {
|
||||
$package = $module->info['package'];
|
||||
$form['modules'][$package][$filename] = $this->buildRow($modules, $module, $distribution);
|
||||
$form['modules'][$package][$filename]['#parents'] = ['modules', $filename];
|
||||
}
|
||||
}
|
||||
|
||||
// Add a wrapper around every package.
|
||||
foreach (Element::children($form['modules']) as $package) {
|
||||
$form['modules'][$package] += array(
|
||||
$form['modules'][$package] += [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t($package),
|
||||
'#open' => TRUE,
|
||||
'#theme' => 'system_modules_details',
|
||||
'#attributes' => array('class' => array('package-listing')),
|
||||
'#attributes' => ['class' => ['package-listing']],
|
||||
// Ensure that the "Core" package comes first.
|
||||
'#weight' => $package == 'Core' ? -10 : NULL,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// If testing modules are shown, collapse the corresponding package by
|
||||
|
@ -173,15 +174,15 @@ class ModulesListForm extends FormBase {
|
|||
}
|
||||
|
||||
// Lastly, sort all packages by title.
|
||||
uasort($form['modules'], array('\Drupal\Component\Utility\SortArray', 'sortByTitleProperty'));
|
||||
uasort($form['modules'], ['\Drupal\Component\Utility\SortArray', 'sortByTitleProperty']);
|
||||
|
||||
$form['#attached']['library'][] = 'system/drupal.system.modules';
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Install'),
|
||||
'#button_type' => 'primary',
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
@ -200,9 +201,9 @@ class ModulesListForm extends FormBase {
|
|||
*/
|
||||
protected function buildRow(array $modules, Extension $module, $distribution) {
|
||||
// Set the basic properties.
|
||||
$row['#required'] = array();
|
||||
$row['#requires'] = array();
|
||||
$row['#required_by'] = array();
|
||||
$row['#required'] = [];
|
||||
$row['#requires'] = [];
|
||||
$row['#required_by'] = [];
|
||||
|
||||
$row['name']['#markup'] = $module->info['name'];
|
||||
$row['description']['#markup'] = $this->t($module->info['description']);
|
||||
|
@ -212,48 +213,48 @@ class ModulesListForm extends FormBase {
|
|||
// implementation exists then the module provides an overview page, rather
|
||||
// than checking to see if the page exists, which is costly.
|
||||
if ($this->moduleHandler->moduleExists('help') && $module->status && in_array($module->getName(), $this->moduleHandler->getImplementations('help'))) {
|
||||
$row['links']['help'] = array(
|
||||
$row['links']['help'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Help'),
|
||||
'#url' => Url::fromRoute('help.page', ['name' => $module->getName()]),
|
||||
'#options' => array('attributes' => array('class' => array('module-link', 'module-link-help'), 'title' => $this->t('Help'))),
|
||||
);
|
||||
'#options' => ['attributes' => ['class' => ['module-link', 'module-link-help'], 'title' => $this->t('Help')]],
|
||||
];
|
||||
}
|
||||
|
||||
// Generate link for module's permission, if the user has access to it.
|
||||
if ($module->status && $this->currentUser->hasPermission('administer permissions') && $this->permissionHandler->moduleProvidesPermissions($module->getName())) {
|
||||
$row['links']['permissions'] = array(
|
||||
$row['links']['permissions'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Permissions'),
|
||||
'#url' => Url::fromRoute('user.admin_permissions'),
|
||||
'#options' => array('fragment' => 'module-' . $module->getName(), 'attributes' => array('class' => array('module-link', 'module-link-permissions'), 'title' => $this->t('Configure permissions'))),
|
||||
);
|
||||
'#options' => ['fragment' => 'module-' . $module->getName(), 'attributes' => ['class' => ['module-link', 'module-link-permissions'], 'title' => $this->t('Configure permissions')]],
|
||||
];
|
||||
}
|
||||
|
||||
// Generate link for module's configuration page, if it has one.
|
||||
if ($module->status && isset($module->info['configure'])) {
|
||||
$route_parameters = isset($module->info['configure_parameters']) ? $module->info['configure_parameters'] : array();
|
||||
$route_parameters = isset($module->info['configure_parameters']) ? $module->info['configure_parameters'] : [];
|
||||
if ($this->accessManager->checkNamedRoute($module->info['configure'], $route_parameters, $this->currentUser)) {
|
||||
$row['links']['configure'] = array(
|
||||
$row['links']['configure'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Configure <span class="visually-hidden">the @module module</span>', ['@module' => $module->info['name']]),
|
||||
'#url' => Url::fromRoute($module->info['configure'], $route_parameters),
|
||||
'#options' => array(
|
||||
'attributes' => array(
|
||||
'class' => array('module-link', 'module-link-configure'),
|
||||
),
|
||||
),
|
||||
);
|
||||
'#options' => [
|
||||
'attributes' => [
|
||||
'class' => ['module-link', 'module-link-configure'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Present a checkbox for installing and indicating the status of a module.
|
||||
$row['enable'] = array(
|
||||
$row['enable'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Install'),
|
||||
'#default_value' => (bool) $module->status,
|
||||
'#disabled' => (bool) $module->status,
|
||||
);
|
||||
];
|
||||
|
||||
// Disable the checkbox for required modules.
|
||||
if (!empty($module->info['required'])) {
|
||||
|
@ -267,24 +268,24 @@ class ModulesListForm extends FormBase {
|
|||
|
||||
// Initialize an empty array of reasons why the module is incompatible. Add
|
||||
// each reason as a separate element of the array.
|
||||
$reasons = array();
|
||||
$reasons = [];
|
||||
|
||||
// Check the core compatibility.
|
||||
if ($module->info['core'] != \Drupal::CORE_COMPATIBILITY) {
|
||||
$compatible = FALSE;
|
||||
$reasons[] = $this->t('This version is not compatible with Drupal @core_version and should be replaced.', array(
|
||||
$reasons[] = $this->t('This version is not compatible with Drupal @core_version and should be replaced.', [
|
||||
'@core_version' => \Drupal::CORE_COMPATIBILITY,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
// Ensure this module is compatible with the currently installed version of PHP.
|
||||
if (version_compare(phpversion(), $module->info['php']) < 0) {
|
||||
$compatible = FALSE;
|
||||
$required = $module->info['php'] . (substr_count($module->info['php'], '.') < 2 ? '.*' : '');
|
||||
$reasons[] = $this->t('This module requires PHP version @php_required and is incompatible with PHP version @php_version.', array(
|
||||
$reasons[] = $this->t('This module requires PHP version @php_required and is incompatible with PHP version @php_version.', [
|
||||
'@php_required' => $required,
|
||||
'@php_version' => phpversion(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
// If this module is not compatible, disable the checkbox.
|
||||
|
@ -298,7 +299,7 @@ class ModulesListForm extends FormBase {
|
|||
// If this module requires other modules, add them to the array.
|
||||
foreach ($module->requires as $dependency => $version) {
|
||||
if (!isset($modules[$dependency])) {
|
||||
$row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">missing</span>)', array('@module' => Unicode::ucfirst($dependency)));
|
||||
$row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">missing</span>)', ['@module' => Unicode::ucfirst($dependency)]);
|
||||
$row['enable']['#disabled'] = TRUE;
|
||||
}
|
||||
// Only display visible modules.
|
||||
|
@ -307,25 +308,25 @@ class ModulesListForm extends FormBase {
|
|||
// Disable the module's checkbox if it is incompatible with the
|
||||
// dependency's version.
|
||||
if ($incompatible_version = drupal_check_incompatibility($version, str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $modules[$dependency]->info['version']))) {
|
||||
$row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">incompatible with</span> version @version)', array(
|
||||
$row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">incompatible with</span> version @version)', [
|
||||
'@module' => $name . $incompatible_version,
|
||||
'@version' => $modules[$dependency]->info['version'],
|
||||
));
|
||||
]);
|
||||
$row['enable']['#disabled'] = TRUE;
|
||||
}
|
||||
// Disable the checkbox if the dependency is incompatible with this
|
||||
// version of Drupal core.
|
||||
elseif ($modules[$dependency]->info['core'] != \Drupal::CORE_COMPATIBILITY) {
|
||||
$row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">incompatible with</span> this version of Drupal core)', array(
|
||||
$row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">incompatible with</span> this version of Drupal core)', [
|
||||
'@module' => $name,
|
||||
));
|
||||
]);
|
||||
$row['enable']['#disabled'] = TRUE;
|
||||
}
|
||||
elseif ($modules[$dependency]->status) {
|
||||
$row['#requires'][$dependency] = $this->t('@module', array('@module' => $name));
|
||||
$row['#requires'][$dependency] = $this->t('@module', ['@module' => $name]);
|
||||
}
|
||||
else {
|
||||
$row['#requires'][$dependency] = $this->t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => $name));
|
||||
$row['#requires'][$dependency] = $this->t('@module (<span class="admin-disabled">disabled</span>)', ['@module' => $name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -335,11 +336,11 @@ class ModulesListForm extends FormBase {
|
|||
foreach ($module->required_by as $dependent => $version) {
|
||||
if (isset($modules[$dependent]) && empty($modules[$dependent]->info['hidden'])) {
|
||||
if ($modules[$dependent]->status == 1 && $module->status == 1) {
|
||||
$row['#required_by'][$dependent] = $this->t('@module', array('@module' => $modules[$dependent]->info['name']));
|
||||
$row['#required_by'][$dependent] = $this->t('@module', ['@module' => $modules[$dependent]->info['name']]);
|
||||
$row['enable']['#disabled'] = TRUE;
|
||||
}
|
||||
else {
|
||||
$row['#required_by'][$dependent] = $this->t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => $modules[$dependent]->info['name']));
|
||||
$row['#required_by'][$dependent] = $this->t('@module (<span class="admin-disabled">disabled</span>)', ['@module' => $modules[$dependent]->info['name']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -357,33 +358,29 @@ class ModulesListForm extends FormBase {
|
|||
* An array of modules to install and their dependencies.
|
||||
*/
|
||||
protected function buildModuleList(FormStateInterface $form_state) {
|
||||
$packages = $form_state->getValue('modules');
|
||||
|
||||
// Build a list of modules to install.
|
||||
$modules = array(
|
||||
'install' => array(),
|
||||
'dependencies' => array(),
|
||||
$modules = [
|
||||
'install' => [],
|
||||
'dependencies' => [],
|
||||
'experimental' => [],
|
||||
);
|
||||
];
|
||||
|
||||
// Required modules have to be installed.
|
||||
// @todo This should really not be handled here.
|
||||
$data = system_rebuild_module_data();
|
||||
foreach ($data as $name => $module) {
|
||||
if (!empty($module->required) && !$this->moduleHandler->moduleExists($name)) {
|
||||
// If the module is installed there is nothing to do.
|
||||
if ($this->moduleHandler->moduleExists($name)) {
|
||||
continue;
|
||||
}
|
||||
// Required modules have to be installed.
|
||||
if (!empty($module->required)) {
|
||||
$modules['install'][$name] = $module->info['name'];
|
||||
}
|
||||
}
|
||||
|
||||
// First, build a list of all modules that were selected.
|
||||
foreach ($packages as $package => $items) {
|
||||
foreach ($items as $name => $checkbox) {
|
||||
if ($checkbox['enable'] && !$this->moduleHandler->moduleExists($name)) {
|
||||
$modules['install'][$name] = $data[$name]->info['name'];
|
||||
// Identify experimental modules.
|
||||
if ($package == 'Core (Experimental)') {
|
||||
$modules['experimental'][$name] = $data[$name]->info['name'];
|
||||
}
|
||||
// Selected modules should be installed.
|
||||
elseif (($checkbox = $form_state->getValue(['modules', $name], FALSE)) && $checkbox['enable']) {
|
||||
$modules['install'][$name] = $data[$name]->info['name'];
|
||||
// Identify experimental modules.
|
||||
if ($data[$name]->info['package'] == 'Core (Experimental)') {
|
||||
$modules['experimental'][$name] = $data[$name]->info['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -450,10 +447,10 @@ class ModulesListForm extends FormBase {
|
|||
try {
|
||||
$this->moduleInstaller->install(array_keys($modules['install']));
|
||||
$module_names = array_values($modules['install']);
|
||||
drupal_set_message($this->formatPlural(count($module_names), 'Module %name has been enabled.', '@count modules have been enabled: %names.', array(
|
||||
drupal_set_message($this->formatPlural(count($module_names), 'Module %name has been enabled.', '@count modules have been enabled: %names.', [
|
||||
'%name' => $module_names[0],
|
||||
'%names' => implode(', ', $module_names),
|
||||
)));
|
||||
]));
|
||||
}
|
||||
catch (PreExistingConfigException $e) {
|
||||
$config_objects = $e->flattenConfigObjects($e->getConfigObjects());
|
||||
|
@ -462,10 +459,10 @@ class ModulesListForm extends FormBase {
|
|||
count($config_objects),
|
||||
'Unable to install @extension, %config_names already exists in active configuration.',
|
||||
'Unable to install @extension, %config_names already exist in active configuration.',
|
||||
array(
|
||||
[
|
||||
'%config_names' => implode(', ', $config_objects),
|
||||
'@extension' => $modules['install'][$e->getExtension()]
|
||||
)),
|
||||
]),
|
||||
'error'
|
||||
);
|
||||
return;
|
||||
|
|
|
@ -51,7 +51,7 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modules = array();
|
||||
protected $modules = [];
|
||||
|
||||
/**
|
||||
* Constructs a ModulesUninstallConfirmForm object.
|
||||
|
@ -135,12 +135,12 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase {
|
|||
|
||||
$data = system_rebuild_module_data();
|
||||
$form['text']['#markup'] = '<p>' . $this->t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') . '</p>';
|
||||
$form['modules'] = array(
|
||||
$form['modules'] = [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => array_map(function ($module) use ($data) {
|
||||
return $data[$module]->info['name'];
|
||||
}, $this->modules),
|
||||
);
|
||||
];
|
||||
|
||||
// List the dependent entities.
|
||||
$this->addDependencyListsToForm($form, 'module', $this->modules, $this->configManager, $this->entityManager);
|
||||
|
|
|
@ -85,28 +85,28 @@ class ModulesUninstallForm extends FormBase {
|
|||
// Include system.admin.inc so we can use the sort callbacks.
|
||||
$this->moduleHandler->loadInclude('system', 'inc', 'system.admin');
|
||||
|
||||
$form['filters'] = array(
|
||||
$form['filters'] = [
|
||||
'#type' => 'container',
|
||||
'#attributes' => array(
|
||||
'class' => array('table-filter', 'js-show'),
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['table-filter', 'js-show'],
|
||||
],
|
||||
];
|
||||
|
||||
$form['filters']['text'] = array(
|
||||
$form['filters']['text'] = [
|
||||
'#type' => 'search',
|
||||
'#title' => $this->t('Filter modules'),
|
||||
'#title_display' => 'invisible',
|
||||
'#size' => 30,
|
||||
'#placeholder' => $this->t('Filter by name or description'),
|
||||
'#description' => $this->t('Enter a part of the module name or description'),
|
||||
'#attributes' => array(
|
||||
'class' => array('table-filter-text'),
|
||||
'#attributes' => [
|
||||
'class' => ['table-filter-text'],
|
||||
'data-table' => '#system-modules-uninstall',
|
||||
'autocomplete' => 'off',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$form['modules'] = array();
|
||||
$form['modules'] = [];
|
||||
|
||||
// Only build the rest of the form if there are any modules available to
|
||||
// uninstall;
|
||||
|
@ -120,18 +120,18 @@ class ModulesUninstallForm extends FormBase {
|
|||
uasort($uninstallable, 'system_sort_modules_by_info_name');
|
||||
$validation_reasons = $this->moduleInstaller->validateUninstall(array_keys($uninstallable));
|
||||
|
||||
$form['uninstall'] = array('#tree' => TRUE);
|
||||
$form['uninstall'] = ['#tree' => TRUE];
|
||||
foreach ($uninstallable as $module_key => $module) {
|
||||
$name = $module->info['name'] ?: $module->getName();
|
||||
$form['modules'][$module->getName()]['#module_name'] = $name;
|
||||
$form['modules'][$module->getName()]['name']['#markup'] = $name;
|
||||
$form['modules'][$module->getName()]['description']['#markup'] = $this->t($module->info['description']);
|
||||
|
||||
$form['uninstall'][$module->getName()] = array(
|
||||
$form['uninstall'][$module->getName()] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Uninstall @module module', array('@module' => $name)),
|
||||
'#title' => $this->t('Uninstall @module module', ['@module' => $name]),
|
||||
'#title_display' => 'invisible',
|
||||
);
|
||||
];
|
||||
|
||||
// If a validator returns reasons not to uninstall a module,
|
||||
// list the reasons and disable the check box.
|
||||
|
@ -152,11 +152,11 @@ class ModulesUninstallForm extends FormBase {
|
|||
}
|
||||
|
||||
$form['#attached']['library'][] = 'system/drupal.system.modules';
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Uninstall'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -100,64 +100,64 @@ class PerformanceForm extends ConfigFormBase {
|
|||
|
||||
$config = $this->config('system.performance');
|
||||
|
||||
$form['clear_cache'] = array(
|
||||
$form['clear_cache'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Clear cache'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['clear_cache']['clear'] = array(
|
||||
$form['clear_cache']['clear'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Clear all caches'),
|
||||
'#submit' => array('::submitCacheClear'),
|
||||
);
|
||||
'#submit' => ['::submitCacheClear'],
|
||||
];
|
||||
|
||||
$form['caching'] = array(
|
||||
$form['caching'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Caching'),
|
||||
'#open' => TRUE,
|
||||
'#description' => $this->t('Note: Drupal provides an internal page cache module that is recommended for small to medium-sized websites.'),
|
||||
);
|
||||
];
|
||||
// Identical options to the ones for block caching.
|
||||
// @see \Drupal\Core\Block\BlockBase::buildConfigurationForm()
|
||||
$period = array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400);
|
||||
$period = array_map(array($this->dateFormatter, 'formatInterval'), array_combine($period, $period));
|
||||
$period = [0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400];
|
||||
$period = array_map([$this->dateFormatter, 'formatInterval'], array_combine($period, $period));
|
||||
$period[0] = '<' . t('no caching') . '>';
|
||||
$form['caching']['page_cache_maximum_age'] = array(
|
||||
$form['caching']['page_cache_maximum_age'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('Page cache maximum age'),
|
||||
'#default_value' => $config->get('cache.page.max_age'),
|
||||
'#options' => $period,
|
||||
'#description' => t('The maximum time a page can be cached by browsers and proxies. This is used as the value for max-age in Cache-Control headers.'),
|
||||
);
|
||||
];
|
||||
|
||||
$directory = 'public://';
|
||||
$is_writable = is_dir($directory) && is_writable($directory);
|
||||
$disabled = !$is_writable;
|
||||
$disabled_message = '';
|
||||
if (!$is_writable) {
|
||||
$disabled_message = ' ' . t('<strong class="error">Set up the <a href=":file-system">public files directory</a> to make these optimizations available.</strong>', array(':file-system' => $this->url('system.file_system_settings')));
|
||||
$disabled_message = ' ' . t('<strong class="error">Set up the <a href=":file-system">public files directory</a> to make these optimizations available.</strong>', [':file-system' => $this->url('system.file_system_settings')]);
|
||||
}
|
||||
|
||||
$form['bandwidth_optimization'] = array(
|
||||
$form['bandwidth_optimization'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Bandwidth optimization'),
|
||||
'#open' => TRUE,
|
||||
'#description' => t('External resources can be optimized automatically, which can reduce both the size and number of requests made to your website.') . $disabled_message,
|
||||
);
|
||||
];
|
||||
|
||||
$form['bandwidth_optimization']['preprocess_css'] = array(
|
||||
$form['bandwidth_optimization']['preprocess_css'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Aggregate CSS files'),
|
||||
'#default_value' => $config->get('css.preprocess'),
|
||||
'#disabled' => $disabled,
|
||||
);
|
||||
$form['bandwidth_optimization']['preprocess_js'] = array(
|
||||
];
|
||||
$form['bandwidth_optimization']['preprocess_js'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Aggregate JavaScript files'),
|
||||
'#default_value' => $config->get('js.preprocess'),
|
||||
'#disabled' => $disabled,
|
||||
);
|
||||
];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
|
|
@ -67,76 +67,76 @@ class RegionalForm extends ConfigFormBase {
|
|||
// Date settings:
|
||||
$zones = system_time_zones();
|
||||
|
||||
$form['locale'] = array(
|
||||
$form['locale'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Locale'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['locale']['site_default_country'] = array(
|
||||
$form['locale']['site_default_country'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('Default country'),
|
||||
'#empty_value' => '',
|
||||
'#default_value' => $system_date->get('country.default'),
|
||||
'#options' => $countries,
|
||||
'#attributes' => array('class' => array('country-detect')),
|
||||
);
|
||||
'#attributes' => ['class' => ['country-detect']],
|
||||
];
|
||||
|
||||
$form['locale']['date_first_day'] = array(
|
||||
$form['locale']['date_first_day'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('First day of week'),
|
||||
'#default_value' => $system_date->get('first_day'),
|
||||
'#options' => array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')),
|
||||
);
|
||||
'#options' => [0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')],
|
||||
];
|
||||
|
||||
$form['timezone'] = array(
|
||||
$form['timezone'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Time zones'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['timezone']['date_default_timezone'] = array(
|
||||
$form['timezone']['date_default_timezone'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('Default time zone'),
|
||||
'#default_value' => $system_date->get('timezone.default') ?: date_default_timezone_get(),
|
||||
'#options' => $zones,
|
||||
);
|
||||
];
|
||||
|
||||
$configurable_timezones = $system_date->get('timezone.user.configurable');
|
||||
$form['timezone']['configurable_timezones'] = array(
|
||||
$form['timezone']['configurable_timezones'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Users may set their own time zone'),
|
||||
'#default_value' => $configurable_timezones,
|
||||
);
|
||||
];
|
||||
|
||||
$form['timezone']['configurable_timezones_wrapper'] = array(
|
||||
$form['timezone']['configurable_timezones_wrapper'] = [
|
||||
'#type' => 'container',
|
||||
'#states' => array(
|
||||
'#states' => [
|
||||
// Hide the user configured timezone settings when users are forced to use
|
||||
// the default setting.
|
||||
'invisible' => array(
|
||||
'input[name="configurable_timezones"]' => array('checked' => FALSE),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['timezone']['configurable_timezones_wrapper']['empty_timezone_message'] = array(
|
||||
'invisible' => [
|
||||
'input[name="configurable_timezones"]' => ['checked' => FALSE],
|
||||
],
|
||||
],
|
||||
];
|
||||
$form['timezone']['configurable_timezones_wrapper']['empty_timezone_message'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Remind users at login if their time zone is not set'),
|
||||
'#default_value' => $system_date->get('timezone.user.warn'),
|
||||
'#description' => t('Only applied if users may set their own time zone.')
|
||||
);
|
||||
];
|
||||
|
||||
$form['timezone']['configurable_timezones_wrapper']['user_default_timezone'] = array(
|
||||
$form['timezone']['configurable_timezones_wrapper']['user_default_timezone'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Time zone for new users'),
|
||||
'#default_value' => $system_date->get('timezone.user.default'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
DRUPAL_USER_TIMEZONE_DEFAULT => t('Default time zone'),
|
||||
DRUPAL_USER_TIMEZONE_EMPTY => t('Empty time zone'),
|
||||
DRUPAL_USER_TIMEZONE_SELECT => t('Users may set their own time zone at registration'),
|
||||
),
|
||||
],
|
||||
'#description' => t('Only applied if users may set their own time zone.')
|
||||
);
|
||||
];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
|
|
@ -29,31 +29,31 @@ class RssFeedsForm extends ConfigFormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$rss_config = $this->config('system.rss');
|
||||
$form['feed_description'] = array(
|
||||
$form['feed_description'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Feed description'),
|
||||
'#default_value' => $rss_config->get('channel.description'),
|
||||
'#description' => t('Description of your site, included in each feed.')
|
||||
);
|
||||
$options = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30);
|
||||
$form['feed_default_items'] = array(
|
||||
];
|
||||
$options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30];
|
||||
$form['feed_default_items'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('Number of items in each feed'),
|
||||
'#default_value' => $rss_config->get('items.limit'),
|
||||
'#options' => array_combine($options, $options),
|
||||
'#description' => t('Default number of items to include in each feed.')
|
||||
);
|
||||
$form['feed_view_mode'] = array(
|
||||
];
|
||||
$form['feed_view_mode'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('Feed content'),
|
||||
'#default_value' => $rss_config->get('items.view_mode'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'title' => t('Titles only'),
|
||||
'teaser' => t('Titles plus teaser'),
|
||||
'fulltext' => t('Full text'),
|
||||
),
|
||||
],
|
||||
'#description' => t('Global setting for the default display of content items in each feed.')
|
||||
);
|
||||
];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
|
|
@ -92,63 +92,63 @@ class SiteInformationForm extends ConfigFormBase {
|
|||
$site_mail = ini_get('sendmail_from');
|
||||
}
|
||||
|
||||
$form['site_information'] = array(
|
||||
$form['site_information'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Site details'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
$form['site_information']['site_name'] = array(
|
||||
];
|
||||
$form['site_information']['site_name'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Site name'),
|
||||
'#default_value' => $site_config->get('name'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['site_information']['site_slogan'] = array(
|
||||
];
|
||||
$form['site_information']['site_slogan'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Slogan'),
|
||||
'#default_value' => $site_config->get('slogan'),
|
||||
'#description' => t("How this is used depends on your site's theme."),
|
||||
);
|
||||
$form['site_information']['site_mail'] = array(
|
||||
];
|
||||
$form['site_information']['site_mail'] = [
|
||||
'#type' => 'email',
|
||||
'#title' => t('Email address'),
|
||||
'#default_value' => $site_mail,
|
||||
'#description' => t("The <em>From</em> address in automated emails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this email being flagged as spam.)"),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['front_page'] = array(
|
||||
];
|
||||
$form['front_page'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Front page'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
];
|
||||
$front_page = $site_config->get('page.front') != '/user/login' ? $this->aliasManager->getAliasByPath($site_config->get('page.front')) : '';
|
||||
$form['front_page']['site_frontpage'] = array(
|
||||
$form['front_page']['site_frontpage'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Default front page'),
|
||||
'#default_value' => $front_page,
|
||||
'#size' => 40,
|
||||
'#description' => t('Optionally, specify a relative URL to display as the front page. Leave blank to display the default front page.'),
|
||||
'#field_prefix' => $this->requestContext->getCompleteBaseUrl(),
|
||||
);
|
||||
$form['error_page'] = array(
|
||||
];
|
||||
$form['error_page'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Error pages'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
$form['error_page']['site_403'] = array(
|
||||
];
|
||||
$form['error_page']['site_403'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Default 403 (access denied) page'),
|
||||
'#default_value' => $site_config->get('page.403'),
|
||||
'#size' => 40,
|
||||
'#description' => t('This page is displayed when the requested document is denied to the current user. Leave blank to display a generic "access denied" page.'),
|
||||
);
|
||||
$form['error_page']['site_404'] = array(
|
||||
];
|
||||
$form['error_page']['site_404'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Default 404 (not found) page'),
|
||||
'#default_value' => $site_config->get('page.404'),
|
||||
'#size' => 40,
|
||||
'#description' => t('This page is displayed when no other content matches the requested document. Leave blank to display a generic "page not found" page.'),
|
||||
);
|
||||
];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ class SiteInformationForm extends ConfigFormBase {
|
|||
|
||||
}
|
||||
if (!$this->pathValidator->isValid($form_state->getValue('site_frontpage'))) {
|
||||
$form_state->setErrorByName('site_frontpage', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_frontpage'))));
|
||||
$form_state->setErrorByName('site_frontpage', $this->t("The path '%path' is either invalid or you do not have access to it.", ['%path' => $form_state->getValue('site_frontpage')]));
|
||||
}
|
||||
// Get the normal paths of both error pages.
|
||||
if (!$form_state->isValueEmpty('site_403')) {
|
||||
|
@ -189,11 +189,11 @@ class SiteInformationForm extends ConfigFormBase {
|
|||
}
|
||||
// Validate 403 error path.
|
||||
if (!$form_state->isValueEmpty('site_403') && !$this->pathValidator->isValid($form_state->getValue('site_403'))) {
|
||||
$form_state->setErrorByName('site_403', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_403'))));
|
||||
$form_state->setErrorByName('site_403', $this->t("The path '%path' is either invalid or you do not have access to it.", ['%path' => $form_state->getValue('site_403')]));
|
||||
}
|
||||
// Validate 404 error path.
|
||||
if (!$form_state->isValueEmpty('site_404') && !$this->pathValidator->isValid($form_state->getValue('site_404'))) {
|
||||
$form_state->setErrorByName('site_404', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_404'))));
|
||||
$form_state->setErrorByName('site_404', $this->t("The path '%path' is either invalid or you do not have access to it.", ['%path' => $form_state->getValue('site_404')]));
|
||||
}
|
||||
|
||||
parent::validateForm($form, $form_state);
|
||||
|
|
|
@ -6,6 +6,7 @@ use Drupal\Core\Config\ConfigFactoryInterface;
|
|||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\Core\Form\ConfigFormBase;
|
||||
use Drupal\user\PermissionHandlerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
@ -20,6 +21,13 @@ class SiteMaintenanceModeForm extends ConfigFormBase {
|
|||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* The permission handler.
|
||||
*
|
||||
* @var \Drupal\user\PermissionHandlerInterface
|
||||
*/
|
||||
protected $permissionHandler;
|
||||
|
||||
/**
|
||||
* Constructs a new SiteMaintenanceModeForm.
|
||||
*
|
||||
|
@ -27,10 +35,13 @@ class SiteMaintenanceModeForm extends ConfigFormBase {
|
|||
* The factory for configuration objects.
|
||||
* @param \Drupal\Core\State\StateInterface $state
|
||||
* The state keyvalue collection to use.
|
||||
* @param \Drupal\user\PermissionHandlerInterface $permission_handler
|
||||
* The permission handler.
|
||||
*/
|
||||
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state) {
|
||||
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state, PermissionHandlerInterface $permission_handler) {
|
||||
parent::__construct($config_factory);
|
||||
$this->state = $state;
|
||||
$this->permissionHandler = $permission_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,7 +50,8 @@ class SiteMaintenanceModeForm extends ConfigFormBase {
|
|||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('config.factory'),
|
||||
$container->get('state')
|
||||
$container->get('state'),
|
||||
$container->get('user.permissions')
|
||||
);
|
||||
}
|
||||
/**
|
||||
|
@ -61,17 +73,19 @@ class SiteMaintenanceModeForm extends ConfigFormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$config = $this->config('system.maintenance');
|
||||
$form['maintenance_mode'] = array(
|
||||
$permissions = $this->permissionHandler->getPermissions();
|
||||
$permission_label = $permissions['access site in maintenance mode']['title'];
|
||||
$form['maintenance_mode'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Put site into maintenance mode'),
|
||||
'#default_value' => $this->state->get('system.maintenance_mode'),
|
||||
'#description' => t('Visitors will only see the maintenance mode message. Only users with the "Access site in maintenance mode" <a href=":permissions-url">permission</a> will be able to access the site. Authorized users can log in directly via the <a href=":user-login">user login</a> page.', array(':permissions-url' => $this->url('user.admin_permissions'), ':user-login' => $this->url('user.login'))),
|
||||
);
|
||||
$form['maintenance_mode_message'] = array(
|
||||
'#description' => t('Visitors will only see the maintenance mode message. Only users with the "@permission-label" <a href=":permissions-url">permission</a> will be able to access the site. Authorized users can log in directly via the <a href=":user-login">user login</a> page.', ['@permission-label' => $permission_label, ':permissions-url' => $this->url('user.admin_permissions'), ':user-login' => $this->url('user.login')]),
|
||||
];
|
||||
$form['maintenance_mode_message'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Message to display when in maintenance mode'),
|
||||
'#default_value' => $config->get('message'),
|
||||
);
|
||||
];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
|
|
@ -29,24 +29,24 @@ class ThemeAdminForm extends ConfigFormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, array $theme_options = NULL) {
|
||||
// Administration theme settings.
|
||||
$form['admin_theme'] = array(
|
||||
$form['admin_theme'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Administration theme'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
$form['admin_theme']['admin_theme'] = array(
|
||||
];
|
||||
$form['admin_theme']['admin_theme'] = [
|
||||
'#type' => 'select',
|
||||
'#options' => array(0 => $this->t('Default theme')) + $theme_options,
|
||||
'#options' => [0 => $this->t('Default theme')] + $theme_options,
|
||||
'#title' => $this->t('Administration theme'),
|
||||
'#description' => $this->t('Choose "Default theme" to always use the same theme as the rest of the site.'),
|
||||
'#default_value' => $this->config('system.theme')->get('admin'),
|
||||
);
|
||||
$form['admin_theme']['actions'] = array('#type' => 'actions');
|
||||
$form['admin_theme']['actions']['submit'] = array(
|
||||
];
|
||||
$form['admin_theme']['actions'] = ['#type' => 'actions'];
|
||||
$form['admin_theme']['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save configuration'),
|
||||
'#button_type' => 'primary',
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Form\ConfigFormBase;
|
||||
use Drupal\Core\Theme\ThemeManagerInterface;
|
||||
|
||||
/**
|
||||
* Displays theme configuration for entire site and individual themes.
|
||||
|
@ -46,6 +47,13 @@ class ThemeSettingsForm extends ConfigFormBase {
|
|||
*/
|
||||
protected $editableConfig = [];
|
||||
|
||||
/**
|
||||
* The theme manager.
|
||||
*
|
||||
* @var \Drupal\Core\Theme\ThemeManagerInterface
|
||||
*/
|
||||
protected $themeManager;
|
||||
|
||||
/**
|
||||
* Constructs a ThemeSettingsForm object.
|
||||
*
|
||||
|
@ -58,12 +66,13 @@ class ThemeSettingsForm extends ConfigFormBase {
|
|||
* @param \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface $mime_type_guesser
|
||||
* The MIME type guesser instance to use.
|
||||
*/
|
||||
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, MimeTypeGuesserInterface $mime_type_guesser) {
|
||||
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, MimeTypeGuesserInterface $mime_type_guesser, ThemeManagerInterface $theme_manager) {
|
||||
parent::__construct($config_factory);
|
||||
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->themeHandler = $theme_handler;
|
||||
$this->mimeTypeGuesser = $mime_type_guesser;
|
||||
$this->themeManager = $theme_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,7 +83,8 @@ class ThemeSettingsForm extends ConfigFormBase {
|
|||
$container->get('config.factory'),
|
||||
$container->get('module_handler'),
|
||||
$container->get('theme_handler'),
|
||||
$container->get('file.mime_type.guesser')
|
||||
$container->get('file.mime_type.guesser'),
|
||||
$container->get('theme.manager')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -122,25 +132,25 @@ class ThemeSettingsForm extends ConfigFormBase {
|
|||
// by https://www.drupal.org/node/2402467.
|
||||
$this->editableConfig = [$config_key];
|
||||
|
||||
$form['var'] = array(
|
||||
$form['var'] = [
|
||||
'#type' => 'hidden',
|
||||
'#value' => $var
|
||||
);
|
||||
$form['config_key'] = array(
|
||||
];
|
||||
$form['config_key'] = [
|
||||
'#type' => 'hidden',
|
||||
'#value' => $config_key
|
||||
);
|
||||
];
|
||||
|
||||
// Toggle settings
|
||||
$toggles = array(
|
||||
$toggles = [
|
||||
'node_user_picture' => t('User pictures in posts'),
|
||||
'comment_user_picture' => t('User pictures in comments'),
|
||||
'comment_user_verification' => t('User verification status in comments'),
|
||||
'favicon' => t('Shortcut icon'),
|
||||
);
|
||||
];
|
||||
|
||||
// Some features are not always available
|
||||
$disabled = array();
|
||||
$disabled = [];
|
||||
if (!user_picture_enabled()) {
|
||||
$disabled['toggle_node_user_picture'] = TRUE;
|
||||
$disabled['toggle_comment_user_picture'] = TRUE;
|
||||
|
@ -150,14 +160,14 @@ class ThemeSettingsForm extends ConfigFormBase {
|
|||
$disabled['toggle_comment_user_verification'] = TRUE;
|
||||
}
|
||||
|
||||
$form['theme_settings'] = array(
|
||||
$form['theme_settings'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Page element display'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
];
|
||||
foreach ($toggles as $name => $title) {
|
||||
if ((!$theme) || in_array($name, $features)) {
|
||||
$form['theme_settings']['toggle_' . $name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => theme_get_setting('features.' . $name, $theme));
|
||||
$form['theme_settings']['toggle_' . $name] = ['#type' => 'checkbox', '#title' => $title, '#default_value' => theme_get_setting('features.' . $name, $theme)];
|
||||
// Disable checkboxes for features not supported in the current configuration.
|
||||
if (isset($disabled['toggle_' . $name])) {
|
||||
$form['theme_settings']['toggle_' . $name]['#disabled'] = TRUE;
|
||||
|
@ -173,82 +183,82 @@ class ThemeSettingsForm extends ConfigFormBase {
|
|||
|
||||
// Logo settings, only available when file.module is enabled.
|
||||
if ((!$theme || in_array('logo', $features)) && $this->moduleHandler->moduleExists('file')) {
|
||||
$form['logo'] = array(
|
||||
$form['logo'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Logo image'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
$form['logo']['default_logo'] = array(
|
||||
];
|
||||
$form['logo']['default_logo'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use the logo supplied by the theme'),
|
||||
'#default_value' => theme_get_setting('logo.use_default', $theme),
|
||||
'#tree' => FALSE,
|
||||
);
|
||||
$form['logo']['settings'] = array(
|
||||
];
|
||||
$form['logo']['settings'] = [
|
||||
'#type' => 'container',
|
||||
'#states' => array(
|
||||
'#states' => [
|
||||
// Hide the logo settings when using the default logo.
|
||||
'invisible' => array(
|
||||
'input[name="default_logo"]' => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['logo']['settings']['logo_path'] = array(
|
||||
'invisible' => [
|
||||
'input[name="default_logo"]' => ['checked' => TRUE],
|
||||
],
|
||||
],
|
||||
];
|
||||
$form['logo']['settings']['logo_path'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Path to custom logo'),
|
||||
'#default_value' => theme_get_setting('logo.path', $theme),
|
||||
);
|
||||
$form['logo']['settings']['logo_upload'] = array(
|
||||
];
|
||||
$form['logo']['settings']['logo_upload'] = [
|
||||
'#type' => 'file',
|
||||
'#title' => t('Upload logo image'),
|
||||
'#maxlength' => 40,
|
||||
'#description' => t("If you don't have direct file access to the server, use this field to upload your logo.")
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
if (((!$theme) || in_array('favicon', $features)) && $this->moduleHandler->moduleExists('file')) {
|
||||
$form['favicon'] = array(
|
||||
$form['favicon'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Favicon'),
|
||||
'#open' => TRUE,
|
||||
'#description' => t("Your shortcut icon, or favicon, is displayed in the address bar and bookmarks of most browsers."),
|
||||
'#states' => array(
|
||||
'#states' => [
|
||||
// Hide the shortcut icon settings fieldset when shortcut icon display
|
||||
// is disabled.
|
||||
'invisible' => array(
|
||||
'input[name="toggle_favicon"]' => array('checked' => FALSE),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['favicon']['default_favicon'] = array(
|
||||
'invisible' => [
|
||||
'input[name="toggle_favicon"]' => ['checked' => FALSE],
|
||||
],
|
||||
],
|
||||
];
|
||||
$form['favicon']['default_favicon'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use the favicon supplied by the theme'),
|
||||
'#default_value' => theme_get_setting('favicon.use_default', $theme),
|
||||
);
|
||||
$form['favicon']['settings'] = array(
|
||||
];
|
||||
$form['favicon']['settings'] = [
|
||||
'#type' => 'container',
|
||||
'#states' => array(
|
||||
'#states' => [
|
||||
// Hide the favicon settings when using the default favicon.
|
||||
'invisible' => array(
|
||||
'input[name="default_favicon"]' => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['favicon']['settings']['favicon_path'] = array(
|
||||
'invisible' => [
|
||||
'input[name="default_favicon"]' => ['checked' => TRUE],
|
||||
],
|
||||
],
|
||||
];
|
||||
$form['favicon']['settings']['favicon_path'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Path to custom icon'),
|
||||
'#default_value' => theme_get_setting('favicon.path', $theme),
|
||||
);
|
||||
$form['favicon']['settings']['favicon_upload'] = array(
|
||||
];
|
||||
$form['favicon']['settings']['favicon_upload'] = [
|
||||
'#type' => 'file',
|
||||
'#title' => t('Upload favicon image'),
|
||||
'#description' => t("If you don't have direct file access to the server, use this field to upload your shortcut icon.")
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Inject human-friendly values and form element descriptions for logo and
|
||||
// favicon.
|
||||
foreach (array('logo' => 'logo.svg', 'favicon' => 'favicon.ico') as $type => $default) {
|
||||
foreach (['logo' => 'logo.svg', 'favicon' => 'favicon.ico'] as $type => $default) {
|
||||
if (isset($form[$type]['settings'][$type . '_path'])) {
|
||||
$element = &$form[$type]['settings'][$type . '_path'];
|
||||
|
||||
|
@ -263,20 +273,20 @@ class ThemeSettingsForm extends ConfigFormBase {
|
|||
|
||||
// Prepare local file path for description.
|
||||
if ($original_path && isset($friendly_path)) {
|
||||
$local_file = strtr($original_path, array('public:/' => PublicStream::basePath()));
|
||||
$local_file = strtr($original_path, ['public:/' => PublicStream::basePath()]);
|
||||
}
|
||||
elseif ($theme) {
|
||||
$local_file = drupal_get_path('theme', $theme) . '/' . $default;
|
||||
}
|
||||
else {
|
||||
$local_file = \Drupal::theme()->getActiveTheme()->getPath() . '/' . $default;
|
||||
$local_file = $this->themeManager->getActiveTheme()->getPath() . '/' . $default;
|
||||
}
|
||||
|
||||
$element['#description'] = t('Examples: <code>@implicit-public-file</code> (for a file in the public filesystem), <code>@explicit-file</code>, or <code>@local-file</code>.', array(
|
||||
$element['#description'] = t('Examples: <code>@implicit-public-file</code> (for a file in the public filesystem), <code>@explicit-file</code>, or <code>@local-file</code>.', [
|
||||
'@implicit-public-file' => isset($friendly_path) ? $friendly_path : $default,
|
||||
'@explicit-file' => file_uri_scheme($original_path) !== FALSE ? $original_path : 'public://' . $default,
|
||||
'@local-file' => $local_file,
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -284,12 +294,12 @@ class ThemeSettingsForm extends ConfigFormBase {
|
|||
// Call engine-specific settings.
|
||||
$function = $themes[$theme]->prefix . '_engine_settings';
|
||||
if (function_exists($function)) {
|
||||
$form['engine_specific'] = array(
|
||||
$form['engine_specific'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Theme-engine-specific settings'),
|
||||
'#open' => TRUE,
|
||||
'#description' => t('These settings only exist for the themes based on the %engine theme engine.', array('%engine' => $themes[$theme]->prefix)),
|
||||
);
|
||||
'#description' => t('These settings only exist for the themes based on the %engine theme engine.', ['%engine' => $themes[$theme]->prefix]),
|
||||
];
|
||||
$function($form, $form_state);
|
||||
}
|
||||
|
||||
|
@ -299,17 +309,17 @@ class ThemeSettingsForm extends ConfigFormBase {
|
|||
$theme_keys[] = $theme;
|
||||
}
|
||||
else {
|
||||
$theme_keys = array($theme);
|
||||
$theme_keys = [$theme];
|
||||
}
|
||||
|
||||
// Save the name of the current theme (if any), so that we can temporarily
|
||||
// override the current theme and allow theme_get_setting() to work
|
||||
// without having to pass the theme name to it.
|
||||
$default_active_theme = \Drupal::theme()->getActiveTheme();
|
||||
$default_active_theme = $this->themeManager->getActiveTheme();
|
||||
$default_theme = $default_active_theme->getName();
|
||||
/** @var \Drupal\Core\Theme\ThemeInitialization $theme_initialization */
|
||||
$theme_initialization = \Drupal::service('theme.initialization');
|
||||
\Drupal::theme()->setActiveTheme($theme_initialization->getActiveThemeByName($theme));
|
||||
$this->themeManager->setActiveTheme($theme_initialization->getActiveThemeByName($theme));
|
||||
|
||||
// Process the theme and all its base themes.
|
||||
foreach ($theme_keys as $theme) {
|
||||
|
@ -328,10 +338,10 @@ class ThemeSettingsForm extends ConfigFormBase {
|
|||
|
||||
// Restore the original current theme.
|
||||
if (isset($default_theme)) {
|
||||
\Drupal::theme()->setActiveTheme($default_active_theme);
|
||||
$this->themeManager->setActiveTheme($default_active_theme);
|
||||
}
|
||||
else {
|
||||
\Drupal::theme()->resetActiveTheme();
|
||||
$this->themeManager->resetActiveTheme();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -346,7 +356,7 @@ class ThemeSettingsForm extends ConfigFormBase {
|
|||
|
||||
if ($this->moduleHandler->moduleExists('file')) {
|
||||
// Handle file uploads.
|
||||
$validators = array('file_validate_is_image' => array());
|
||||
$validators = ['file_validate_is_image' => []];
|
||||
|
||||
// Check for a new uploaded logo.
|
||||
$file = file_save_upload('logo_upload', $validators, FALSE, 0);
|
||||
|
@ -362,7 +372,7 @@ class ThemeSettingsForm extends ConfigFormBase {
|
|||
}
|
||||
}
|
||||
|
||||
$validators = array('file_validate_extensions' => array('ico png gif jpg jpeg apng svg'));
|
||||
$validators = ['file_validate_extensions' => ['ico png gif jpg jpeg apng svg']];
|
||||
|
||||
// Check for a new uploaded favicon.
|
||||
$file = file_save_upload('favicon_upload', $validators, FALSE, 0);
|
||||
|
|
|
@ -52,7 +52,7 @@ class PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface {
|
|||
protected $router;
|
||||
|
||||
/**
|
||||
* The dynamic router service.
|
||||
* The inbound path processor.
|
||||
*
|
||||
* @var \Drupal\Core\PathProcessor\InboundPathProcessorInterface
|
||||
*/
|
||||
|
@ -122,14 +122,14 @@ class PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface {
|
|||
*/
|
||||
public function build(RouteMatchInterface $route_match) {
|
||||
$breadcrumb = new Breadcrumb();
|
||||
$links = array();
|
||||
$links = [];
|
||||
|
||||
// General path-based breadcrumbs. Use the actual request path, prior to
|
||||
// resolving path aliases, so the breadcrumb can be defined by simply
|
||||
// creating a hierarchy of path aliases.
|
||||
$path = trim($this->context->getPathInfo(), '/');
|
||||
$path_elements = explode('/', $path);
|
||||
$exclude = array();
|
||||
$exclude = [];
|
||||
// Don't show a link to the front-page path.
|
||||
$front = $this->config->get('page.front');
|
||||
$exclude[$front] = TRUE;
|
||||
|
@ -154,7 +154,7 @@ class PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface {
|
|||
if (!isset($title)) {
|
||||
// Fallback to using the raw path component as the title if the
|
||||
// route is missing a _title or _title_callback attribute.
|
||||
$title = str_replace(array('-', '_'), ' ', Unicode::ucfirst(end($path_elements)));
|
||||
$title = str_replace(['-', '_'], ' ', Unicode::ucfirst(end($path_elements)));
|
||||
}
|
||||
$url = Url::fromRouteMatch($route_match);
|
||||
$links[] = new Link($title, $url);
|
||||
|
|
|
@ -60,12 +60,12 @@ class SystemBrandingBlock extends BlockBase implements ContainerFactoryPluginInt
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array(
|
||||
return [
|
||||
'use_site_logo' => TRUE,
|
||||
'use_site_name' => TRUE,
|
||||
'use_site_slogan' => TRUE,
|
||||
'label_display' => FALSE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,15 +77,15 @@ class SystemBrandingBlock extends BlockBase implements ContainerFactoryPluginInt
|
|||
|
||||
// Get permissions.
|
||||
$url_system_theme_settings = new Url('system.theme_settings');
|
||||
$url_system_theme_settings_theme = new Url('system.theme_settings_theme', array('theme' => $theme));
|
||||
$url_system_theme_settings_theme = new Url('system.theme_settings_theme', ['theme' => $theme]);
|
||||
|
||||
if ($url_system_theme_settings->access() && $url_system_theme_settings_theme->access()) {
|
||||
// Provide links to the Appearance Settings and Theme Settings pages
|
||||
// if the user has access to administer themes.
|
||||
$site_logo_description = $this->t('Defined on the <a href=":appearance">Appearance Settings</a> or <a href=":theme">Theme Settings</a> page.', array(
|
||||
$site_logo_description = $this->t('Defined on the <a href=":appearance">Appearance Settings</a> or <a href=":theme">Theme Settings</a> page.', [
|
||||
':appearance' => $url_system_theme_settings->toString(),
|
||||
':theme' => $url_system_theme_settings_theme->toString(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
else {
|
||||
// Explain that the user does not have access to the Appearance and Theme
|
||||
|
@ -99,8 +99,8 @@ class SystemBrandingBlock extends BlockBase implements ContainerFactoryPluginInt
|
|||
|
||||
// Provide link to Site Information page if the user has access to
|
||||
// administer site configuration.
|
||||
$site_name_description = $this->t('Defined on the <a href=":information">Site Information</a> page.', array(':information' => $site_information_url));
|
||||
$site_slogan_description = $this->t('Defined on the <a href=":information">Site Information</a> page.', array(':information' => $site_information_url));
|
||||
$site_name_description = $this->t('Defined on the <a href=":information">Site Information</a> page.', [':information' => $site_information_url]);
|
||||
$site_slogan_description = $this->t('Defined on the <a href=":information">Site Information</a> page.', [':information' => $site_information_url]);
|
||||
}
|
||||
else {
|
||||
// Explain that the user does not have access to the Site Information
|
||||
|
@ -109,30 +109,30 @@ class SystemBrandingBlock extends BlockBase implements ContainerFactoryPluginInt
|
|||
$site_slogan_description = $this->t('Defined on the Site Information page. You do not have the appropriate permissions to change the site logo.');
|
||||
}
|
||||
|
||||
$form['block_branding'] = array(
|
||||
$form['block_branding'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => $this->t('Toggle branding elements'),
|
||||
'#description' => $this->t('Choose which branding elements you want to show in this block instance.'),
|
||||
);
|
||||
$form['block_branding']['use_site_logo'] = array(
|
||||
];
|
||||
$form['block_branding']['use_site_logo'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Site logo'),
|
||||
'#description' => $site_logo_description,
|
||||
'#default_value' => $this->configuration['use_site_logo'],
|
||||
);
|
||||
];
|
||||
|
||||
$form['block_branding']['use_site_name'] = array(
|
||||
$form['block_branding']['use_site_name'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Site name'),
|
||||
'#description' => $site_name_description,
|
||||
'#default_value' => $this->configuration['use_site_name'],
|
||||
);
|
||||
$form['block_branding']['use_site_slogan'] = array(
|
||||
];
|
||||
$form['block_branding']['use_site_slogan'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Site slogan'),
|
||||
'#description' => $site_slogan_description,
|
||||
'#default_value' => $this->configuration['use_site_slogan'],
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -150,25 +150,25 @@ class SystemBrandingBlock extends BlockBase implements ContainerFactoryPluginInt
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
$build = array();
|
||||
$build = [];
|
||||
$site_config = $this->configFactory->get('system.site');
|
||||
|
||||
$build['site_logo'] = array(
|
||||
$build['site_logo'] = [
|
||||
'#theme' => 'image',
|
||||
'#uri' => theme_get_setting('logo.url'),
|
||||
'#alt' => $this->t('Home'),
|
||||
'#access' => $this->configuration['use_site_logo'],
|
||||
);
|
||||
];
|
||||
|
||||
$build['site_name'] = array(
|
||||
$build['site_name'] = [
|
||||
'#markup' => $site_config->get('name'),
|
||||
'#access' => $this->configuration['use_site_name'],
|
||||
);
|
||||
];
|
||||
|
||||
$build['site_slogan'] = array(
|
||||
$build['site_slogan'] = [
|
||||
'#markup' => $site_config->get('slogan'),
|
||||
'#access' => $this->configuration['use_site_slogan'],
|
||||
);
|
||||
];
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
|
|
@ -76,36 +76,36 @@ class SystemMenuBlock extends BlockBase implements ContainerFactoryPluginInterfa
|
|||
$config = $this->configuration;
|
||||
|
||||
$defaults = $this->defaultConfiguration();
|
||||
$form['menu_levels'] = array(
|
||||
$form['menu_levels'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Menu levels'),
|
||||
// Open if not set to defaults.
|
||||
'#open' => $defaults['level'] !== $config['level'] || $defaults['depth'] !== $config['depth'],
|
||||
'#process' => [[get_class(), 'processMenuLevelParents']],
|
||||
);
|
||||
];
|
||||
|
||||
$options = range(0, $this->menuTree->maxDepth());
|
||||
unset($options[0]);
|
||||
|
||||
$form['menu_levels']['level'] = array(
|
||||
$form['menu_levels']['level'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Initial menu level'),
|
||||
'#title' => $this->t('Initial visibility level'),
|
||||
'#default_value' => $config['level'],
|
||||
'#options' => $options,
|
||||
'#description' => $this->t('The menu will only be visible if the menu item for the current page is at or below the selected starting level. Select level 1 to always keep this menu visible.'),
|
||||
'#description' => $this->t('The menu is only visible if the menu item for the current page is at this level or below it. Use level 1 to always display this menu.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$options[0] = $this->t('Unlimited');
|
||||
|
||||
$form['menu_levels']['depth'] = array(
|
||||
$form['menu_levels']['depth'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Maximum number of menu levels to display'),
|
||||
'#title' => $this->t('Number of levels to display'),
|
||||
'#default_value' => $config['depth'],
|
||||
'#options' => $options,
|
||||
'#description' => $this->t('The maximum number of menu levels to show, starting from the initial menu level. For example: with an initial level 2 and a maximum number of 3, menu levels 2, 3 and 4 can be displayed.'),
|
||||
'#description' => $this->t('This maximum number includes the initial level.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
@ -148,10 +148,10 @@ class SystemMenuBlock extends BlockBase implements ContainerFactoryPluginInterfa
|
|||
}
|
||||
|
||||
$tree = $this->menuTree->load($menu_name, $parameters);
|
||||
$manipulators = array(
|
||||
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
|
||||
array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'),
|
||||
);
|
||||
$manipulators = [
|
||||
['callable' => 'menu.default_tree_manipulators:checkAccess'],
|
||||
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
|
||||
];
|
||||
$tree = $this->menuTree->transform($tree, $manipulators);
|
||||
return $this->menuTree->build($tree);
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ class SystemMessagesBlock extends BlockBase implements MessagesBlockPluginInterf
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array(
|
||||
return [
|
||||
'label_display' => FALSE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,7 @@ class SystemPoweredByBlock extends BlockBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
return array('#markup' => '<span>' . $this->t('Powered by <a href=":poweredby">Drupal</a>', array(':poweredby' => 'https://www.drupal.org')) . '</span>');
|
||||
return ['#markup' => '<span>' . $this->t('Powered by <a href=":poweredby">Drupal</a>', [':poweredby' => 'https://www.drupal.org']) . '</span>'];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -70,21 +70,21 @@ class CurrentThemeCondition extends ConditionPluginBase implements ContainerFact
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array('theme' => '') + parent::defaultConfiguration();
|
||||
return ['theme' => ''] + parent::defaultConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$form['theme'] = array(
|
||||
$form['theme'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Theme'),
|
||||
'#default_value' => $this->configuration['theme'],
|
||||
'#options' => array_map(function ($theme_info) {
|
||||
return $theme_info->info['name'];
|
||||
}, $this->themeHandler->listInfo()),
|
||||
);
|
||||
];
|
||||
return parent::buildConfigurationForm($form, $form_state);
|
||||
}
|
||||
|
||||
|
@ -112,10 +112,10 @@ class CurrentThemeCondition extends ConditionPluginBase implements ContainerFact
|
|||
*/
|
||||
public function summary() {
|
||||
if ($this->isNegated()) {
|
||||
return $this->t('The current theme is not @theme', array('@theme' => $this->configuration['theme']));
|
||||
return $this->t('The current theme is not @theme', ['@theme' => $this->configuration['theme']]);
|
||||
}
|
||||
|
||||
return $this->t('The current theme is @theme', array('@theme' => $this->configuration['theme']));
|
||||
return $this->t('The current theme is @theme', ['@theme' => $this->configuration['theme']]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -94,22 +94,22 @@ class RequestPath extends ConditionPluginBase implements ContainerFactoryPluginI
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array('pages' => '') + parent::defaultConfiguration();
|
||||
return ['pages' => ''] + parent::defaultConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$form['pages'] = array(
|
||||
$form['pages'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Pages'),
|
||||
'#default_value' => $this->configuration['pages'],
|
||||
'#description' => $this->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. An example path is %user-wildcard for every user page. %front is the front page.", array(
|
||||
'#description' => $this->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. An example path is %user-wildcard for every user page. %front is the front page.", [
|
||||
'%user-wildcard' => '/user/*',
|
||||
'%front' => '<front>',
|
||||
)),
|
||||
);
|
||||
]),
|
||||
];
|
||||
return parent::buildConfigurationForm($form, $form_state);
|
||||
}
|
||||
|
||||
|
@ -128,9 +128,9 @@ class RequestPath extends ConditionPluginBase implements ContainerFactoryPluginI
|
|||
$pages = array_map('trim', explode("\n", $this->configuration['pages']));
|
||||
$pages = implode(', ', $pages);
|
||||
if (!empty($this->configuration['negate'])) {
|
||||
return $this->t('Do not return true on the following pages: @pages', array('@pages' => $pages));
|
||||
return $this->t('Do not return true on the following pages: @pages', ['@pages' => $pages]);
|
||||
}
|
||||
return $this->t('Return true on the following pages: @pages', array('@pages' => $pages));
|
||||
return $this->t('Return true on the following pages: @pages', ['@pages' => $pages]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,7 +47,7 @@ class SystemMenuBlock extends DeriverBase implements ContainerDeriverInterface {
|
|||
foreach ($this->menuStorage->loadMultiple() as $menu => $entity) {
|
||||
$this->derivatives[$menu] = $base_plugin_definition;
|
||||
$this->derivatives[$menu]['admin_label'] = $entity->label();
|
||||
$this->derivatives[$menu]['config_dependencies']['config'] = array($entity->getConfigDependencyName());
|
||||
$this->derivatives[$menu]['config_dependencies']['config'] = [$entity->getConfigDependencyName()];
|
||||
}
|
||||
return $this->derivatives;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class ThemeLocalTask extends DeriverBase implements ContainerDeriverInterface {
|
|||
if ($this->themeHandler->hasUi($theme_name)) {
|
||||
$this->derivatives[$theme_name] = $base_plugin_definition;
|
||||
$this->derivatives[$theme_name]['title'] = $theme->info['name'];
|
||||
$this->derivatives[$theme_name]['route_parameters'] = array('theme' => $theme_name);
|
||||
$this->derivatives[$theme_name]['route_parameters'] = ['theme' => $theme_name];
|
||||
}
|
||||
}
|
||||
return $this->derivatives;
|
||||
|
|
|
@ -143,7 +143,7 @@ class GDToolkit extends ImageToolkitBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$form['image_jpeg_quality'] = array(
|
||||
$form['image_jpeg_quality'] = [
|
||||
'#type' => 'number',
|
||||
'#title' => t('JPEG quality'),
|
||||
'#description' => t('Define the image quality for JPEG manipulations. Ranges from 0 to 100. Higher values mean better image quality but bigger files.'),
|
||||
|
@ -151,7 +151,7 @@ class GDToolkit extends ImageToolkitBase {
|
|||
'#max' => 100,
|
||||
'#default_value' => $this->configFactory->getEditable('system.image.gd')->get('jpeg_quality', FALSE),
|
||||
'#field_suffix' => t('%'),
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ class GDToolkit extends ImageToolkitBase {
|
|||
*/
|
||||
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->configFactory->getEditable('system.image.gd')
|
||||
->set('jpeg_quality', $form_state->getValue(array('gd', 'image_jpeg_quality')))
|
||||
->set('jpeg_quality', $form_state->getValue(['gd', 'image_jpeg_quality']))
|
||||
->save();
|
||||
}
|
||||
|
||||
|
@ -186,13 +186,13 @@ class GDToolkit extends ImageToolkitBase {
|
|||
// Convert indexed images to truecolor, copying the image to a new
|
||||
// truecolor resource, so that filters work correctly and don't result
|
||||
// in unnecessary dither.
|
||||
$data = array(
|
||||
$data = [
|
||||
'width' => imagesx($resource),
|
||||
'height' => imagesy($resource),
|
||||
'extension' => image_type_to_extension($this->getType(), FALSE),
|
||||
'transparent_color' => $this->getTransparentColor(),
|
||||
'is_temp' => TRUE,
|
||||
);
|
||||
];
|
||||
if ($this->apply('create_new', $data)) {
|
||||
imagecopy($this->getResource(), $resource, 0, 0, 0, 0, imagesx($resource), imagesy($resource));
|
||||
imagedestroy($resource);
|
||||
|
@ -362,13 +362,13 @@ class GDToolkit extends ImageToolkitBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRequirements() {
|
||||
$requirements = array();
|
||||
$requirements = [];
|
||||
|
||||
$info = gd_info();
|
||||
$requirements['version'] = array(
|
||||
$requirements['version'] = [
|
||||
'title' => t('GD library'),
|
||||
'value' => $info['GD Version'],
|
||||
);
|
||||
];
|
||||
|
||||
// Check for filter and rotate support.
|
||||
if (!function_exists('imagefilter') || !function_exists('imagerotate')) {
|
||||
|
@ -391,7 +391,7 @@ class GDToolkit extends ImageToolkitBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSupportedExtensions() {
|
||||
$extensions = array();
|
||||
$extensions = [];
|
||||
foreach (static::supportedTypes() as $image_type) {
|
||||
// @todo Automatically fetch possible extensions for each mime type.
|
||||
// @see https://www.drupal.org/node/2311679
|
||||
|
@ -440,7 +440,7 @@ class GDToolkit extends ImageToolkitBase {
|
|||
* IMAGETYPE_* constant (e.g. IMAGETYPE_JPEG, IMAGETYPE_PNG, etc.).
|
||||
*/
|
||||
protected static function supportedTypes() {
|
||||
return array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF);
|
||||
return [IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,11 +19,11 @@ class Convert extends GDImageToolkitOperationBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function arguments() {
|
||||
return array(
|
||||
'extension' => array(
|
||||
return [
|
||||
'extension' => [
|
||||
'description' => 'The new extension of the converted image',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,13 +47,13 @@ class Convert extends GDImageToolkitOperationBase {
|
|||
$height = $this->getToolkit()->getHeight();
|
||||
$original_resource = $this->getToolkit()->getResource();
|
||||
$original_type = $this->getToolkit()->getType();
|
||||
$data = array(
|
||||
$data = [
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
'extension' => $arguments['extension'],
|
||||
'transparent_color' => $this->getToolkit()->getTransparentColor(),
|
||||
'is_temp' => TRUE,
|
||||
);
|
||||
];
|
||||
if ($this->getToolkit()->apply('create_new', $data)) {
|
||||
if (imagecopyresampled($this->getToolkit()->getResource(), $original_resource, 0, 0, 0, 0, $width, $height, $width, $height)) {
|
||||
imagedestroy($original_resource);
|
||||
|
|
|
@ -21,29 +21,29 @@ class CreateNew extends GDImageToolkitOperationBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function arguments() {
|
||||
return array(
|
||||
'width' => array(
|
||||
return [
|
||||
'width' => [
|
||||
'description' => 'The width of the image, in pixels',
|
||||
),
|
||||
'height' => array(
|
||||
],
|
||||
'height' => [
|
||||
'description' => 'The height of the image, in pixels',
|
||||
),
|
||||
'extension' => array(
|
||||
],
|
||||
'extension' => [
|
||||
'description' => 'The extension of the image file (e.g. png, gif, etc.)',
|
||||
'required' => FALSE,
|
||||
'default' => 'png',
|
||||
),
|
||||
'transparent_color' => array(
|
||||
],
|
||||
'transparent_color' => [
|
||||
'description' => 'The RGB hex color for GIF transparency',
|
||||
'required' => FALSE,
|
||||
'default' => '#ffffff',
|
||||
),
|
||||
'is_temp' => array(
|
||||
],
|
||||
'is_temp' => [
|
||||
'description' => 'If TRUE, this operation is being used to create a temporary image by another GD operation. After performing its function, the caller is responsible for destroying the original GD resource.',
|
||||
'required' => FALSE,
|
||||
'default' => FALSE,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,24 +19,24 @@ class Crop extends GDImageToolkitOperationBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function arguments() {
|
||||
return array(
|
||||
'x' => array(
|
||||
return [
|
||||
'x' => [
|
||||
'description' => 'The starting x offset at which to start the crop, in pixels',
|
||||
),
|
||||
'y' => array(
|
||||
],
|
||||
'y' => [
|
||||
'description' => 'The starting y offset at which to start the crop, in pixels',
|
||||
),
|
||||
'width' => array(
|
||||
],
|
||||
'width' => [
|
||||
'description' => 'The width of the cropped area, in pixels',
|
||||
'required' => FALSE,
|
||||
'default' => NULL,
|
||||
),
|
||||
'height' => array(
|
||||
],
|
||||
'height' => [
|
||||
'description' => 'The height of the cropped area, in pixels',
|
||||
'required' => FALSE,
|
||||
'default' => NULL,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,7 +54,7 @@ class Crop extends GDImageToolkitOperationBase {
|
|||
$arguments['width'] = empty($arguments['width']) ? $arguments['height'] / $aspect : $arguments['width'];
|
||||
|
||||
// Assure integers for all arguments.
|
||||
foreach (array('x', 'y', 'width', 'height') as $key) {
|
||||
foreach (['x', 'y', 'width', 'height'] as $key) {
|
||||
$arguments[$key] = (int) round($arguments[$key]);
|
||||
}
|
||||
|
||||
|
@ -77,13 +77,13 @@ class Crop extends GDImageToolkitOperationBase {
|
|||
// the original resource on it with resampling. Destroy the original
|
||||
// resource upon success.
|
||||
$original_resource = $this->getToolkit()->getResource();
|
||||
$data = array(
|
||||
$data = [
|
||||
'width' => $arguments['width'],
|
||||
'height' => $arguments['height'],
|
||||
'extension' => image_type_to_extension($this->getToolkit()->getType(), FALSE),
|
||||
'transparent_color' => $this->getToolkit()->getTransparentColor(),
|
||||
'is_temp' => TRUE,
|
||||
);
|
||||
];
|
||||
if ($this->getToolkit()->apply('create_new', $data)) {
|
||||
if (imagecopyresampled($this->getToolkit()->getResource(), $original_resource, 0, 0, $arguments['x'], $arguments['y'], $arguments['width'], $arguments['height'], $arguments['width'], $arguments['height'])) {
|
||||
imagedestroy($original_resource);
|
||||
|
|
|
@ -20,7 +20,7 @@ class Desaturate extends GDImageToolkitOperationBase {
|
|||
*/
|
||||
protected function arguments() {
|
||||
// This operation does not use any parameters.
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@ class Desaturate extends GDImageToolkitOperationBase {
|
|||
protected function execute(array $arguments) {
|
||||
// PHP installations using non-bundled GD do not have imagefilter.
|
||||
if (!function_exists('imagefilter')) {
|
||||
$this->logger->notice("The image '@file' could not be desaturated because the imagefilter() function is not available in this PHP installation.", array('@file' => $this->getToolkit()->getSource()));
|
||||
$this->logger->notice("The image '@file' could not be desaturated because the imagefilter() function is not available in this PHP installation.", ['@file' => $this->getToolkit()->getSource()]);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,14 +19,14 @@ class Resize extends GDImageToolkitOperationBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function arguments() {
|
||||
return array(
|
||||
'width' => array(
|
||||
return [
|
||||
'width' => [
|
||||
'description' => 'The new width of the resized image, in pixels',
|
||||
),
|
||||
'height' => array(
|
||||
],
|
||||
'height' => [
|
||||
'description' => 'The new height of the resized image, in pixels',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,18 +51,18 @@ class Resize extends GDImageToolkitOperationBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(array $arguments = array()) {
|
||||
protected function execute(array $arguments = []) {
|
||||
// Create a new resource of the required dimensions, and copy and resize
|
||||
// the original resource on it with resampling. Destroy the original
|
||||
// resource upon success.
|
||||
$original_resource = $this->getToolkit()->getResource();
|
||||
$data = array(
|
||||
$data = [
|
||||
'width' => $arguments['width'],
|
||||
'height' => $arguments['height'],
|
||||
'extension' => image_type_to_extension($this->getToolkit()->getType(), FALSE),
|
||||
'transparent_color' => $this->getToolkit()->getTransparentColor(),
|
||||
'is_temp' => TRUE,
|
||||
);
|
||||
];
|
||||
if ($this->getToolkit()->apply('create_new', $data)) {
|
||||
if (imagecopyresampled($this->getToolkit()->getResource(), $original_resource, 0, 0, 0, 0, $arguments['width'], $arguments['height'], imagesx($original_resource), imagesy($original_resource))) {
|
||||
imagedestroy($original_resource);
|
||||
|
|
|
@ -21,16 +21,16 @@ class Rotate extends GDImageToolkitOperationBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function arguments() {
|
||||
return array(
|
||||
'degrees' => array(
|
||||
return [
|
||||
'degrees' => [
|
||||
'description' => 'The number of (clockwise) degrees to rotate the image',
|
||||
),
|
||||
'background' => array(
|
||||
],
|
||||
'background' => [
|
||||
'description' => "A string specifying the hexadecimal color code to use as background for the uncovered area of the image after the rotation. E.g. '#000000' for black, '#ff00ff' for magenta, and '#ffffff' for white. For images that support transparency, this will default to transparent white",
|
||||
'required' => FALSE,
|
||||
'default' => NULL,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,11 +45,11 @@ class Rotate extends GDImageToolkitOperationBase {
|
|||
// Validate or set background color argument.
|
||||
if (!empty($arguments['background'])) {
|
||||
// Validate the background color: Color::hexToRgb does so for us.
|
||||
$background = Color::hexToRgb($arguments['background']) + array( 'alpha' => 0 );
|
||||
$background = Color::hexToRgb($arguments['background']) + [ 'alpha' => 0 ];
|
||||
}
|
||||
else {
|
||||
// Background color is not specified: use transparent white as background.
|
||||
$background = array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127);
|
||||
$background = ['red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127];
|
||||
}
|
||||
// Store the color index for the background as that is what GD uses.
|
||||
$arguments['background_idx'] = imagecolorallocatealpha($this->getToolkit()->getResource(), $background['red'], $background['green'], $background['blue'], $background['alpha']);
|
||||
|
@ -89,7 +89,7 @@ class Rotate extends GDImageToolkitOperationBase {
|
|||
protected function execute(array $arguments) {
|
||||
// PHP installations using non-bundled GD do not have imagerotate.
|
||||
if (!function_exists('imagerotate')) {
|
||||
$this->logger->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', array('%file' => $this->getToolkit()->getSource()));
|
||||
$this->logger->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', ['%file' => $this->getToolkit()->getSource()]);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,23 +19,23 @@ class Scale extends Resize {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function arguments() {
|
||||
return array(
|
||||
'width' => array(
|
||||
return [
|
||||
'width' => [
|
||||
'description' => 'The target width, in pixels. This value is omitted then the scaling will based only on the height value',
|
||||
'required' => FALSE,
|
||||
'default' => NULL,
|
||||
),
|
||||
'height' => array(
|
||||
],
|
||||
'height' => [
|
||||
'description' => 'The target height, in pixels. This value is omitted then the scaling will based only on the width value',
|
||||
'required' => FALSE,
|
||||
'default' => NULL,
|
||||
),
|
||||
'upscale' => array(
|
||||
],
|
||||
'upscale' => [
|
||||
'description' => 'Boolean indicating that files smaller than the dimensions will be scaled up. This generally results in a low quality image',
|
||||
'required' => FALSE,
|
||||
'default' => FALSE,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,7 +78,7 @@ class Scale extends Resize {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(array $arguments = array()) {
|
||||
protected function execute(array $arguments = []) {
|
||||
// Don't scale if we don't change the dimensions at all.
|
||||
if ($arguments['width'] !== $this->getToolkit()->getWidth() || $arguments['height'] !== $this->getToolkit()->getHeight()) {
|
||||
// Don't upscale if the option isn't enabled.
|
||||
|
|
|
@ -19,14 +19,14 @@ class ScaleAndCrop extends GDImageToolkitOperationBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function arguments() {
|
||||
return array(
|
||||
'width' => array(
|
||||
return [
|
||||
'width' => [
|
||||
'description' => 'The target width, in pixels',
|
||||
),
|
||||
'height' => array(
|
||||
],
|
||||
'height' => [
|
||||
'description' => 'The target height, in pixels',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,10 +40,10 @@ class ScaleAndCrop extends GDImageToolkitOperationBase {
|
|||
|
||||
$arguments['x'] = (int) round(($actualWidth * $scaleFactor - $arguments['width']) / 2);
|
||||
$arguments['y'] = (int) round(($actualHeight * $scaleFactor - $arguments['height']) / 2);
|
||||
$arguments['resize'] = array(
|
||||
$arguments['resize'] = [
|
||||
'width' => (int) round($actualWidth * $scaleFactor),
|
||||
'height' => (int) round($actualHeight * $scaleFactor),
|
||||
);
|
||||
];
|
||||
|
||||
// Fail when width or height are 0 or negative.
|
||||
if ($arguments['width'] <= 0) {
|
||||
|
@ -59,7 +59,7 @@ class ScaleAndCrop extends GDImageToolkitOperationBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(array $arguments = array()) {
|
||||
protected function execute(array $arguments = []) {
|
||||
return $this->getToolkit()->apply('resize', $arguments['resize'])
|
||||
&& $this->getToolkit()->apply('crop', $arguments);
|
||||
}
|
||||
|
|
|
@ -25,11 +25,11 @@ class Menu extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'menu_name' => $this->t('The menu name. Primary key.'),
|
||||
'title' => $this->t('The human-readable name of the menu.'),
|
||||
'description' => $this->t('A description of the menu'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,7 +49,7 @@ class BulkForm extends FieldPluginBase implements CacheableDependencyInterface {
|
|||
*
|
||||
* @var \Drupal\system\ActionConfigEntityInterface[]
|
||||
*/
|
||||
protected $actions = array();
|
||||
protected $actions = [];
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
|
@ -162,13 +162,13 @@ class BulkForm extends FieldPluginBase implements CacheableDependencyInterface {
|
|||
*/
|
||||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
$options['action_title'] = array('default' => $this->t('Action'));
|
||||
$options['include_exclude'] = array(
|
||||
$options['action_title'] = ['default' => $this->t('Action')];
|
||||
$options['include_exclude'] = [
|
||||
'default' => 'exclude',
|
||||
);
|
||||
$options['selected_actions'] = array(
|
||||
'default' => array(),
|
||||
);
|
||||
];
|
||||
$options['selected_actions'] = [
|
||||
'default' => [],
|
||||
];
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
@ -176,28 +176,28 @@ class BulkForm extends FieldPluginBase implements CacheableDependencyInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
$form['action_title'] = array(
|
||||
$form['action_title'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Action title'),
|
||||
'#default_value' => $this->options['action_title'],
|
||||
'#description' => $this->t('The title shown above the actions dropdown.'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['include_exclude'] = array(
|
||||
$form['include_exclude'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('Available actions'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'exclude' => $this->t('All actions, except selected'),
|
||||
'include' => $this->t('Only selected actions'),
|
||||
),
|
||||
],
|
||||
'#default_value' => $this->options['include_exclude'],
|
||||
);
|
||||
$form['selected_actions'] = array(
|
||||
];
|
||||
$form['selected_actions'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => $this->t('Selected actions'),
|
||||
'#options' => $this->getBulkOptions(FALSE),
|
||||
'#default_value' => $this->options['selected_actions'],
|
||||
);
|
||||
];
|
||||
|
||||
parent::buildOptionsForm($form, $form_state);
|
||||
}
|
||||
|
@ -208,8 +208,8 @@ class BulkForm extends FieldPluginBase implements CacheableDependencyInterface {
|
|||
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
parent::validateOptionsForm($form, $form_state);
|
||||
|
||||
$selected_actions = $form_state->getValue(array('options', 'selected_actions'));
|
||||
$form_state->setValue(array('options', 'selected_actions'), array_values(array_filter($selected_actions)));
|
||||
$selected_actions = $form_state->getValue(['options', 'selected_actions']);
|
||||
$form_state->setValue(['options', 'selected_actions'], array_values(array_filter($selected_actions)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -259,7 +259,7 @@ class BulkForm extends FieldPluginBase implements CacheableDependencyInterface {
|
|||
foreach ($this->view->result as $row_index => $row) {
|
||||
$entity = $this->getEntityTranslation($this->getEntity($row), $row);
|
||||
|
||||
$form[$this->options['id']][$row_index] = array(
|
||||
$form[$this->options['id']][$row_index] = [
|
||||
'#type' => 'checkbox',
|
||||
// We are not able to determine a main "title" for each row, so we can
|
||||
// only output a generic label.
|
||||
|
@ -267,28 +267,28 @@ class BulkForm extends FieldPluginBase implements CacheableDependencyInterface {
|
|||
'#title_display' => 'invisible',
|
||||
'#default_value' => !empty($form_state->getValue($this->options['id'])[$row_index]) ? 1 : NULL,
|
||||
'#return_value' => $this->calculateEntityBulkFormKey($entity, $use_revision),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Replace the form submit button label.
|
||||
$form['actions']['submit']['#value'] = $this->t('Apply to selected items');
|
||||
|
||||
// Ensure a consistent container for filters/operations in the view header.
|
||||
$form['header'] = array(
|
||||
$form['header'] = [
|
||||
'#type' => 'container',
|
||||
'#weight' => -100,
|
||||
);
|
||||
];
|
||||
|
||||
// Build the bulk operations action widget for the header.
|
||||
// Allow themes to apply .container-inline on this separate container.
|
||||
$form['header'][$this->options['id']] = array(
|
||||
$form['header'][$this->options['id']] = [
|
||||
'#type' => 'container',
|
||||
);
|
||||
$form['header'][$this->options['id']]['action'] = array(
|
||||
];
|
||||
$form['header'][$this->options['id']]['action'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->options['action_title'],
|
||||
'#options' => $this->getBulkOptions(),
|
||||
);
|
||||
];
|
||||
|
||||
// Duplicate the form actions into the action container in the header.
|
||||
$form['header'][$this->options['id']]['actions'] = $form['actions'];
|
||||
|
@ -308,7 +308,7 @@ class BulkForm extends FieldPluginBase implements CacheableDependencyInterface {
|
|||
* An associative array of operations, suitable for a select element.
|
||||
*/
|
||||
protected function getBulkOptions($filtered = TRUE) {
|
||||
$options = array();
|
||||
$options = [];
|
||||
// Filter the action list.
|
||||
foreach ($this->actions as $id => $action) {
|
||||
if ($filtered) {
|
||||
|
@ -344,9 +344,12 @@ class BulkForm extends FieldPluginBase implements CacheableDependencyInterface {
|
|||
*/
|
||||
public function viewsFormSubmit(&$form, FormStateInterface $form_state) {
|
||||
if ($form_state->get('step') == 'views_form_views_form') {
|
||||
// Filter only selected checkboxes.
|
||||
$selected = array_filter($form_state->getValue($this->options['id']));
|
||||
$entities = array();
|
||||
// Filter only selected checkboxes. Use the actual user input rather than
|
||||
// the raw form values array, since the site data may change before the
|
||||
// bulk form is submitted, which can lead to data loss.
|
||||
$user_input = $form_state->getUserInput();
|
||||
$selected = array_filter($user_input[$this->options['id']]);
|
||||
$entities = [];
|
||||
$action = $this->actions[$form_state->getValue('action')];
|
||||
$count = 0;
|
||||
|
||||
|
@ -372,18 +375,18 @@ class BulkForm extends FieldPluginBase implements CacheableDependencyInterface {
|
|||
|
||||
$operation_definition = $action->getPluginDefinition();
|
||||
if (!empty($operation_definition['confirm_form_route_name'])) {
|
||||
$options = array(
|
||||
$options = [
|
||||
'query' => $this->getDestinationArray(),
|
||||
);
|
||||
$form_state->setRedirect($operation_definition['confirm_form_route_name'], array(), $options);
|
||||
];
|
||||
$form_state->setRedirect($operation_definition['confirm_form_route_name'], [], $options);
|
||||
}
|
||||
else {
|
||||
// Don't display the message unless there are some elements affected and
|
||||
// there is no confirmation form.
|
||||
if ($count) {
|
||||
drupal_set_message($this->formatPlural($count, '%action was applied to @count item.', '%action was applied to @count items.', array(
|
||||
drupal_set_message($this->formatPlural($count, '%action was applied to @count item.', '%action was applied to @count items.', [
|
||||
'%action' => $action->label(),
|
||||
)));
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,11 +81,11 @@ class SystemConfigSubscriber implements EventSubscriberInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedEvents() {
|
||||
$events[ConfigEvents::SAVE][] = array('onConfigSave', 0);
|
||||
$events[ConfigEvents::SAVE][] = ['onConfigSave', 0];
|
||||
// The empty check has a high priority so that it can stop propagation if
|
||||
// there is no configuration to import.
|
||||
$events[ConfigEvents::IMPORT_VALIDATE][] = array('onConfigImporterValidateNotEmpty', 512);
|
||||
$events[ConfigEvents::IMPORT_VALIDATE][] = array('onConfigImporterValidateSiteUUID', 256);
|
||||
$events[ConfigEvents::IMPORT_VALIDATE][] = ['onConfigImporterValidateNotEmpty', 512];
|
||||
$events[ConfigEvents::IMPORT_VALIDATE][] = ['onConfigImporterValidateSiteUUID', 256];
|
||||
return $events;
|
||||
}
|
||||
|
||||
|
|
|
@ -109,8 +109,8 @@ class SystemManager {
|
|||
drupal_load_updates();
|
||||
|
||||
// Check run-time requirements and status information.
|
||||
$requirements = $this->moduleHandler->invokeAll('requirements', array('runtime'));
|
||||
usort($requirements, function($a, $b) {
|
||||
$requirements = $this->moduleHandler->invokeAll('requirements', ['runtime']);
|
||||
uasort($requirements, function($a, $b) {
|
||||
if (!isset($a['weight'])) {
|
||||
if (!isset($b['weight'])) {
|
||||
return strcasecmp($a['title'], $b['title']);
|
||||
|
@ -159,15 +159,15 @@ class SystemManager {
|
|||
// or elsewhere could give us a blank block.
|
||||
$link = $this->menuActiveTrail->getActiveLink('admin');
|
||||
if ($link && $content = $this->getAdminBlock($link)) {
|
||||
$output = array(
|
||||
$output = [
|
||||
'#theme' => 'admin_block_content',
|
||||
'#content' => $content,
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$output = array(
|
||||
$output = [
|
||||
'#markup' => t('You do not have any administrative items.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
@ -182,16 +182,16 @@ class SystemManager {
|
|||
* An array of menu items, as expected by admin-block-content.html.twig.
|
||||
*/
|
||||
public function getAdminBlock(MenuLinkInterface $instance) {
|
||||
$content = array();
|
||||
$content = [];
|
||||
// Only find the children of this link.
|
||||
$link_id = $instance->getPluginId();
|
||||
$parameters = new MenuTreeParameters();
|
||||
$parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
|
||||
$tree = $this->menuTree->load(NULL, $parameters);
|
||||
$manipulators = array(
|
||||
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
|
||||
array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'),
|
||||
);
|
||||
$manipulators = [
|
||||
['callable' => 'menu.default_tree_manipulators:checkAccess'],
|
||||
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
|
||||
];
|
||||
$tree = $this->menuTree->transform($tree, $manipulators);
|
||||
foreach ($tree as $key => $element) {
|
||||
// Only render accessible links.
|
||||
|
|
|
@ -11,13 +11,13 @@ class AjaxInGroupTest extends AjaxTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser(array('access content')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['access content']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits forms with select and checkbox elements via Ajax.
|
||||
*/
|
||||
function testSimpleAjaxFormValue() {
|
||||
public function testSimpleAjaxFormValue() {
|
||||
$this->drupalGet('/ajax_forms_test_get_form');
|
||||
$this->assertText('Test group');
|
||||
$this->assertText('AJAX checkbox in a group');
|
||||
|
|
|
@ -14,7 +14,7 @@ abstract class AjaxTestBase extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'ajax_test', 'ajax_forms_test');
|
||||
public static $modules = ['node', 'ajax_test', 'ajax_forms_test'];
|
||||
|
||||
/**
|
||||
* Asserts the array of Ajax commands contains the searched command.
|
||||
|
|
|
@ -32,91 +32,91 @@ class CommandsTest extends AjaxTestBase {
|
|||
/**
|
||||
* Tests the various Ajax Commands.
|
||||
*/
|
||||
function testAjaxCommands() {
|
||||
public function testAjaxCommands() {
|
||||
$form_path = 'ajax_forms_test_ajax_commands_form';
|
||||
$web_user = $this->drupalCreateUser(array('access content'));
|
||||
$web_user = $this->drupalCreateUser(['access content']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
|
||||
// Tests the 'add_css' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX 'add_css' command")));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX 'add_css' command")]);
|
||||
$expected = new AddCssCommand('my/file.css');
|
||||
$this->assertCommand($commands, $expected->render(), "'add_css' AJAX command issued with correct data.");
|
||||
|
||||
// Tests the 'after' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX 'After': Click to put something after the div")));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX 'After': Click to put something after the div")]);
|
||||
$expected = new AfterCommand('#after_div', 'This will be placed after');
|
||||
$this->assertCommand($commands, $expected->render(), "'after' AJAX command issued with correct data.");
|
||||
|
||||
// Tests the 'alert' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX 'Alert': Click to alert")));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX 'Alert': Click to alert")]);
|
||||
$expected = new AlertCommand(t('Alert'));
|
||||
$this->assertCommand($commands, $expected->render(), "'alert' AJAX Command issued with correct text.");
|
||||
|
||||
// Tests the 'append' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX 'Append': Click to append something")));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX 'Append': Click to append something")]);
|
||||
$expected = new AppendCommand('#append_div', 'Appended text');
|
||||
$this->assertCommand($commands, $expected->render(), "'append' AJAX command issued with correct data.");
|
||||
|
||||
// Tests the 'before' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX 'before': Click to put something before the div")));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX 'before': Click to put something before the div")]);
|
||||
$expected = new BeforeCommand('#before_div', 'Before text');
|
||||
$this->assertCommand($commands, $expected->render(), "'before' AJAX command issued with correct data.");
|
||||
|
||||
// Tests the 'changed' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX changed: Click to mark div changed.")));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX changed: Click to mark div changed.")]);
|
||||
$expected = new ChangedCommand('#changed_div');
|
||||
$this->assertCommand($commands, $expected->render(), "'changed' AJAX command issued with correct selector.");
|
||||
|
||||
// Tests the 'changed' command using the second argument.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX changed: Click to mark div changed with asterisk.")));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX changed: Click to mark div changed with asterisk.")]);
|
||||
$expected = new ChangedCommand('#changed_div', '#changed_div_mark_this');
|
||||
$this->assertCommand($commands, $expected->render(), "'changed' AJAX command (with asterisk) issued with correct selector.");
|
||||
|
||||
// Tests the 'css' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("Set the '#box' div to be blue.")));
|
||||
$expected = new CssCommand('#css_div', array('background-color' => 'blue'));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("Set the '#box' div to be blue.")]);
|
||||
$expected = new CssCommand('#css_div', ['background-color' => 'blue']);
|
||||
$this->assertCommand($commands, $expected->render(), "'css' AJAX command issued with correct selector.");
|
||||
|
||||
// Tests the 'data' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX data command: Issue command.")));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX data command: Issue command.")]);
|
||||
$expected = new DataCommand('#data_div', 'testkey', 'testvalue');
|
||||
$this->assertCommand($commands, $expected->render(), "'data' AJAX command issued with correct key and value.");
|
||||
|
||||
// Tests the 'html' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX html: Replace the HTML in a selector.")));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX html: Replace the HTML in a selector.")]);
|
||||
$expected = new HtmlCommand('#html_div', 'replacement text');
|
||||
$this->assertCommand($commands, $expected->render(), "'html' AJAX command issued with correct data.");
|
||||
|
||||
// Tests the 'insert' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX insert: Let client insert based on #ajax['method'].")));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX insert: Let client insert based on #ajax['method'].")]);
|
||||
$expected = new InsertCommand('#insert_div', 'insert replacement text');
|
||||
$this->assertCommand($commands, $expected->render(), "'insert' AJAX command issued with correct data.");
|
||||
|
||||
// Tests the 'invoke' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX invoke command: Invoke addClass() method.")));
|
||||
$expected = new InvokeCommand('#invoke_div', 'addClass', array('error'));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX invoke command: Invoke addClass() method.")]);
|
||||
$expected = new InvokeCommand('#invoke_div', 'addClass', ['error']);
|
||||
$this->assertCommand($commands, $expected->render(), "'invoke' AJAX command issued with correct method and argument.");
|
||||
|
||||
// Tests the 'prepend' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX 'prepend': Click to prepend something")));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX 'prepend': Click to prepend something")]);
|
||||
$expected = new PrependCommand('#prepend_div', 'prepended text');
|
||||
$this->assertCommand($commands, $expected->render(), "'prepend' AJAX command issued with correct data.");
|
||||
|
||||
// Tests the 'remove' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX 'remove': Click to remove text")));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX 'remove': Click to remove text")]);
|
||||
$expected = new RemoveCommand('#remove_text');
|
||||
$this->assertCommand($commands, $expected->render(), "'remove' AJAX command issued with correct command and selector.");
|
||||
|
||||
// Tests the 'restripe' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX 'restripe' command")));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX 'restripe' command")]);
|
||||
$expected = new RestripeCommand('#restripe_table');
|
||||
$this->assertCommand($commands, $expected->render(), "'restripe' AJAX command issued with correct selector.");
|
||||
|
||||
// Tests the 'settings' command.
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, array('op' => t("AJAX 'settings' command")));
|
||||
$expected = new SettingsCommand(array('ajax_forms_test' => array('foo' => 42)));
|
||||
$commands = $this->drupalPostAjaxForm($form_path, $edit, ['op' => t("AJAX 'settings' command")]);
|
||||
$expected = new SettingsCommand(['ajax_forms_test' => ['foo' => 42]]);
|
||||
$this->assertCommand($commands, $expected->render(), "'settings' AJAX command issued with correct data.");
|
||||
}
|
||||
|
||||
|
|
|
@ -19,72 +19,72 @@ class DialogTest extends AjaxTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('ajax_test', 'ajax_forms_test', 'contact');
|
||||
public static $modules = ['ajax_test', 'ajax_forms_test', 'contact'];
|
||||
|
||||
/**
|
||||
* Test sending non-JS and AJAX requests to open and manipulate modals.
|
||||
*/
|
||||
public function testDialog() {
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer contact forms')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer contact forms']));
|
||||
// Ensure the elements render without notices or exceptions.
|
||||
$this->drupalGet('ajax-test/dialog');
|
||||
|
||||
// Set up variables for this test.
|
||||
$dialog_renderable = AjaxTestController::dialogContents();
|
||||
$dialog_contents = \Drupal::service('renderer')->renderRoot($dialog_renderable);
|
||||
$modal_expected_response = array(
|
||||
$modal_expected_response = [
|
||||
'command' => 'openDialog',
|
||||
'selector' => '#drupal-modal',
|
||||
'settings' => NULL,
|
||||
'data' => $dialog_contents,
|
||||
'dialogOptions' => array(
|
||||
'dialogOptions' => [
|
||||
'modal' => TRUE,
|
||||
'title' => 'AJAX Dialog & contents',
|
||||
),
|
||||
);
|
||||
$form_expected_response = array(
|
||||
],
|
||||
];
|
||||
$form_expected_response = [
|
||||
'command' => 'openDialog',
|
||||
'selector' => '#drupal-modal',
|
||||
'settings' => NULL,
|
||||
'dialogOptions' => array(
|
||||
'dialogOptions' => [
|
||||
'modal' => TRUE,
|
||||
'title' => 'Ajax Form contents',
|
||||
),
|
||||
);
|
||||
$entity_form_expected_response = array(
|
||||
],
|
||||
];
|
||||
$entity_form_expected_response = [
|
||||
'command' => 'openDialog',
|
||||
'selector' => '#drupal-modal',
|
||||
'settings' => NULL,
|
||||
'dialogOptions' => array(
|
||||
'dialogOptions' => [
|
||||
'modal' => TRUE,
|
||||
'title' => 'Add contact form',
|
||||
),
|
||||
);
|
||||
$normal_expected_response = array(
|
||||
],
|
||||
];
|
||||
$normal_expected_response = [
|
||||
'command' => 'openDialog',
|
||||
'selector' => '#ajax-test-dialog-wrapper-1',
|
||||
'settings' => NULL,
|
||||
'data' => $dialog_contents,
|
||||
'dialogOptions' => array(
|
||||
'dialogOptions' => [
|
||||
'modal' => FALSE,
|
||||
'title' => 'AJAX Dialog & contents',
|
||||
),
|
||||
);
|
||||
$no_target_expected_response = array(
|
||||
],
|
||||
];
|
||||
$no_target_expected_response = [
|
||||
'command' => 'openDialog',
|
||||
'selector' => '#drupal-dialog-ajax-testdialog-contents',
|
||||
'settings' => NULL,
|
||||
'data' => $dialog_contents,
|
||||
'dialogOptions' => array(
|
||||
'dialogOptions' => [
|
||||
'modal' => FALSE,
|
||||
'title' => 'AJAX Dialog & contents',
|
||||
),
|
||||
);
|
||||
$close_expected_response = array(
|
||||
],
|
||||
];
|
||||
$close_expected_response = [
|
||||
'command' => 'closeDialog',
|
||||
'selector' => '#ajax-test-dialog-wrapper-1',
|
||||
'persist' => FALSE,
|
||||
);
|
||||
];
|
||||
|
||||
// Check that requesting a modal dialog without JS goes to a page.
|
||||
$this->drupalGet('ajax-test/dialog-contents');
|
||||
|
@ -95,7 +95,7 @@ class DialogTest extends AjaxTestBase {
|
|||
$this->assertRaw($dialog_contents, 'Modal dialog page on XMLHttpRequest present.');
|
||||
|
||||
// Emulate going to the JS version of the page and check the JSON response.
|
||||
$ajax_result = $this->drupalGetAjax('ajax-test/dialog-contents', array('query' => array(MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_modal')));
|
||||
$ajax_result = $this->drupalGetAjax('ajax-test/dialog-contents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_modal']]);
|
||||
$this->assertEqual($modal_expected_response, $ajax_result[3], 'Modal dialog JSON response matches.');
|
||||
// Test the HTML escaping of & character.
|
||||
$this->assertEqual($ajax_result[3]['dialogOptions']['title'], 'AJAX Dialog & contents');
|
||||
|
@ -108,26 +108,26 @@ class DialogTest extends AjaxTestBase {
|
|||
// Emulate going to the JS version of the page and check the JSON response.
|
||||
// This needs to use WebTestBase::drupalPostAjaxForm() so that the correct
|
||||
// dialog options are sent.
|
||||
$ajax_result = $this->drupalPostAjaxForm('ajax-test/dialog', array(
|
||||
$ajax_result = $this->drupalPostAjaxForm('ajax-test/dialog', [
|
||||
// We have to mock a form element to make drupalPost submit from a link.
|
||||
'textfield' => 'test',
|
||||
), array(), 'ajax-test/dialog-contents', array('query' => array(MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_dialog')), array(), NULL, array(
|
||||
'submit' => array(
|
||||
], [], 'ajax-test/dialog-contents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_dialog']], [], NULL, [
|
||||
'submit' => [
|
||||
'dialogOptions[target]' => 'ajax-test-dialog-wrapper-1',
|
||||
)
|
||||
));
|
||||
]
|
||||
]);
|
||||
$this->assertEqual($normal_expected_response, $ajax_result[3], 'Normal dialog JSON response matches.');
|
||||
|
||||
// Emulate going to the JS version of the page and check the JSON response.
|
||||
// This needs to use WebTestBase::drupalPostAjaxForm() so that the correct
|
||||
// dialog options are sent.
|
||||
$ajax_result = $this->drupalPostAjaxForm('ajax-test/dialog', array(
|
||||
$ajax_result = $this->drupalPostAjaxForm('ajax-test/dialog', [
|
||||
// We have to mock a form element to make drupalPost submit from a link.
|
||||
'textfield' => 'test',
|
||||
), array(), 'ajax-test/dialog-contents', array('query' => array(MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_dialog')), array(), NULL, array(
|
||||
], [], 'ajax-test/dialog-contents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_dialog']], [], NULL, [
|
||||
// Don't send a target.
|
||||
'submit' => array()
|
||||
));
|
||||
'submit' => []
|
||||
]);
|
||||
// Make sure the selector ID starts with the right string.
|
||||
$this->assert(strpos($ajax_result[3]['selector'], $no_target_expected_response['selector']) === 0, 'Selector starts with right string.');
|
||||
unset($ajax_result[3]['selector']);
|
||||
|
@ -142,7 +142,7 @@ class DialogTest extends AjaxTestBase {
|
|||
// Test submitting via a POST request through the button for modals. This
|
||||
// approach more accurately reflects the real responses by Drupal because
|
||||
// all of the necessary page variables are emulated.
|
||||
$ajax_result = $this->drupalPostAjaxForm('ajax-test/dialog', array(), 'button1');
|
||||
$ajax_result = $this->drupalPostAjaxForm('ajax-test/dialog', [], 'button1');
|
||||
|
||||
// Check that CSS and JavaScript are "added" to the page dynamically.
|
||||
$this->assertTrue(in_array('core/drupal.dialog.ajax', explode(',', $ajax_result[0]['settings']['ajaxPageState']['libraries'])), 'core/drupal.dialog.ajax library is added to the page.');
|
||||
|
@ -159,7 +159,7 @@ class DialogTest extends AjaxTestBase {
|
|||
$this->assertNotEqual($ajax_result[4]['dialogOptions']['title'], 'AJAX Dialog & contents');
|
||||
|
||||
// Abbreviated test for "normal" dialogs, testing only the difference.
|
||||
$ajax_result = $this->drupalPostAjaxForm('ajax-test/dialog', array(), 'button2');
|
||||
$ajax_result = $this->drupalPostAjaxForm('ajax-test/dialog', [], 'button2');
|
||||
$this->assertEqual($normal_expected_response, $ajax_result[4], 'POST request normal dialog JSON response matches.');
|
||||
|
||||
// Check that requesting a form dialog without JS goes to a page.
|
||||
|
@ -170,7 +170,7 @@ class DialogTest extends AjaxTestBase {
|
|||
$this->assertTrue(!empty($form), 'Non-JS form page present.');
|
||||
|
||||
// Emulate going to the JS version of the form and check the JSON response.
|
||||
$ajax_result = $this->drupalGetAjax('ajax-test/dialog-form', array('query' => array(MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_modal')));
|
||||
$ajax_result = $this->drupalGetAjax('ajax-test/dialog-form', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_modal']]);
|
||||
$expected_ajax_settings = [
|
||||
'edit-preview' => [
|
||||
'callback' => '::preview',
|
||||
|
@ -202,7 +202,7 @@ class DialogTest extends AjaxTestBase {
|
|||
$this->assertTrue(!empty($form), 'Non-JS entity form page present.');
|
||||
|
||||
// Emulate going to the JS version of the form and check the JSON response.
|
||||
$ajax_result = $this->drupalGetAjax('admin/structure/contact/add', array('query' => array(MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_modal')));
|
||||
$ajax_result = $this->drupalGetAjax('admin/structure/contact/add', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_modal']]);
|
||||
$this->setRawContent($ajax_result[3]['data']);
|
||||
// Remove the data, the form build id and token will never match.
|
||||
unset($ajax_result[3]['data']);
|
||||
|
|
|
@ -16,8 +16,8 @@ class ElementValidationTest extends AjaxTestBase {
|
|||
* filled in, and we want to see if the activation of the "drivertext"
|
||||
* Ajax-enabled field fails due to the required field being empty.
|
||||
*/
|
||||
function testAjaxElementValidation() {
|
||||
$edit = array('drivertext' => t('some dumb text'));
|
||||
public function testAjaxElementValidation() {
|
||||
$edit = ['drivertext' => t('some dumb text')];
|
||||
|
||||
// Post with 'drivertext' as the triggering element.
|
||||
$this->drupalPostAjaxForm('ajax_validation_test', $edit, 'drivertext');
|
||||
|
@ -26,7 +26,7 @@ class ElementValidationTest extends AjaxTestBase {
|
|||
$this->assertText('ajax_forms_test_validation_form_callback invoked', 'The correct callback was invoked');
|
||||
|
||||
$this->drupalGet('ajax_validation_test');
|
||||
$edit = array('drivernumber' => 12345);
|
||||
$edit = ['drivernumber' => 12345];
|
||||
|
||||
// Post with 'drivernumber' as the triggering element.
|
||||
$this->drupalPostAjaxForm('ajax_validation_test', $edit, 'drivernumber');
|
||||
|
|
|
@ -13,28 +13,28 @@ class FormValuesTest extends AjaxTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser(array('access content')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['access content']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits forms with select and checkbox elements via Ajax.
|
||||
*/
|
||||
function testSimpleAjaxFormValue() {
|
||||
public function testSimpleAjaxFormValue() {
|
||||
// Verify form values of a select element.
|
||||
foreach (array('red', 'green', 'blue') as $item) {
|
||||
$edit = array(
|
||||
foreach (['red', 'green', 'blue'] as $item) {
|
||||
$edit = [
|
||||
'select' => $item,
|
||||
);
|
||||
];
|
||||
$commands = $this->drupalPostAjaxForm('ajax_forms_test_get_form', $edit, 'select');
|
||||
$expected = new DataCommand('#ajax_selected_color', 'form_state_value_select', $item);
|
||||
$this->assertCommand($commands, $expected->render(), 'Verification of AJAX form values from a selectbox issued with a correct value.');
|
||||
}
|
||||
|
||||
// Verify form values of a checkbox element.
|
||||
foreach (array(FALSE, TRUE) as $item) {
|
||||
$edit = array(
|
||||
foreach ([FALSE, TRUE] as $item) {
|
||||
$edit = [
|
||||
'checkbox' => $item,
|
||||
);
|
||||
];
|
||||
$commands = $this->drupalPostAjaxForm('ajax_forms_test_get_form', $edit, 'checkbox');
|
||||
$expected = new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $item);
|
||||
$this->assertCommand($commands, $expected->render(), 'Verification of AJAX form values from a checkbox issued with a correct value.');
|
||||
|
@ -46,11 +46,11 @@ class FormValuesTest extends AjaxTestBase {
|
|||
// We don't need to check for the X-Drupal-Ajax-Token header with these
|
||||
// invalid requests.
|
||||
$this->assertAjaxHeader = FALSE;
|
||||
foreach (array('null', 'empty', 'nonexistent') as $key) {
|
||||
foreach (['null', 'empty', 'nonexistent'] as $key) {
|
||||
$element_name = 'select_' . $key . '_callback';
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$element_name => 'red',
|
||||
);
|
||||
];
|
||||
$commands = $this->drupalPostAjaxForm('ajax_forms_test_get_form', $edit, $element_name);
|
||||
$this->assertResponse(500);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class FrameworkTest extends AjaxTestBase {
|
|||
public function testAJAXRender() {
|
||||
// Verify that settings command is generated if JavaScript settings exist.
|
||||
$commands = $this->drupalGetAjax('ajax-test/render');
|
||||
$expected = new SettingsCommand(array('ajax' => 'test'), TRUE);
|
||||
$expected = new SettingsCommand(['ajax' => 'test'], TRUE);
|
||||
$this->assertCommand($commands, $expected->render(), 'JavaScript settings command is present.');
|
||||
}
|
||||
|
||||
|
@ -30,14 +30,14 @@ class FrameworkTest extends AjaxTestBase {
|
|||
* Tests AjaxResponse::prepare() AJAX commands ordering.
|
||||
*/
|
||||
public function testOrder() {
|
||||
$expected_commands = array();
|
||||
$expected_commands = [];
|
||||
|
||||
// Expected commands, in a very specific order.
|
||||
$asset_resolver = \Drupal::service('asset.resolver');
|
||||
$css_collection_renderer = \Drupal::service('asset.css.collection_renderer');
|
||||
$js_collection_renderer = \Drupal::service('asset.js.collection_renderer');
|
||||
$renderer = \Drupal::service('renderer');
|
||||
$expected_commands[0] = new SettingsCommand(array('ajax' => 'test'), TRUE);
|
||||
$expected_commands[0] = new SettingsCommand(['ajax' => 'test'], TRUE);
|
||||
$build['#attached']['library'][] = 'ajax_test/order-css-command';
|
||||
$assets = AttachedAssets::createFromRenderArray($build);
|
||||
$css_render_array = $css_collection_renderer->render($asset_resolver->getCssAssets($assets, FALSE));
|
||||
|
@ -65,7 +65,7 @@ class FrameworkTest extends AjaxTestBase {
|
|||
// 3. JavaScript files in the header
|
||||
// 4. JavaScript files in the footer
|
||||
// 5. Any other AJAX commands, in whatever order they were added.
|
||||
$commands = $this->drupalPostAjaxForm(NULL, array(), NULL, 'ajax-test/order', array(), array(), NULL, array());
|
||||
$commands = $this->drupalPostAjaxForm(NULL, [], NULL, 'ajax-test/order', [], [], NULL, []);
|
||||
$this->assertCommand(array_slice($commands, 0, 1), $expected_commands[0]->render(), 'Settings command is first.');
|
||||
$this->assertCommand(array_slice($commands, 1, 1), $expected_commands[1]->render(), 'CSS command is second (and CSS files are ordered correctly).');
|
||||
$this->assertCommand(array_slice($commands, 2, 1), $expected_commands[2]->render(), 'Header JS command is third.');
|
||||
|
@ -78,10 +78,10 @@ class FrameworkTest extends AjaxTestBase {
|
|||
*/
|
||||
public function testAJAXRenderError() {
|
||||
// Verify custom error message.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'message' => 'Custom error message.',
|
||||
);
|
||||
$commands = $this->drupalGetAjax('ajax-test/render-error', array('query' => $edit));
|
||||
];
|
||||
$commands = $this->drupalGetAjax('ajax-test/render-error', ['query' => $edit]);
|
||||
$expected = new AlertCommand($edit['message']);
|
||||
$this->assertCommand($commands, $expected->render(), 'Custom error message is output.');
|
||||
}
|
||||
|
@ -95,12 +95,12 @@ class FrameworkTest extends AjaxTestBase {
|
|||
$js_collection_renderer = \Drupal::service('asset.js.collection_renderer');
|
||||
$renderer = \Drupal::service('renderer');
|
||||
|
||||
$expected = array(
|
||||
$expected = [
|
||||
'setting_name' => 'ajax_forms_test_lazy_load_form_submit',
|
||||
'setting_value' => 'executed',
|
||||
'library_1' => 'system/admin',
|
||||
'library_2' => 'system/drupal.system',
|
||||
);
|
||||
];
|
||||
|
||||
// Get the base page.
|
||||
$this->drupalGet('ajax_forms_test_lazy_load_form');
|
||||
|
@ -109,9 +109,9 @@ class FrameworkTest extends AjaxTestBase {
|
|||
|
||||
// Verify that the base page doesn't have the settings and files that are to
|
||||
// be lazy loaded as part of the next requests.
|
||||
$this->assertTrue(!isset($original_settings[$expected['setting_name']]), format_string('Page originally lacks the %setting, as expected.', array('%setting' => $expected['setting_name'])));
|
||||
$this->assertTrue(!in_array($expected['library_1'], $original_libraries), format_string('Page originally lacks the %library library, as expected.', array('%library' => $expected['library_1'])));
|
||||
$this->assertTrue(!in_array($expected['library_2'], $original_libraries), format_string('Page originally lacks the %library library, as expected.', array('%library' => $expected['library_2'])));
|
||||
$this->assertTrue(!isset($original_settings[$expected['setting_name']]), format_string('Page originally lacks the %setting, as expected.', ['%setting' => $expected['setting_name']]));
|
||||
$this->assertTrue(!in_array($expected['library_1'], $original_libraries), format_string('Page originally lacks the %library library, as expected.', ['%library' => $expected['library_1']]));
|
||||
$this->assertTrue(!in_array($expected['library_2'], $original_libraries), format_string('Page originally lacks the %library library, as expected.', ['%library' => $expected['library_2']]));
|
||||
|
||||
// Calculate the expected CSS and JS.
|
||||
$assets = new AttachedAssets();
|
||||
|
@ -128,14 +128,14 @@ class FrameworkTest extends AjaxTestBase {
|
|||
$expected_js_html = $renderer->renderRoot($js_render_array);
|
||||
|
||||
// Submit the AJAX request without triggering files getting added.
|
||||
$commands = $this->drupalPostAjaxForm(NULL, array('add_files' => FALSE), array('op' => t('Submit')));
|
||||
$commands = $this->drupalPostAjaxForm(NULL, ['add_files' => FALSE], ['op' => t('Submit')]);
|
||||
$new_settings = $this->getDrupalSettings();
|
||||
$new_libraries = explode(',', $new_settings['ajaxPageState']['libraries']);
|
||||
|
||||
// Verify the setting was not added when not expected.
|
||||
$this->assertTrue(!isset($new_settings[$expected['setting_name']]), format_string('Page still lacks the %setting, as expected.', array('%setting' => $expected['setting_name'])));
|
||||
$this->assertTrue(!in_array($expected['library_1'], $new_libraries), format_string('Page still lacks the %library library, as expected.', array('%library' => $expected['library_1'])));
|
||||
$this->assertTrue(!in_array($expected['library_2'], $new_libraries), format_string('Page still lacks the %library library, as expected.', array('%library' => $expected['library_2'])));
|
||||
$this->assertTrue(!isset($new_settings[$expected['setting_name']]), format_string('Page still lacks the %setting, as expected.', ['%setting' => $expected['setting_name']]));
|
||||
$this->assertTrue(!in_array($expected['library_1'], $new_libraries), format_string('Page still lacks the %library library, as expected.', ['%library' => $expected['library_1']]));
|
||||
$this->assertTrue(!in_array($expected['library_2'], $new_libraries), format_string('Page still lacks the %library library, as expected.', ['%library' => $expected['library_2']]));
|
||||
// Verify a settings command does not add CSS or scripts to drupalSettings
|
||||
// and no command inserts the corresponding tags on the page.
|
||||
$found_settings_command = FALSE;
|
||||
|
@ -148,24 +148,24 @@ class FrameworkTest extends AjaxTestBase {
|
|||
$found_markup_command = TRUE;
|
||||
}
|
||||
}
|
||||
$this->assertFalse($found_settings_command, format_string('Page state still lacks the %library_1 and %library_2 libraries, as expected.', array('%library_1' => $expected['library_1'], '%library_2' => $expected['library_2'])));
|
||||
$this->assertFalse($found_markup_command, format_string('Page still lacks the %library_1 and %library_2 libraries, as expected.', array('%library_1' => $expected['library_1'], '%library_2' => $expected['library_2'])));
|
||||
$this->assertFalse($found_settings_command, format_string('Page state still lacks the %library_1 and %library_2 libraries, as expected.', ['%library_1' => $expected['library_1'], '%library_2' => $expected['library_2']]));
|
||||
$this->assertFalse($found_markup_command, format_string('Page still lacks the %library_1 and %library_2 libraries, as expected.', ['%library_1' => $expected['library_1'], '%library_2' => $expected['library_2']]));
|
||||
|
||||
// Submit the AJAX request and trigger adding files.
|
||||
$commands = $this->drupalPostAjaxForm(NULL, array('add_files' => TRUE), array('op' => t('Submit')));
|
||||
$commands = $this->drupalPostAjaxForm(NULL, ['add_files' => TRUE], ['op' => t('Submit')]);
|
||||
$new_settings = $this->getDrupalSettings();
|
||||
$new_libraries = explode(',', $new_settings['ajaxPageState']['libraries']);
|
||||
|
||||
// Verify the expected setting was added, both to drupalSettings, and as
|
||||
// the first AJAX command.
|
||||
$this->assertIdentical($new_settings[$expected['setting_name']], $expected['setting_value'], format_string('Page now has the %setting.', array('%setting' => $expected['setting_name'])));
|
||||
$expected_command = new SettingsCommand(array($expected['setting_name'] => $expected['setting_value']), TRUE);
|
||||
$this->assertIdentical($new_settings[$expected['setting_name']], $expected['setting_value'], format_string('Page now has the %setting.', ['%setting' => $expected['setting_name']]));
|
||||
$expected_command = new SettingsCommand([$expected['setting_name'] => $expected['setting_value']], TRUE);
|
||||
$this->assertCommand(array_slice($commands, 0, 1), $expected_command->render(), 'The settings command was first.');
|
||||
|
||||
// Verify the expected CSS file was added, both to drupalSettings, and as
|
||||
// the second AJAX command for inclusion into the HTML.
|
||||
$this->assertTrue(in_array($expected['library_1'], $new_libraries), format_string('Page state now has the %library library.', array('%library' => $expected['library_1'])));
|
||||
$this->assertCommand(array_slice($commands, 1, 1), array('data' => $expected_css_html), format_string('Page now has the %library library.', array('%library' => $expected['library_1'])));
|
||||
$this->assertTrue(in_array($expected['library_1'], $new_libraries), format_string('Page state now has the %library library.', ['%library' => $expected['library_1']]));
|
||||
$this->assertCommand(array_slice($commands, 1, 1), ['data' => $expected_css_html], format_string('Page now has the %library library.', ['%library' => $expected['library_1']]));
|
||||
|
||||
// Verify the expected JS file was added, both to drupalSettings, and as
|
||||
// the third AJAX command for inclusion into the HTML. By testing for an
|
||||
|
@ -173,15 +173,15 @@ class FrameworkTest extends AjaxTestBase {
|
|||
// unexpected JavaScript code, such as a jQuery.extend() that would
|
||||
// potentially clobber rather than properly merge settings, didn't
|
||||
// accidentally get added.
|
||||
$this->assertTrue(in_array($expected['library_2'], $new_libraries), format_string('Page state now has the %library library.', array('%library' => $expected['library_2'])));
|
||||
$this->assertCommand(array_slice($commands, 2, 1), array('data' => $expected_js_html), format_string('Page now has the %library library.', array('%library' => $expected['library_2'])));
|
||||
$this->assertTrue(in_array($expected['library_2'], $new_libraries), format_string('Page state now has the %library library.', ['%library' => $expected['library_2']]));
|
||||
$this->assertCommand(array_slice($commands, 2, 1), ['data' => $expected_js_html], format_string('Page now has the %library library.', ['%library' => $expected['library_2']]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that drupalSettings.currentPath is not updated on AJAX requests.
|
||||
*/
|
||||
public function testCurrentPathChange() {
|
||||
$commands = $this->drupalPostAjaxForm('ajax_forms_test_lazy_load_form', array('add_files' => FALSE), array('op' => t('Submit')));
|
||||
$commands = $this->drupalPostAjaxForm('ajax_forms_test_lazy_load_form', ['add_files' => FALSE], ['op' => t('Submit')]);
|
||||
foreach ($commands as $command) {
|
||||
if ($command['command'] == 'settings') {
|
||||
$this->assertFalse(isset($command['settings']['currentPath']), 'Value of drupalSettings.currentPath is not updated after an AJAX request.');
|
||||
|
@ -195,14 +195,14 @@ class FrameworkTest extends AjaxTestBase {
|
|||
public function testLazyLoadOverriddenCSS() {
|
||||
// The test theme overrides js.module.css without an implementation,
|
||||
// thereby removing it.
|
||||
\Drupal::service('theme_handler')->install(array('test_theme'));
|
||||
\Drupal::service('theme_handler')->install(['test_theme']);
|
||||
$this->config('system.theme')
|
||||
->set('default', 'test_theme')
|
||||
->save();
|
||||
|
||||
// This gets the form, and emulates an Ajax submission on it, including
|
||||
// adding markup to the HEAD and BODY for any lazy loaded JS/CSS files.
|
||||
$this->drupalPostAjaxForm('ajax_forms_test_lazy_load_form', array('add_files' => TRUE), array('op' => t('Submit')));
|
||||
$this->drupalPostAjaxForm('ajax_forms_test_lazy_load_form', ['add_files' => TRUE], ['op' => t('Submit')]);
|
||||
|
||||
// Verify that the resulting HTML does not load the overridden CSS file.
|
||||
// We add a "?" to the assertion, because drupalSettings may include
|
||||
|
|
|
@ -19,38 +19,38 @@ class MultiFormTest extends AjaxTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('form_test');
|
||||
public static $modules = ['form_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Page'));
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Page']);
|
||||
|
||||
// Create a multi-valued field for 'page' nodes to use for Ajax testing.
|
||||
$field_name = 'field_ajax_test';
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'entity_type' => 'node',
|
||||
'field_name' => $field_name,
|
||||
'type' => 'text',
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
))->save();
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
])->save();
|
||||
entity_get_form_display('node', 'page', 'default')
|
||||
->setComponent($field_name, array('type' => 'text_textfield'))
|
||||
->setComponent($field_name, ['type' => 'text_textfield'])
|
||||
->save();
|
||||
|
||||
// Log in a user who can create 'page' nodes.
|
||||
$this->drupalLogin ($this->drupalCreateUser(array('create page content')));
|
||||
$this->drupalLogin ($this->drupalCreateUser(['create page content']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that pages with the 'node_page_form' included twice work correctly.
|
||||
*/
|
||||
function testMultiForm() {
|
||||
public function testMultiForm() {
|
||||
// HTML IDs for elements within the field are potentially modified with
|
||||
// each Ajax submission, but these variables are stable and help target the
|
||||
// desired elements.
|
||||
|
@ -84,7 +84,7 @@ class MultiFormTest extends AjaxTestBase {
|
|||
$forms = $this->xpath($form_xpath);
|
||||
foreach ($forms as $offset => $form) {
|
||||
$form_html_id = (string) $form['id'];
|
||||
$this->drupalPostAjaxForm(NULL, array(), array($button_name => $button_value), NULL, array(), array(), $form_html_id);
|
||||
$this->drupalPostAjaxForm(NULL, [], [$button_name => $button_value], NULL, [], [], $form_html_id);
|
||||
$form = $this->xpath($form_xpath)[$offset];
|
||||
$field = $form->xpath('.' . $field_xpath);
|
||||
|
||||
|
|
|
@ -16,22 +16,22 @@ class PageTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('batch_test');
|
||||
public static $modules = ['batch_test'];
|
||||
|
||||
/**
|
||||
* Tests that the batch API progress page uses the correct theme.
|
||||
*/
|
||||
function testBatchProgressPageTheme() {
|
||||
public function testBatchProgressPageTheme() {
|
||||
// Make sure that the page which starts the batch (an administrative page)
|
||||
// is using a different theme than would normally be used by the batch API.
|
||||
$this->container->get('theme_handler')->install(array('seven', 'bartik'));
|
||||
$this->container->get('theme_handler')->install(['seven', 'bartik']);
|
||||
$this->config('system.theme')
|
||||
->set('default', 'bartik')
|
||||
->set('admin', 'seven')
|
||||
->save();
|
||||
|
||||
// Log in as an administrator who can see the administrative theme.
|
||||
$admin_user = $this->drupalCreateUser(array('view the administration theme'));
|
||||
$admin_user = $this->drupalCreateUser(['view the administration theme']);
|
||||
$this->drupalLogin($admin_user);
|
||||
// Visit an administrative page that runs a test batch, and check that the
|
||||
// theme that was used during batch execution (which the batch callback
|
||||
|
@ -40,13 +40,13 @@ class PageTest extends WebTestBase {
|
|||
$this->drupalGet('admin/batch-test/test-theme');
|
||||
// The stack should contain the name of the theme used on the progress
|
||||
// page.
|
||||
$this->assertEqual(batch_test_stack(), array('seven'), 'A progressive batch correctly uses the theme of the page that started the batch.');
|
||||
$this->assertEqual(batch_test_stack(), ['seven'], 'A progressive batch correctly uses the theme of the page that started the batch.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the batch API progress page shows the title correctly.
|
||||
*/
|
||||
function testBatchProgressPageTitle() {
|
||||
public function testBatchProgressPageTitle() {
|
||||
// Visit an administrative page that runs a test batch, and check that the
|
||||
// title shown during batch execution (which the batch callback function
|
||||
// saved as a variable) matches the theme used on the administrative page.
|
||||
|
@ -59,7 +59,7 @@ class PageTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that the progress messages are correct.
|
||||
*/
|
||||
function testBatchProgressMessages() {
|
||||
public function testBatchProgressMessages() {
|
||||
// Go to the initial step only.
|
||||
$this->maximumMetaRefreshCount = 0;
|
||||
$this->drupalGet('batch-test/test-title');
|
||||
|
|
|
@ -17,12 +17,12 @@ class ProcessingTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('batch_test', 'test_page_test');
|
||||
public static $modules = ['batch_test', 'test_page_test'];
|
||||
|
||||
/**
|
||||
* Tests batches triggered outside of form submission.
|
||||
*/
|
||||
function testBatchNoForm() {
|
||||
public function testBatchNoForm() {
|
||||
// Displaying the page triggers batch 1.
|
||||
$this->drupalGet('batch-test/no-form');
|
||||
$this->assertBatchMessages($this->_resultMessages('batch_1'), 'Batch for step 2 performed successfully.');
|
||||
|
@ -33,7 +33,7 @@ class ProcessingTest extends WebTestBase {
|
|||
/**
|
||||
* Tests batches that redirect in the batch finished callback.
|
||||
*/
|
||||
function testBatchRedirectFinishedCallback() {
|
||||
public function testBatchRedirectFinishedCallback() {
|
||||
// Displaying the page triggers batch 1.
|
||||
$this->drupalGet('batch-test/finish-redirect');
|
||||
$this->assertBatchMessages($this->_resultMessages('batch_1'), 'Batch for step 2 performed successfully.');
|
||||
|
@ -45,16 +45,16 @@ class ProcessingTest extends WebTestBase {
|
|||
/**
|
||||
* Tests batches defined in a form submit handler.
|
||||
*/
|
||||
function testBatchForm() {
|
||||
public function testBatchForm() {
|
||||
// Batch 0: no operation.
|
||||
$edit = array('batch' => 'batch_0');
|
||||
$edit = ['batch' => 'batch_0'];
|
||||
$this->drupalPostForm('batch-test', $edit, 'Submit');
|
||||
$this->assertNoEscaped('<', 'No escaped markup is present.');
|
||||
$this->assertBatchMessages($this->_resultMessages('batch_0'), 'Batch with no operation performed successfully.');
|
||||
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
|
||||
|
||||
// Batch 1: several simple operations.
|
||||
$edit = array('batch' => 'batch_1');
|
||||
$edit = ['batch' => 'batch_1'];
|
||||
$this->drupalPostForm('batch-test', $edit, 'Submit');
|
||||
$this->assertNoEscaped('<', 'No escaped markup is present.');
|
||||
$this->assertBatchMessages($this->_resultMessages('batch_1'), 'Batch with simple operations performed successfully.');
|
||||
|
@ -62,7 +62,7 @@ class ProcessingTest extends WebTestBase {
|
|||
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
|
||||
|
||||
// Batch 2: one multistep operation.
|
||||
$edit = array('batch' => 'batch_2');
|
||||
$edit = ['batch' => 'batch_2'];
|
||||
$this->drupalPostForm('batch-test', $edit, 'Submit');
|
||||
$this->assertNoEscaped('<', 'No escaped markup is present.');
|
||||
$this->assertBatchMessages($this->_resultMessages('batch_2'), 'Batch with multistep operation performed successfully.');
|
||||
|
@ -70,7 +70,7 @@ class ProcessingTest extends WebTestBase {
|
|||
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
|
||||
|
||||
// Batch 3: simple + multistep combined.
|
||||
$edit = array('batch' => 'batch_3');
|
||||
$edit = ['batch' => 'batch_3'];
|
||||
$this->drupalPostForm('batch-test', $edit, 'Submit');
|
||||
$this->assertNoEscaped('<', 'No escaped markup is present.');
|
||||
$this->assertBatchMessages($this->_resultMessages('batch_3'), 'Batch with simple and multistep operations performed successfully.');
|
||||
|
@ -78,7 +78,7 @@ class ProcessingTest extends WebTestBase {
|
|||
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
|
||||
|
||||
// Batch 4: nested batch.
|
||||
$edit = array('batch' => 'batch_4');
|
||||
$edit = ['batch' => 'batch_4'];
|
||||
$this->drupalPostForm('batch-test', $edit, 'Submit');
|
||||
$this->assertNoEscaped('<', 'No escaped markup is present.');
|
||||
$this->assertBatchMessages($this->_resultMessages('batch_4'), 'Nested batch performed successfully.');
|
||||
|
@ -89,34 +89,41 @@ class ProcessingTest extends WebTestBase {
|
|||
/**
|
||||
* Tests batches defined in a multistep form.
|
||||
*/
|
||||
function testBatchFormMultistep() {
|
||||
public function testBatchFormMultistep() {
|
||||
$this->drupalGet('batch-test/multistep');
|
||||
$this->assertNoEscaped('<', 'No escaped markup is present.');
|
||||
$this->assertText('step 1', 'Form is displayed in step 1.');
|
||||
|
||||
// First step triggers batch 1.
|
||||
$this->drupalPostForm(NULL, array(), 'Submit');
|
||||
$this->drupalPostForm(NULL, [], 'Submit');
|
||||
$this->assertBatchMessages($this->_resultMessages('batch_1'), 'Batch for step 1 performed successfully.');
|
||||
$this->assertEqual(batch_test_stack(), $this->_resultStack('batch_1'), 'Execution order was correct.');
|
||||
$this->assertText('step 2', 'Form is displayed in step 2.');
|
||||
$this->assertNoEscaped('<', 'No escaped markup is present.');
|
||||
|
||||
// Second step triggers batch 2.
|
||||
$this->drupalPostForm(NULL, array(), 'Submit');
|
||||
$this->drupalPostForm(NULL, [], 'Submit');
|
||||
$this->assertBatchMessages($this->_resultMessages('batch_2'), 'Batch for step 2 performed successfully.');
|
||||
$this->assertEqual(batch_test_stack(), $this->_resultStack('batch_2'), 'Execution order was correct.');
|
||||
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
|
||||
$this->assertNoEscaped('<', 'No escaped markup is present.');
|
||||
|
||||
// Extra query arguments will trigger logic that will add them to the
|
||||
// redirect URL. Make sure they are persisted.
|
||||
$this->drupalGet('batch-test/multistep', ['query' => ['big_tree' => 'small_axe']]);
|
||||
$this->drupalPostForm(NULL, [], 'Submit');
|
||||
$this->assertText('step 2', 'Form is displayed in step 2.');
|
||||
$this->assertTrue(strpos($this->getUrl(), 'batch-test/multistep?big_tree=small_axe'), 'Query argument was persisted and another extra argument was added.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests batches defined in different submit handlers on the same form.
|
||||
*/
|
||||
function testBatchFormMultipleBatches() {
|
||||
public function testBatchFormMultipleBatches() {
|
||||
// Batches 1, 2 and 3 are triggered in sequence by different submit
|
||||
// handlers. Each submit handler modify the submitted 'value'.
|
||||
$value = rand(0, 255);
|
||||
$edit = array('value' => $value);
|
||||
$edit = ['value' => $value];
|
||||
$this->drupalPostForm('batch-test/chained', $edit, 'Submit');
|
||||
// Check that result messages are present and in the correct order.
|
||||
$this->assertBatchMessages($this->_resultMessages('chained'), 'Batches defined in separate submit handlers performed successfully.');
|
||||
|
@ -131,7 +138,7 @@ class ProcessingTest extends WebTestBase {
|
|||
*
|
||||
* Same as above, but the form is submitted through drupal_form_execute().
|
||||
*/
|
||||
function testBatchFormProgrammatic() {
|
||||
public function testBatchFormProgrammatic() {
|
||||
// Batches 1, 2 and 3 are triggered in sequence by different submit
|
||||
// handlers. Each submit handler modify the submitted 'value'.
|
||||
$value = rand(0, 255);
|
||||
|
@ -147,12 +154,12 @@ class ProcessingTest extends WebTestBase {
|
|||
/**
|
||||
* Test form submission during a batch operation.
|
||||
*/
|
||||
function testDrupalFormSubmitInBatch() {
|
||||
public function testDrupalFormSubmitInBatch() {
|
||||
// Displaying the page triggers a batch that programmatically submits a
|
||||
// form.
|
||||
$value = rand(0, 255);
|
||||
$this->drupalGet('batch-test/nested-programmatic/' . $value);
|
||||
$this->assertEqual(batch_test_stack(), array('mock form submitted with value = ' . $value), '\Drupal::formBuilder()->submitForm() ran successfully within a batch operation.');
|
||||
$this->assertEqual(batch_test_stack(), ['mock form submitted with value = ' . $value], '\Drupal::formBuilder()->submitForm() ran successfully within a batch operation.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,7 +167,7 @@ class ProcessingTest extends WebTestBase {
|
|||
*
|
||||
* @see https://www.drupal.org/node/600836
|
||||
*/
|
||||
function testBatchLargePercentage() {
|
||||
public function testBatchLargePercentage() {
|
||||
// Displaying the page triggers batch 5.
|
||||
$this->drupalGet('batch-test/large-percentage');
|
||||
$this->assertBatchMessages($this->_resultMessages('batch_5'), 'Batch for step 2 performed successfully.');
|
||||
|
@ -180,7 +187,7 @@ class ProcessingTest extends WebTestBase {
|
|||
* @return
|
||||
* TRUE on pass, FALSE on fail.
|
||||
*/
|
||||
function assertBatchMessages($texts, $message) {
|
||||
public function assertBatchMessages($texts, $message) {
|
||||
$pattern = '|' . implode('.*', $texts) . '|s';
|
||||
return $this->assertPattern($pattern, $message);
|
||||
}
|
||||
|
@ -188,8 +195,8 @@ class ProcessingTest extends WebTestBase {
|
|||
/**
|
||||
* Returns expected execution stacks for the test batches.
|
||||
*/
|
||||
function _resultStack($id, $value = 0) {
|
||||
$stack = array();
|
||||
public function _resultStack($id, $value = 0) {
|
||||
$stack = [];
|
||||
switch ($id) {
|
||||
case 'batch_1':
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
|
@ -255,8 +262,8 @@ class ProcessingTest extends WebTestBase {
|
|||
/**
|
||||
* Returns expected result messages for the test batches.
|
||||
*/
|
||||
function _resultMessages($id) {
|
||||
$messages = array();
|
||||
public function _resultMessages($id) {
|
||||
$messages = [];
|
||||
|
||||
switch ($id) {
|
||||
case 'batch_0':
|
||||
|
|
|
@ -89,7 +89,7 @@ trait AssertPageCacheContextsAndTagsTrait {
|
|||
$this->assertCacheContexts($expected_contexts);
|
||||
|
||||
// Assert page cache item + expected cache tags.
|
||||
$cid_parts = array($url->setAbsolute()->toString(), 'html');
|
||||
$cid_parts = [$url->setAbsolute()->toString(), 'html'];
|
||||
$cid = implode(':', $cid_parts);
|
||||
$cache_entry = \Drupal::cache('render')->get($cid);
|
||||
sort($cache_entry->tags);
|
||||
|
@ -122,10 +122,14 @@ trait AssertPageCacheContextsAndTagsTrait {
|
|||
*/
|
||||
protected function assertCacheTags(array $expected_tags, $include_default_tags = TRUE) {
|
||||
// The anonymous role cache tag is only added if the user is anonymous.
|
||||
if ($include_default_tags && \Drupal::currentUser()->isAnonymous()) {
|
||||
$expected_tags = Cache::mergeTags($expected_tags, ['config:user.role.anonymous']);
|
||||
if ($include_default_tags) {
|
||||
if (\Drupal::currentUser()->isAnonymous()) {
|
||||
$expected_tags = Cache::mergeTags($expected_tags, ['config:user.role.anonymous']);
|
||||
}
|
||||
$expected_tags[] = 'http_response';
|
||||
}
|
||||
$actual_tags = $this->getCacheHeaderValues('X-Drupal-Cache-Tags');
|
||||
$expected_tags = array_unique($expected_tags);
|
||||
sort($expected_tags);
|
||||
sort($actual_tags);
|
||||
$this->assertIdentical($actual_tags, $expected_tags);
|
||||
|
|
|
@ -6,6 +6,9 @@ use Drupal\simpletest\WebTestBase;
|
|||
|
||||
/**
|
||||
* Provides helper methods for cache tests.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use \Drupal\Tests\system\Functional\Cache\CacheTestBase instead.
|
||||
*/
|
||||
abstract class CacheTestBase extends WebTestBase {
|
||||
|
||||
|
@ -71,7 +74,7 @@ abstract class CacheTestBase extends WebTestBase {
|
|||
* @param $bin
|
||||
* The bin the cache item was stored in.
|
||||
*/
|
||||
function assertCacheRemoved($message, $cid = NULL, $bin = NULL) {
|
||||
public function assertCacheRemoved($message, $cid = NULL, $bin = NULL) {
|
||||
if ($bin == NULL) {
|
||||
$bin = $this->defaultBin;
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
}
|
||||
|
||||
protected function setUp() {
|
||||
$this->cachebackends = array();
|
||||
$this->cachebackends = [];
|
||||
$this->defaultValue = $this->randomMachineName(10);
|
||||
|
||||
parent::setUp();
|
||||
|
@ -134,7 +134,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
$backend = $this->getCacheBackend();
|
||||
|
||||
$this->assertIdentical(FALSE, $backend->get('test1'), "Backend does not contain data for cache id test1.");
|
||||
$with_backslash = array('foo' => '\Drupal\foo\Bar');
|
||||
$with_backslash = ['foo' => '\Drupal\foo\Bar'];
|
||||
$backend->set('test1', $with_backslash);
|
||||
$cached = $backend->get('test1');
|
||||
$this->assert(is_object($cached), "Backend returned an object for cache id test1.");
|
||||
|
@ -145,10 +145,10 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
$this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.');
|
||||
|
||||
$this->assertIdentical(FALSE, $backend->get('test2'), "Backend does not contain data for cache id test2.");
|
||||
$backend->set('test2', array('value' => 3), REQUEST_TIME + 3);
|
||||
$backend->set('test2', ['value' => 3], REQUEST_TIME + 3);
|
||||
$cached = $backend->get('test2');
|
||||
$this->assert(is_object($cached), "Backend returned an object for cache id test2.");
|
||||
$this->assertIdentical(array('value' => 3), $cached->data);
|
||||
$this->assertIdentical(['value' => 3], $cached->data);
|
||||
$this->assertTrue($cached->valid, 'Item is marked as valid.');
|
||||
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.');
|
||||
$this->assertEqual($cached->expire, REQUEST_TIME + 3, 'Expire time is correct.');
|
||||
|
@ -162,7 +162,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
$this->assertEqual($cached->expire, REQUEST_TIME - 3, 'Expire time is correct.');
|
||||
|
||||
$this->assertIdentical(FALSE, $backend->get('test4'), "Backend does not contain data for cache id test4.");
|
||||
$with_eof = array('foo' => "\nEOF\ndata");
|
||||
$with_eof = ['foo' => "\nEOF\ndata"];
|
||||
$backend->set('test4', $with_eof);
|
||||
$cached = $backend->get('test4');
|
||||
$this->assert(is_object($cached), "Backend returned an object for cache id test4.");
|
||||
|
@ -172,7 +172,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
$this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.');
|
||||
|
||||
$this->assertIdentical(FALSE, $backend->get('test5'), "Backend does not contain data for cache id test5.");
|
||||
$with_eof_and_semicolon = array('foo' => "\nEOF;\ndata");
|
||||
$with_eof_and_semicolon = ['foo' => "\nEOF;\ndata"];
|
||||
$backend->set('test5', $with_eof_and_semicolon);
|
||||
$cached = $backend->get('test5');
|
||||
$this->assert(is_object($cached), "Backend returned an object for cache id test5.");
|
||||
|
@ -181,7 +181,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.');
|
||||
$this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.');
|
||||
|
||||
$with_variable = array('foo' => '$bar');
|
||||
$with_variable = ['foo' => '$bar'];
|
||||
$backend->set('test6', $with_variable);
|
||||
$cached = $backend->get('test6');
|
||||
$this->assert(is_object($cached), "Backend returned an object for cache id test6.");
|
||||
|
@ -260,14 +260,14 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
public function testValueTypeIsKept() {
|
||||
$backend = $this->getCacheBackend();
|
||||
|
||||
$variables = array(
|
||||
$variables = [
|
||||
'test1' => 1,
|
||||
'test2' => '0',
|
||||
'test3' => '',
|
||||
'test4' => 12.64,
|
||||
'test5' => FALSE,
|
||||
'test6' => array(1, 2, 3),
|
||||
);
|
||||
'test6' => [1, 2, 3],
|
||||
];
|
||||
|
||||
// Create cache entries.
|
||||
foreach ($variables as $cid => $data) {
|
||||
|
@ -300,14 +300,14 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
$backend->set($long_cid, 300);
|
||||
|
||||
// Mismatch order for harder testing.
|
||||
$reference = array(
|
||||
$reference = [
|
||||
'test3',
|
||||
'test7',
|
||||
'test21', // Cid does not exist.
|
||||
'test6',
|
||||
'test19', // Cid does not exist until added before second getMultiple().
|
||||
'test2',
|
||||
);
|
||||
];
|
||||
|
||||
$cids = $reference;
|
||||
$ret = $backend->getMultiple($cids);
|
||||
|
@ -367,7 +367,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
$this->assertFalse(in_array('test19', $cids), "Added cache id test19 is not in cids array.");
|
||||
|
||||
// Test with a long $cid and non-numeric array key.
|
||||
$cids = array('key:key' => $long_cid);
|
||||
$cids = ['key:key' => $long_cid];
|
||||
$return = $backend->getMultiple($cids);
|
||||
$this->assertEqual(300, $return[$long_cid]->data);
|
||||
$this->assertTrue(empty($cids));
|
||||
|
@ -383,13 +383,13 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
|
||||
// Set multiple testing keys.
|
||||
$backend->set('cid_1', 'Some other value');
|
||||
$items = array(
|
||||
'cid_1' => array('data' => 1),
|
||||
'cid_2' => array('data' => 2),
|
||||
'cid_3' => array('data' => array(1, 2)),
|
||||
'cid_4' => array('data' => 1, 'expire' => $future_expiration),
|
||||
'cid_5' => array('data' => 1, 'tags' => array('test:a', 'test:b')),
|
||||
);
|
||||
$items = [
|
||||
'cid_1' => ['data' => 1],
|
||||
'cid_2' => ['data' => 2],
|
||||
'cid_3' => ['data' => [1, 2]],
|
||||
'cid_4' => ['data' => 1, 'expire' => $future_expiration],
|
||||
'cid_5' => ['data' => 1, 'tags' => ['test:a', 'test:b']],
|
||||
];
|
||||
$backend->setMultiple($items);
|
||||
$cids = array_keys($items);
|
||||
$cached = $backend->getMultiple($cids);
|
||||
|
@ -414,9 +414,9 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
// assertion.
|
||||
try {
|
||||
$items = [
|
||||
'exception_test_1' => array('data' => 1, 'tags' => []),
|
||||
'exception_test_2' => array('data' => 2, 'tags' => ['valid']),
|
||||
'exception_test_3' => array('data' => 3, 'tags' => ['node' => [3, 5, 7]]),
|
||||
'exception_test_1' => ['data' => 1, 'tags' => []],
|
||||
'exception_test_2' => ['data' => 2, 'tags' => ['valid']],
|
||||
'exception_test_3' => ['data' => 3, 'tags' => ['node' => [3, 5, 7]]],
|
||||
];
|
||||
$backend->setMultiple($items);
|
||||
$this->fail('::setMultiple() was called with invalid cache tags, runtime assertion did not fail.');
|
||||
|
@ -444,13 +444,13 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
|
||||
$backend->delete('test1');
|
||||
$backend->delete('test23'); // Nonexistent key should not cause an error.
|
||||
$backend->deleteMultiple(array(
|
||||
$backend->deleteMultiple([
|
||||
'test3',
|
||||
'test5',
|
||||
'test7',
|
||||
'test19', // Nonexistent key should not cause an error.
|
||||
'test21', // Nonexistent key should not cause an error.
|
||||
));
|
||||
]);
|
||||
|
||||
// Test if expected keys have been deleted.
|
||||
$this->assertIdentical(FALSE, $backend->get('test1'), "Cache id test1 deleted.");
|
||||
|
@ -468,7 +468,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
$this->assertIdentical(FALSE, $backend->get('test21'), "Cache id test21 does not exist.");
|
||||
|
||||
// Calling deleteMultiple() with an empty array should not cause an error.
|
||||
$this->assertFalse($backend->deleteMultiple(array()));
|
||||
$this->assertFalse($backend->deleteMultiple([]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -494,21 +494,21 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
* Test Drupal\Core\Cache\CacheBackendInterface::invalidate() and
|
||||
* Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple().
|
||||
*/
|
||||
function testInvalidate() {
|
||||
public function testInvalidate() {
|
||||
$backend = $this->getCacheBackend();
|
||||
$backend->set('test1', 1);
|
||||
$backend->set('test2', 2);
|
||||
$backend->set('test3', 2);
|
||||
$backend->set('test4', 2);
|
||||
|
||||
$reference = array('test1', 'test2', 'test3', 'test4');
|
||||
$reference = ['test1', 'test2', 'test3', 'test4'];
|
||||
|
||||
$cids = $reference;
|
||||
$ret = $backend->getMultiple($cids);
|
||||
$this->assertEqual(count($ret), 4, 'Four items returned.');
|
||||
|
||||
$backend->invalidate('test1');
|
||||
$backend->invalidateMultiple(array('test2', 'test3'));
|
||||
$backend->invalidateMultiple(['test2', 'test3']);
|
||||
|
||||
$cids = $reference;
|
||||
$ret = $backend->getMultiple($cids);
|
||||
|
@ -520,55 +520,55 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
|
|||
|
||||
// Calling invalidateMultiple() with an empty array should not cause an
|
||||
// error.
|
||||
$this->assertFalse($backend->invalidateMultiple(array()));
|
||||
$this->assertFalse($backend->invalidateMultiple([]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Drupal\Core\Cache\CacheBackendInterface::invalidateTags().
|
||||
*/
|
||||
function testInvalidateTags() {
|
||||
public function testInvalidateTags() {
|
||||
$backend = $this->getCacheBackend();
|
||||
|
||||
// Create two cache entries with the same tag and tag value.
|
||||
$backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag:2'));
|
||||
$backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag:2'));
|
||||
$backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, ['test_tag:2']);
|
||||
$backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, ['test_tag:2']);
|
||||
$this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Two cache items were created.');
|
||||
|
||||
// Invalidate test_tag of value 1. This should invalidate both entries.
|
||||
Cache::invalidateTags(array('test_tag:2'));
|
||||
Cache::invalidateTags(['test_tag:2']);
|
||||
$this->assertFalse($backend->get('test_cid_invalidate1') || $backend->get('test_cid_invalidate2'), 'Two cache items invalidated after invalidating a cache tag.');
|
||||
$this->assertTrue($backend->get('test_cid_invalidate1', TRUE) && $backend->get('test_cid_invalidate2', TRUE), 'Cache items not deleted after invalidating a cache tag.');
|
||||
|
||||
// Create two cache entries with the same tag and an array tag value.
|
||||
$backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag:1'));
|
||||
$backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag:1'));
|
||||
$backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, ['test_tag:1']);
|
||||
$backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, ['test_tag:1']);
|
||||
$this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Two cache items were created.');
|
||||
|
||||
// Invalidate test_tag of value 1. This should invalidate both entries.
|
||||
Cache::invalidateTags(array('test_tag:1'));
|
||||
Cache::invalidateTags(['test_tag:1']);
|
||||
$this->assertFalse($backend->get('test_cid_invalidate1') || $backend->get('test_cid_invalidate2'), 'Two caches removed after invalidating a cache tag.');
|
||||
$this->assertTrue($backend->get('test_cid_invalidate1', TRUE) && $backend->get('test_cid_invalidate2', TRUE), 'Cache items not deleted after invalidating a cache tag.');
|
||||
|
||||
// Create three cache entries with a mix of tags and tag values.
|
||||
$backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag:1'));
|
||||
$backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag:2'));
|
||||
$backend->set('test_cid_invalidate3', $this->defaultValue, Cache::PERMANENT, array('test_tag_foo:3'));
|
||||
$backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, ['test_tag:1']);
|
||||
$backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, ['test_tag:2']);
|
||||
$backend->set('test_cid_invalidate3', $this->defaultValue, Cache::PERMANENT, ['test_tag_foo:3']);
|
||||
$this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2') && $backend->get('test_cid_invalidate3'), 'Three cached items were created.');
|
||||
Cache::invalidateTags(array('test_tag_foo:3'));
|
||||
Cache::invalidateTags(['test_tag_foo:3']);
|
||||
$this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Cache items not matching the tag were not invalidated.');
|
||||
$this->assertFalse($backend->get('test_cid_invalidated3'), 'Cached item matching the tag was removed.');
|
||||
|
||||
// Create cache entry in multiple bins. Two cache entries
|
||||
// (test_cid_invalidate1 and test_cid_invalidate2) still exist from previous
|
||||
// tests.
|
||||
$tags = array('test_tag:1', 'test_tag:2', 'test_tag:3');
|
||||
$bins = array('path', 'bootstrap', 'page');
|
||||
$tags = ['test_tag:1', 'test_tag:2', 'test_tag:3'];
|
||||
$bins = ['path', 'bootstrap', 'page'];
|
||||
foreach ($bins as $bin) {
|
||||
$this->getCacheBackend($bin)->set('test', $this->defaultValue, Cache::PERMANENT, $tags);
|
||||
$this->assertTrue($this->getCacheBackend($bin)->get('test'), 'Cache item was set in bin.');
|
||||
}
|
||||
|
||||
Cache::invalidateTags(array('test_tag:2'));
|
||||
Cache::invalidateTags(['test_tag:2']);
|
||||
|
||||
// Test that the cache entry has been invalidated in multiple bins.
|
||||
foreach ($bins as $bin) {
|
||||
|
|
|
@ -8,6 +8,9 @@ use Drupal\Component\Utility\SafeMarkup;
|
|||
|
||||
/**
|
||||
* Provides helper methods for page cache tags tests.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use \Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase instead.
|
||||
*/
|
||||
abstract class PageCacheTagsTestBase extends WebTestBase {
|
||||
|
||||
|
@ -44,12 +47,12 @@ abstract class PageCacheTagsTestBase extends WebTestBase {
|
|||
*/
|
||||
protected function verifyPageCache(Url $url, $hit_or_miss, $tags = FALSE) {
|
||||
$this->drupalGet($url);
|
||||
$message = SafeMarkup::format('Page cache @hit_or_miss for %path.', array('@hit_or_miss' => $hit_or_miss, '%path' => $url->toString()));
|
||||
$message = SafeMarkup::format('Page cache @hit_or_miss for %path.', ['@hit_or_miss' => $hit_or_miss, '%path' => $url->toString()]);
|
||||
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), $hit_or_miss, $message);
|
||||
|
||||
if ($hit_or_miss === 'HIT' && is_array($tags)) {
|
||||
$absolute_url = $url->setAbsolute()->toString();
|
||||
$cid_parts = array($absolute_url, 'html');
|
||||
$cid_parts = [$absolute_url, 'html'];
|
||||
$cid = implode(':', $cid_parts);
|
||||
$cache_entry = \Drupal::cache('render')->get($cid);
|
||||
sort($cache_entry->tags);
|
||||
|
|
|
@ -58,7 +58,7 @@ class SessionExistsCacheContextTest extends WebTestBase {
|
|||
/**
|
||||
* Asserts whether a session cookie is present on the client or not.
|
||||
*/
|
||||
function assertSessionCookieOnClient($expected_present) {
|
||||
public function assertSessionCookieOnClient($expected_present) {
|
||||
$non_deleted_cookies = array_filter($this->cookies, function ($item) { return $item['value'] !== 'deleted'; });
|
||||
$this->assertEqual($expected_present, isset($non_deleted_cookies[$this->getSessionName()]), 'Session cookie exists.');
|
||||
}
|
||||
|
|
|
@ -15,41 +15,41 @@ class AddFeedTest extends WebTestBase {
|
|||
/**
|
||||
* Tests attaching feeds with paths, URLs, and titles.
|
||||
*/
|
||||
function testBasicFeedAddNoTitle() {
|
||||
public function testBasicFeedAddNoTitle() {
|
||||
$path = $this->randomMachineName(12);
|
||||
$external_url = 'http://' . $this->randomMachineName(12) . '/' . $this->randomMachineName(12);
|
||||
$fully_qualified_local_url = Url::fromUri('base:' . $this->randomMachineName(12), array('absolute' => TRUE))->toString();
|
||||
$fully_qualified_local_url = Url::fromUri('base:' . $this->randomMachineName(12), ['absolute' => TRUE])->toString();
|
||||
|
||||
$path_for_title = $this->randomMachineName(12);
|
||||
$external_for_title = 'http://' . $this->randomMachineName(12) . '/' . $this->randomMachineName(12);
|
||||
$fully_qualified_for_title = Url::fromUri('base:' . $this->randomMachineName(12), array('absolute' => TRUE))->toString();
|
||||
$fully_qualified_for_title = Url::fromUri('base:' . $this->randomMachineName(12), ['absolute' => TRUE])->toString();
|
||||
|
||||
$urls = array(
|
||||
'path without title' => array(
|
||||
'url' => Url::fromUri('base:' . $path, array('absolute' => TRUE))->toString(),
|
||||
$urls = [
|
||||
'path without title' => [
|
||||
'url' => Url::fromUri('base:' . $path, ['absolute' => TRUE])->toString(),
|
||||
'title' => '',
|
||||
),
|
||||
'external URL without title' => array(
|
||||
],
|
||||
'external URL without title' => [
|
||||
'url' => $external_url,
|
||||
'title' => '',
|
||||
),
|
||||
'local URL without title' => array(
|
||||
],
|
||||
'local URL without title' => [
|
||||
'url' => $fully_qualified_local_url,
|
||||
'title' => '',
|
||||
),
|
||||
'path with title' => array(
|
||||
'url' => Url::fromUri('base:' . $path_for_title, array('absolute' => TRUE))->toString(),
|
||||
],
|
||||
'path with title' => [
|
||||
'url' => Url::fromUri('base:' . $path_for_title, ['absolute' => TRUE])->toString(),
|
||||
'title' => $this->randomMachineName(12),
|
||||
),
|
||||
'external URL with title' => array(
|
||||
],
|
||||
'external URL with title' => [
|
||||
'url' => $external_for_title,
|
||||
'title' => $this->randomMachineName(12),
|
||||
),
|
||||
'local URL with title' => array(
|
||||
],
|
||||
'local URL with title' => [
|
||||
'url' => $fully_qualified_for_title,
|
||||
'title' => $this->randomMachineName(12),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$build = [];
|
||||
foreach ($urls as $feed_info) {
|
||||
|
@ -63,14 +63,14 @@ class AddFeedTest extends WebTestBase {
|
|||
$this->setRawContent($response->getContent());
|
||||
// Assert that the content contains the RSS links we specified.
|
||||
foreach ($urls as $description => $feed_info) {
|
||||
$this->assertPattern($this->urlToRSSLinkPattern($feed_info['url'], $feed_info['title']), format_string('Found correct feed header for %description', array('%description' => $description)));
|
||||
$this->assertPattern($this->urlToRSSLinkPattern($feed_info['url'], $feed_info['title']), format_string('Found correct feed header for %description', ['%description' => $description]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a pattern representing the RSS feed in the page.
|
||||
*/
|
||||
function urlToRSSLinkPattern($url, $title = '') {
|
||||
public function urlToRSSLinkPattern($url, $title = '') {
|
||||
// Escape any regular expression characters in the URL ('?' is the worst).
|
||||
$url = preg_replace('/([+?.*])/', '[$0]', $url);
|
||||
$generated_pattern = '%<link +href="' . $url . '" +rel="alternate" +title="' . $title . '" +type="application/rss.xml" */>%';
|
||||
|
@ -82,12 +82,12 @@ class AddFeedTest extends WebTestBase {
|
|||
*
|
||||
* @see https://www.drupal.org/node/1211668
|
||||
*/
|
||||
function testFeedIconEscaping() {
|
||||
$variables = array(
|
||||
public function testFeedIconEscaping() {
|
||||
$variables = [
|
||||
'#theme' => 'feed_icon',
|
||||
'#url' => 'node',
|
||||
'#title' => '<>&"\'',
|
||||
);
|
||||
];
|
||||
$text = \Drupal::service('renderer')->renderRoot($variables);
|
||||
$this->assertEqual(trim(strip_tags($text)), 'Subscribe to <>&"'', 'feed_icon template escapes reserved HTML characters.');
|
||||
}
|
||||
|
|
|
@ -16,24 +16,24 @@ class AlterTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'common_test');
|
||||
public static $modules = ['block', 'common_test'];
|
||||
|
||||
/**
|
||||
* Tests if the theme has been altered.
|
||||
*/
|
||||
function testDrupalAlter() {
|
||||
public function testDrupalAlter() {
|
||||
// This test depends on Bartik, so make sure that it is always the current
|
||||
// active theme.
|
||||
\Drupal::service('theme_handler')->install(array('bartik'));
|
||||
\Drupal::service('theme_handler')->install(['bartik']);
|
||||
\Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('bartik'));
|
||||
|
||||
$array = array('foo' => 'bar');
|
||||
$array = ['foo' => 'bar'];
|
||||
$entity = new \stdClass();
|
||||
$entity->foo = 'bar';
|
||||
|
||||
// Verify alteration of a single argument.
|
||||
$array_copy = $array;
|
||||
$array_expected = array('foo' => 'Drupal theme');
|
||||
$array_expected = ['foo' => 'Drupal theme'];
|
||||
\Drupal::moduleHandler()->alter('drupal_alter', $array_copy);
|
||||
\Drupal::theme()->alter('drupal_alter', $array_copy);
|
||||
$this->assertEqual($array_copy, $array_expected, 'Single array was altered.');
|
||||
|
@ -47,12 +47,12 @@ class AlterTest extends WebTestBase {
|
|||
|
||||
// Verify alteration of multiple arguments.
|
||||
$array_copy = $array;
|
||||
$array_expected = array('foo' => 'Drupal theme');
|
||||
$array_expected = ['foo' => 'Drupal theme'];
|
||||
$entity_copy = clone $entity;
|
||||
$entity_expected = clone $entity;
|
||||
$entity_expected->foo = 'Drupal theme';
|
||||
$array2_copy = $array;
|
||||
$array2_expected = array('foo' => 'Drupal theme');
|
||||
$array2_expected = ['foo' => 'Drupal theme'];
|
||||
\Drupal::moduleHandler()->alter('drupal_alter', $array_copy, $entity_copy, $array2_copy);
|
||||
\Drupal::theme()->alter('drupal_alter', $array_copy, $entity_copy, $array2_copy);
|
||||
$this->assertEqual($array_copy, $array_expected, 'First argument to \Drupal::moduleHandler->alter() was altered.');
|
||||
|
@ -63,9 +63,9 @@ class AlterTest extends WebTestBase {
|
|||
// common_test_module_implements_alter() places 'block' implementation after
|
||||
// other modules.
|
||||
$array_copy = $array;
|
||||
$array_expected = array('foo' => 'Drupal block theme');
|
||||
\Drupal::moduleHandler()->alter(array('drupal_alter', 'drupal_alter_foo'), $array_copy);
|
||||
\Drupal::theme()->alter(array('drupal_alter', 'drupal_alter_foo'), $array_copy);
|
||||
$array_expected = ['foo' => 'Drupal block theme'];
|
||||
\Drupal::moduleHandler()->alter(['drupal_alter', 'drupal_alter_foo'], $array_copy);
|
||||
\Drupal::theme()->alter(['drupal_alter', 'drupal_alter_foo'], $array_copy);
|
||||
$this->assertEqual($array_copy, $array_expected, 'hook_TYPE_alter() implementations ran in correct order.');
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class EarlyRenderingControllerTest extends WebTestBase {
|
|||
/**
|
||||
* Tests theme preprocess functions being able to attach assets.
|
||||
*/
|
||||
function testEarlyRendering() {
|
||||
public function testEarlyRendering() {
|
||||
// Render array: non-early & early.
|
||||
$this->drupalGet(Url::fromRoute('early_rendering_controller_test.render_array'));
|
||||
$this->assertResponse(200);
|
||||
|
|
|
@ -17,7 +17,7 @@ class FormatDateTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language');
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Arbitrary langcode for a custom language.
|
||||
|
@ -32,16 +32,16 @@ class FormatDateTest extends WebTestBase {
|
|||
->save();
|
||||
$formats = $this->container->get('entity.manager')
|
||||
->getStorage('date_format')
|
||||
->loadMultiple(array('long', 'medium', 'short'));
|
||||
->loadMultiple(['long', 'medium', 'short']);
|
||||
$formats['long']->setPattern('l, j. F Y - G:i')->save();
|
||||
$formats['medium']->setPattern('j. F Y - G:i')->save();
|
||||
$formats['short']->setPattern('Y M j - g:ia')->save();
|
||||
$this->refreshVariables();
|
||||
|
||||
$this->settingsSet('locale_custom_strings_' . self::LANGCODE, array(
|
||||
'' => array('Sunday' => 'domingo'),
|
||||
'Long month name' => array('March' => 'marzo'),
|
||||
));
|
||||
$this->settingsSet('locale_custom_strings_' . self::LANGCODE, [
|
||||
'' => ['Sunday' => 'domingo'],
|
||||
'Long month name' => ['March' => 'marzo'],
|
||||
]);
|
||||
|
||||
ConfigurableLanguage::createFromLangcode(static::LANGCODE)->save();
|
||||
$this->resetAll();
|
||||
|
@ -50,24 +50,24 @@ class FormatDateTest extends WebTestBase {
|
|||
/**
|
||||
* Tests admin-defined formats in format_date().
|
||||
*/
|
||||
function testAdminDefinedFormatDate() {
|
||||
public function testAdminDefinedFormatDate() {
|
||||
// Create and log in an admin user.
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer site configuration')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer site configuration']));
|
||||
|
||||
// Add new date format.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'id' => 'example_style',
|
||||
'label' => 'Example Style',
|
||||
'date_format_pattern' => 'j M y',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
|
||||
|
||||
// Add a second date format with a different case than the first.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'id' => 'example_style_uppercase',
|
||||
'label' => 'Example Style Uppercase',
|
||||
'date_format_pattern' => 'j M Y',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
|
||||
$this->assertText(t('Custom date format added.'));
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\system\Tests\Common;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
/**
|
||||
* Tests that anonymous users are not served any JavaScript in the Standard
|
||||
|
@ -18,7 +19,7 @@ class NoJavaScriptAnonymousTest extends WebTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Grant the anonymous user the permission to look at user profiles.
|
||||
user_role_grant_permissions('anonymous', array('access user profiles'));
|
||||
user_role_grant_permissions('anonymous', ['access user profiles']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,9 +27,9 @@ class NoJavaScriptAnonymousTest extends WebTestBase {
|
|||
*/
|
||||
public function testNoJavaScript() {
|
||||
// Create a node that is listed on the frontpage.
|
||||
$this->drupalCreateNode(array(
|
||||
'promote' => NODE_PROMOTED,
|
||||
));
|
||||
$this->drupalCreateNode([
|
||||
'promote' => NodeInterface::PROMOTED,
|
||||
]);
|
||||
$user = $this->drupalCreateUser();
|
||||
|
||||
// Test frontpage.
|
||||
|
|
|
@ -19,12 +19,12 @@ class RenderWebTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('common_test');
|
||||
public static $modules = ['common_test'];
|
||||
|
||||
/**
|
||||
* Asserts the cache context for the wrapper format is always present.
|
||||
*/
|
||||
function testWrapperFormatCacheContext() {
|
||||
public function testWrapperFormatCacheContext() {
|
||||
$this->drupalGet('common-test/type-link-active-class');
|
||||
$this->assertIdentical(0, strpos($this->getRawContent(), "<!DOCTYPE html>\n<html"));
|
||||
$this->assertIdentical('text/html; charset=UTF-8', $this->drupalGetHeader('Content-Type'));
|
||||
|
@ -43,135 +43,135 @@ class RenderWebTest extends WebTestBase {
|
|||
* Tests rendering form elements without passing through
|
||||
* \Drupal::formBuilder()->doBuildForm().
|
||||
*/
|
||||
function testDrupalRenderFormElements() {
|
||||
public function testDrupalRenderFormElements() {
|
||||
// Define a series of form elements.
|
||||
$element = array(
|
||||
$element = [
|
||||
'#type' => 'button',
|
||||
'#value' => $this->randomMachineName(),
|
||||
);
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'submit'));
|
||||
];
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', [':type' => 'submit']);
|
||||
|
||||
$element = array(
|
||||
$element = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->randomMachineName(),
|
||||
'#value' => $this->randomMachineName(),
|
||||
);
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'text'));
|
||||
];
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', [':type' => 'text']);
|
||||
|
||||
$element = array(
|
||||
$element = [
|
||||
'#type' => 'password',
|
||||
'#title' => $this->randomMachineName(),
|
||||
);
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'password'));
|
||||
];
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', [':type' => 'password']);
|
||||
|
||||
$element = array(
|
||||
$element = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->randomMachineName(),
|
||||
'#value' => $this->randomMachineName(),
|
||||
);
|
||||
];
|
||||
$this->assertRenderedElement($element, '//textarea');
|
||||
|
||||
$element = array(
|
||||
$element = [
|
||||
'#type' => 'radio',
|
||||
'#title' => $this->randomMachineName(),
|
||||
'#value' => FALSE,
|
||||
);
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'radio'));
|
||||
];
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', [':type' => 'radio']);
|
||||
|
||||
$element = array(
|
||||
$element = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->randomMachineName(),
|
||||
);
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'checkbox'));
|
||||
];
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', [':type' => 'checkbox']);
|
||||
|
||||
$element = array(
|
||||
$element = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->randomMachineName(),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
0 => $this->randomMachineName(),
|
||||
1 => $this->randomMachineName(),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$this->assertRenderedElement($element, '//select');
|
||||
|
||||
$element = array(
|
||||
$element = [
|
||||
'#type' => 'file',
|
||||
'#title' => $this->randomMachineName(),
|
||||
);
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'file'));
|
||||
];
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', [':type' => 'file']);
|
||||
|
||||
$element = array(
|
||||
$element = [
|
||||
'#type' => 'item',
|
||||
'#title' => $this->randomMachineName(),
|
||||
'#markup' => $this->randomMachineName(),
|
||||
);
|
||||
$this->assertRenderedElement($element, '//div[contains(@class, :class) and contains(., :markup)]/label[contains(., :label)]', array(
|
||||
];
|
||||
$this->assertRenderedElement($element, '//div[contains(@class, :class) and contains(., :markup)]/label[contains(., :label)]', [
|
||||
':class' => 'js-form-type-item',
|
||||
':markup' => $element['#markup'],
|
||||
':label' => $element['#title'],
|
||||
));
|
||||
]);
|
||||
|
||||
$element = array(
|
||||
$element = [
|
||||
'#type' => 'hidden',
|
||||
'#title' => $this->randomMachineName(),
|
||||
'#value' => $this->randomMachineName(),
|
||||
);
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'hidden'));
|
||||
];
|
||||
$this->assertRenderedElement($element, '//input[@type=:type]', [':type' => 'hidden']);
|
||||
|
||||
$element = array(
|
||||
$element = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->randomMachineName(),
|
||||
'#url' => Url::fromRoute('common_test.destination'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'absolute' => TRUE,
|
||||
),
|
||||
);
|
||||
$this->assertRenderedElement($element, '//a[@href=:href and contains(., :title)]', array(
|
||||
],
|
||||
];
|
||||
$this->assertRenderedElement($element, '//a[@href=:href and contains(., :title)]', [
|
||||
':href' => URL::fromRoute('common_test.destination')->setAbsolute()->toString(),
|
||||
':title' => $element['#title'],
|
||||
));
|
||||
]);
|
||||
|
||||
$element = array(
|
||||
$element = [
|
||||
'#type' => 'details',
|
||||
'#open' => TRUE,
|
||||
'#title' => $this->randomMachineName(),
|
||||
);
|
||||
$this->assertRenderedElement($element, '//details/summary[contains(., :title)]', array(
|
||||
];
|
||||
$this->assertRenderedElement($element, '//details/summary[contains(., :title)]', [
|
||||
':title' => $element['#title'],
|
||||
));
|
||||
]);
|
||||
|
||||
$element = array(
|
||||
$element = [
|
||||
'#type' => 'details',
|
||||
'#open' => TRUE,
|
||||
'#title' => $this->randomMachineName(),
|
||||
);
|
||||
];
|
||||
$this->assertRenderedElement($element, '//details');
|
||||
|
||||
$element['item'] = array(
|
||||
$element['item'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => $this->randomMachineName(),
|
||||
'#markup' => $this->randomMachineName(),
|
||||
);
|
||||
$this->assertRenderedElement($element, '//details/div/div[contains(@class, :class) and contains(., :markup)]', array(
|
||||
];
|
||||
$this->assertRenderedElement($element, '//details/div/div[contains(@class, :class) and contains(., :markup)]', [
|
||||
':class' => 'js-form-type-item',
|
||||
':markup' => $element['item']['#markup'],
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that elements are rendered properly.
|
||||
*/
|
||||
protected function assertRenderedElement(array $element, $xpath, array $xpath_args = array()) {
|
||||
protected function assertRenderedElement(array $element, $xpath, array $xpath_args = []) {
|
||||
$original_element = $element;
|
||||
$this->setRawContent(drupal_render_root($element));
|
||||
$this->verbose('<hr />' . $this->getRawContent());
|
||||
|
||||
// @see \Drupal\simpletest\WebTestBase::xpath()
|
||||
$xpath = $this->buildXPathQuery($xpath, $xpath_args);
|
||||
$element += array('#value' => NULL);
|
||||
$this->assertFieldByXPath($xpath, $element['#value'], format_string('#type @type was properly rendered.', array(
|
||||
$element += ['#value' => NULL];
|
||||
$this->assertFieldByXPath($xpath, $element['#value'], format_string('#type @type was properly rendered.', [
|
||||
'@type' => var_export($element['#type'], TRUE),
|
||||
)));
|
||||
]));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class SimpleTestErrorCollectorTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('system_test', 'error_test');
|
||||
public static $modules = ['system_test', 'error_test'];
|
||||
|
||||
/**
|
||||
* Errors triggered during the test.
|
||||
|
@ -26,13 +26,13 @@ class SimpleTestErrorCollectorTest extends WebTestBase {
|
|||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $collectedErrors = array();
|
||||
protected $collectedErrors = [];
|
||||
|
||||
/**
|
||||
* Tests that simpletest collects errors from the tested site.
|
||||
*/
|
||||
function testErrorCollect() {
|
||||
$this->collectedErrors = array();
|
||||
public function testErrorCollect() {
|
||||
$this->collectedErrors = [];
|
||||
$this->drupalGet('error-test/generate-warnings-with-report');
|
||||
$this->assertEqual(count($this->collectedErrors), 3, 'Three errors were collected');
|
||||
|
||||
|
@ -71,23 +71,23 @@ class SimpleTestErrorCollectorTest extends WebTestBase {
|
|||
}
|
||||
// Everything else should be collected but not propagated.
|
||||
else {
|
||||
$this->collectedErrors[] = array(
|
||||
$this->collectedErrors[] = [
|
||||
'message' => $message,
|
||||
'group' => $group,
|
||||
'caller' => $caller
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a collected error matches what we are expecting.
|
||||
*/
|
||||
function assertError($error, $group, $function, $file, $message = NULL) {
|
||||
$this->assertEqual($error['group'], $group, format_string("Group was %group", array('%group' => $group)));
|
||||
$this->assertEqual($error['caller']['function'], $function, format_string("Function was %function", array('%function' => $function)));
|
||||
$this->assertEqual(drupal_basename($error['caller']['file']), $file, format_string("File was %file", array('%file' => $file)));
|
||||
public function assertError($error, $group, $function, $file, $message = NULL) {
|
||||
$this->assertEqual($error['group'], $group, format_string("Group was %group", ['%group' => $group]));
|
||||
$this->assertEqual($error['caller']['function'], $function, format_string("Function was %function", ['%function' => $function]));
|
||||
$this->assertEqual(drupal_basename($error['caller']['file']), $file, format_string("File was %file", ['%file' => $file]));
|
||||
if (isset($message)) {
|
||||
$this->assertEqual($error['message'], $message, format_string("Message was %message", array('%message' => $message)));
|
||||
$this->assertEqual($error['message'], $message, format_string("Message was %message", ['%message' => $message]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,19 +20,19 @@ use Drupal\simpletest\WebTestBase;
|
|||
*/
|
||||
class UrlTest extends WebTestBase {
|
||||
|
||||
public static $modules = array('common_test', 'url_alter_test');
|
||||
public static $modules = ['common_test', 'url_alter_test'];
|
||||
|
||||
/**
|
||||
* Confirms that invalid URLs are filtered in link generating functions.
|
||||
*/
|
||||
function testLinkXSS() {
|
||||
public function testLinkXSS() {
|
||||
// Test \Drupal::l().
|
||||
$text = $this->randomMachineName();
|
||||
$path = "<SCRIPT>alert('XSS')</SCRIPT>";
|
||||
$encoded_path = "3CSCRIPT%3Ealert%28%27XSS%27%29%3C/SCRIPT%3E";
|
||||
|
||||
$link = \Drupal::l($text, Url::fromUserInput('/' . $path));
|
||||
$this->assertTrue(strpos($link, $encoded_path) !== FALSE && strpos($link, $path) === FALSE, format_string('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', array('@path' => $path)));
|
||||
$this->assertTrue(strpos($link, $encoded_path) !== FALSE && strpos($link, $path) === FALSE, format_string('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', ['@path' => $path]));
|
||||
|
||||
// Test \Drupal\Core\Url.
|
||||
$link = Url::fromUri('base:' . $path)->toString();
|
||||
|
@ -42,7 +42,7 @@ class UrlTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that #type=link bubbles outbound route/path processors' metadata.
|
||||
*/
|
||||
function testLinkBubbleableMetadata() {
|
||||
public function testLinkBubbleableMetadata() {
|
||||
$cases = [
|
||||
['Regular link', 'internal:/user', [], ['contexts' => [], 'tags' => [], 'max-age' => Cache::PERMANENT], []],
|
||||
['Regular link, absolute', 'internal:/user', ['absolute' => TRUE], ['contexts' => ['url.site'], 'tags' => [], 'max-age' => Cache::PERMANENT], []],
|
||||
|
@ -71,20 +71,20 @@ class UrlTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that default and custom attributes are handled correctly on links.
|
||||
*/
|
||||
function testLinkAttributes() {
|
||||
public function testLinkAttributes() {
|
||||
/** @var \Drupal\Core\Render\RendererInterface $renderer */
|
||||
$renderer = $this->container->get('renderer');
|
||||
|
||||
// Test that hreflang is added when a link has a known language.
|
||||
$language = new Language(array('id' => 'fr', 'name' => 'French'));
|
||||
$hreflang_link = array(
|
||||
$language = new Language(['id' => 'fr', 'name' => 'French']);
|
||||
$hreflang_link = [
|
||||
'#type' => 'link',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'language' => $language,
|
||||
),
|
||||
],
|
||||
'#url' => Url::fromUri('https://www.drupal.org'),
|
||||
'#title' => 'bar',
|
||||
);
|
||||
];
|
||||
$langcode = $language->getId();
|
||||
|
||||
// Test that the default hreflang handling for links does not override a
|
||||
|
@ -93,45 +93,45 @@ class UrlTest extends WebTestBase {
|
|||
$hreflang_override_link['#options']['attributes']['hreflang'] = 'foo';
|
||||
|
||||
$rendered = $renderer->renderRoot($hreflang_link);
|
||||
$this->assertTrue($this->hasAttribute('hreflang', $rendered, $langcode), format_string('hreflang attribute with value @langcode is present on a rendered link when langcode is provided in the render array.', array('@langcode' => $langcode)));
|
||||
$this->assertTrue($this->hasAttribute('hreflang', $rendered, $langcode), format_string('hreflang attribute with value @langcode is present on a rendered link when langcode is provided in the render array.', ['@langcode' => $langcode]));
|
||||
|
||||
$rendered = $renderer->renderRoot($hreflang_override_link);
|
||||
$this->assertTrue($this->hasAttribute('hreflang', $rendered, 'foo'), format_string('hreflang attribute with value @hreflang is present on a rendered link when @hreflang is provided in the render array.', array('@hreflang' => 'foo')));
|
||||
$this->assertTrue($this->hasAttribute('hreflang', $rendered, 'foo'), format_string('hreflang attribute with value @hreflang is present on a rendered link when @hreflang is provided in the render array.', ['@hreflang' => 'foo']));
|
||||
|
||||
// Test the active class in links produced by
|
||||
// \Drupal\Core\Utility\LinkGeneratorInterface::generate() and #type 'link'.
|
||||
$options_no_query = array();
|
||||
$options_query = array(
|
||||
'query' => array(
|
||||
$options_no_query = [];
|
||||
$options_query = [
|
||||
'query' => [
|
||||
'foo' => 'bar',
|
||||
'one' => 'two',
|
||||
),
|
||||
);
|
||||
$options_query_reverse = array(
|
||||
'query' => array(
|
||||
],
|
||||
];
|
||||
$options_query_reverse = [
|
||||
'query' => [
|
||||
'one' => 'two',
|
||||
'foo' => 'bar',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Test #type link.
|
||||
$path = 'common-test/type-link-active-class';
|
||||
|
||||
$this->drupalGet($path, $options_no_query);
|
||||
$links = $this->xpath('//a[@href = :href and contains(@class, :class)]', array(':href' => Url::fromRoute('common_test.l_active_class', [], $options_no_query)->toString(), ':class' => 'is-active'));
|
||||
$links = $this->xpath('//a[@href = :href and contains(@class, :class)]', [':href' => Url::fromRoute('common_test.l_active_class', [], $options_no_query)->toString(), ':class' => 'is-active']);
|
||||
$this->assertTrue(isset($links[0]), 'A link generated by the link generator to the current page is marked active.');
|
||||
|
||||
$links = $this->xpath('//a[@href = :href and not(contains(@class, :class))]', array(':href' => Url::fromRoute('common_test.l_active_class', [], $options_query)->toString(), ':class' => 'is-active'));
|
||||
$links = $this->xpath('//a[@href = :href and not(contains(@class, :class))]', [':href' => Url::fromRoute('common_test.l_active_class', [], $options_query)->toString(), ':class' => 'is-active']);
|
||||
$this->assertTrue(isset($links[0]), 'A link generated by the link generator to the current page with a query string when the current page has no query string is not marked active.');
|
||||
|
||||
$this->drupalGet($path, $options_query);
|
||||
$links = $this->xpath('//a[@href = :href and contains(@class, :class)]', array(':href' => Url::fromRoute('common_test.l_active_class', [], $options_query)->toString(), ':class' => 'is-active'));
|
||||
$links = $this->xpath('//a[@href = :href and contains(@class, :class)]', [':href' => Url::fromRoute('common_test.l_active_class', [], $options_query)->toString(), ':class' => 'is-active']);
|
||||
$this->assertTrue(isset($links[0]), 'A link generated by the link generator to the current page with a query string that matches the current query string is marked active.');
|
||||
|
||||
$links = $this->xpath('//a[@href = :href and contains(@class, :class)]', array(':href' => Url::fromRoute('common_test.l_active_class', [], $options_query_reverse)->toString(), ':class' => 'is-active'));
|
||||
$links = $this->xpath('//a[@href = :href and contains(@class, :class)]', [':href' => Url::fromRoute('common_test.l_active_class', [], $options_query_reverse)->toString(), ':class' => 'is-active']);
|
||||
$this->assertTrue(isset($links[0]), 'A link generated by the link generator to the current page with a query string that has matching parameters to the current query string but in a different order is marked active.');
|
||||
|
||||
$links = $this->xpath('//a[@href = :href and not(contains(@class, :class))]', array(':href' => Url::fromRoute('common_test.l_active_class', [], $options_no_query)->toString(), ':class' => 'is-active'));
|
||||
$links = $this->xpath('//a[@href = :href and not(contains(@class, :class))]', [':href' => Url::fromRoute('common_test.l_active_class', [], $options_no_query)->toString(), ':class' => 'is-active']);
|
||||
$this->assertTrue(isset($links[0]), 'A link generated by the link generator to the current page without a query string when the current page has a query string is not marked active.');
|
||||
|
||||
// Test adding a custom class in links produced by
|
||||
|
@ -139,28 +139,28 @@ class UrlTest extends WebTestBase {
|
|||
// Test the link generator.
|
||||
$class_l = $this->randomMachineName();
|
||||
$link_l = \Drupal::l($this->randomMachineName(), new Url('<current>', [], ['attributes' => ['class' => [$class_l]]]));
|
||||
$this->assertTrue($this->hasAttribute('class', $link_l, $class_l), format_string('Custom class @class is present on link when requested by l()', array('@class' => $class_l)));
|
||||
$this->assertTrue($this->hasAttribute('class', $link_l, $class_l), format_string('Custom class @class is present on link when requested by l()', ['@class' => $class_l]));
|
||||
|
||||
// Test #type.
|
||||
$class_theme = $this->randomMachineName();
|
||||
$type_link = array(
|
||||
$type_link = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->randomMachineName(),
|
||||
'#url' => Url::fromRoute('<current>'),
|
||||
'#options' => array(
|
||||
'attributes' => array(
|
||||
'class' => array($class_theme),
|
||||
),
|
||||
),
|
||||
);
|
||||
'#options' => [
|
||||
'attributes' => [
|
||||
'class' => [$class_theme],
|
||||
],
|
||||
],
|
||||
];
|
||||
$link_theme = $renderer->renderRoot($type_link);
|
||||
$this->assertTrue($this->hasAttribute('class', $link_theme, $class_theme), format_string('Custom class @class is present on link when requested by #type', array('@class' => $class_theme)));
|
||||
$this->assertTrue($this->hasAttribute('class', $link_theme, $class_theme), format_string('Custom class @class is present on link when requested by #type', ['@class' => $class_theme]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that link functions support render arrays as 'text'.
|
||||
*/
|
||||
function testLinkRenderArrayText() {
|
||||
public function testLinkRenderArrayText() {
|
||||
/** @var \Drupal\Core\Render\RendererInterface $renderer */
|
||||
$renderer = $this->container->get('renderer');
|
||||
|
||||
|
@ -169,26 +169,26 @@ class UrlTest extends WebTestBase {
|
|||
|
||||
// Test a renderable array passed to the link generator.
|
||||
$renderer->executeInRenderContext(new RenderContext(), function() use ($renderer, $l) {
|
||||
$renderable_text = array('#markup' => 'foo');
|
||||
$renderable_text = ['#markup' => 'foo'];
|
||||
$l_renderable_text = \Drupal::l($renderable_text, Url::fromUri('https://www.drupal.org'));
|
||||
$this->assertEqual($l_renderable_text, $l);
|
||||
});
|
||||
|
||||
// Test a themed link with plain text 'text'.
|
||||
$type_link_plain_array = array(
|
||||
$type_link_plain_array = [
|
||||
'#type' => 'link',
|
||||
'#title' => 'foo',
|
||||
'#url' => Url::fromUri('https://www.drupal.org'),
|
||||
);
|
||||
];
|
||||
$type_link_plain = $renderer->renderRoot($type_link_plain_array);
|
||||
$this->assertEqual($type_link_plain, $l);
|
||||
|
||||
// Build a themed link with renderable 'text'.
|
||||
$type_link_nested_array = array(
|
||||
$type_link_nested_array = [
|
||||
'#type' => 'link',
|
||||
'#title' => array('#markup' => 'foo'),
|
||||
'#title' => ['#markup' => 'foo'],
|
||||
'#url' => Url::fromUri('https://www.drupal.org'),
|
||||
);
|
||||
];
|
||||
$type_link_nested = $renderer->renderRoot($type_link_nested_array);
|
||||
$this->assertEqual($type_link_nested, $l);
|
||||
}
|
||||
|
@ -211,54 +211,54 @@ class UrlTest extends WebTestBase {
|
|||
/**
|
||||
* Tests UrlHelper::filterQueryParameters().
|
||||
*/
|
||||
function testDrupalGetQueryParameters() {
|
||||
$original = array(
|
||||
public function testDrupalGetQueryParameters() {
|
||||
$original = [
|
||||
'a' => 1,
|
||||
'b' => array(
|
||||
'b' => [
|
||||
'd' => 4,
|
||||
'e' => array(
|
||||
'e' => [
|
||||
'f' => 5,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
'c' => 3,
|
||||
);
|
||||
];
|
||||
|
||||
// First-level exclusion.
|
||||
$result = $original;
|
||||
unset($result['b']);
|
||||
$this->assertEqual(UrlHelper::filterQueryParameters($original, array('b')), $result, "'b' was removed.");
|
||||
$this->assertEqual(UrlHelper::filterQueryParameters($original, ['b']), $result, "'b' was removed.");
|
||||
|
||||
// Second-level exclusion.
|
||||
$result = $original;
|
||||
unset($result['b']['d']);
|
||||
$this->assertEqual(UrlHelper::filterQueryParameters($original, array('b[d]')), $result, "'b[d]' was removed.");
|
||||
$this->assertEqual(UrlHelper::filterQueryParameters($original, ['b[d]']), $result, "'b[d]' was removed.");
|
||||
|
||||
// Third-level exclusion.
|
||||
$result = $original;
|
||||
unset($result['b']['e']['f']);
|
||||
$this->assertEqual(UrlHelper::filterQueryParameters($original, array('b[e][f]')), $result, "'b[e][f]' was removed.");
|
||||
$this->assertEqual(UrlHelper::filterQueryParameters($original, ['b[e][f]']), $result, "'b[e][f]' was removed.");
|
||||
|
||||
// Multiple exclusions.
|
||||
$result = $original;
|
||||
unset($result['a'], $result['b']['e'], $result['c']);
|
||||
$this->assertEqual(UrlHelper::filterQueryParameters($original, array('a', 'b[e]', 'c')), $result, "'a', 'b[e]', 'c' were removed.");
|
||||
$this->assertEqual(UrlHelper::filterQueryParameters($original, ['a', 'b[e]', 'c']), $result, "'a', 'b[e]', 'c' were removed.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests UrlHelper::parse().
|
||||
*/
|
||||
function testDrupalParseUrl() {
|
||||
public function testDrupalParseUrl() {
|
||||
// Relative, absolute, and external URLs, without/with explicit script path,
|
||||
// without/with Drupal path.
|
||||
foreach (array('', '/', 'https://www.drupal.org/') as $absolute) {
|
||||
foreach (array('', 'index.php/') as $script) {
|
||||
foreach (array('', 'foo/bar') as $path) {
|
||||
foreach (['', '/', 'https://www.drupal.org/'] as $absolute) {
|
||||
foreach (['', 'index.php/'] as $script) {
|
||||
foreach (['', 'foo/bar'] as $path) {
|
||||
$url = $absolute . $script . $path . '?foo=bar&bar=baz&baz#foo';
|
||||
$expected = array(
|
||||
$expected = [
|
||||
'path' => $absolute . $script . $path,
|
||||
'query' => array('foo' => 'bar', 'bar' => 'baz', 'baz' => ''),
|
||||
'query' => ['foo' => 'bar', 'bar' => 'baz', 'baz' => ''],
|
||||
'fragment' => 'foo',
|
||||
);
|
||||
];
|
||||
$this->assertEqual(UrlHelper::parse($url), $expected, 'URL parsed correctly.');
|
||||
}
|
||||
}
|
||||
|
@ -266,11 +266,11 @@ class UrlTest extends WebTestBase {
|
|||
|
||||
// Relative URL that is known to confuse parse_url().
|
||||
$url = 'foo/bar:1';
|
||||
$result = array(
|
||||
$result = [
|
||||
'path' => 'foo/bar:1',
|
||||
'query' => array(),
|
||||
'query' => [],
|
||||
'fragment' => '',
|
||||
);
|
||||
];
|
||||
$this->assertEqual(UrlHelper::parse($url), $result, 'Relative URL parsed correctly.');
|
||||
|
||||
// Test that drupal can recognize an absolute URL. Used to prevent attack vectors.
|
||||
|
@ -285,7 +285,7 @@ class UrlTest extends WebTestBase {
|
|||
/**
|
||||
* Tests external URL handling.
|
||||
*/
|
||||
function testExternalUrls() {
|
||||
public function testExternalUrls() {
|
||||
$test_url = 'https://www.drupal.org/';
|
||||
|
||||
// Verify external URL can contain a fragment.
|
||||
|
@ -296,7 +296,7 @@ class UrlTest extends WebTestBase {
|
|||
// Verify fragment can be overridden in an external URL.
|
||||
$url = $test_url . '#drupal';
|
||||
$fragment = $this->randomMachineName(10);
|
||||
$result = Url::fromUri($url, array('fragment' => $fragment))->toString();
|
||||
$result = Url::fromUri($url, ['fragment' => $fragment])->toString();
|
||||
$this->assertEqual($test_url . '#' . $fragment, $result, 'External URL fragment is overridden with a custom fragment in $options.');
|
||||
|
||||
// Verify external URL can contain a query string.
|
||||
|
@ -306,14 +306,14 @@ class UrlTest extends WebTestBase {
|
|||
|
||||
// Verify external URL can be extended with a query string.
|
||||
$url = $test_url;
|
||||
$query = array($this->randomMachineName(5) => $this->randomMachineName(5));
|
||||
$result = Url::fromUri($url, array('query' => $query))->toString();
|
||||
$query = [$this->randomMachineName(5) => $this->randomMachineName(5)];
|
||||
$result = Url::fromUri($url, ['query' => $query])->toString();
|
||||
$this->assertEqual($url . '?' . http_build_query($query, '', '&'), $result, 'External URL can be extended with a query string in $options.');
|
||||
|
||||
// Verify query string can be extended in an external URL.
|
||||
$url = $test_url . '?drupal=awesome';
|
||||
$query = array($this->randomMachineName(5) => $this->randomMachineName(5));
|
||||
$result = Url::fromUri($url, array('query' => $query))->toString();
|
||||
$query = [$this->randomMachineName(5) => $this->randomMachineName(5)];
|
||||
$result = Url::fromUri($url, ['query' => $query])->toString();
|
||||
$this->assertEqual($url . '&' . http_build_query($query, '', '&'), $result);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,14 +16,14 @@ use Drupal\simpletest\WebTestBase;
|
|||
*/
|
||||
class ConditionFormTest extends WebTestBase {
|
||||
|
||||
public static $modules = array('node', 'condition_test');
|
||||
public static $modules = ['node', 'condition_test'];
|
||||
|
||||
/**
|
||||
* Submit the condition_node_type_test_form to test condition forms.
|
||||
*/
|
||||
function testConfigForm() {
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Page'));
|
||||
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
|
||||
public function testConfigForm() {
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Page']);
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
|
||||
$article = Node::create([
|
||||
'type' => 'article',
|
||||
|
@ -34,7 +34,7 @@ class ConditionFormTest extends WebTestBase {
|
|||
$this->drupalGet('condition_test');
|
||||
$this->assertField('bundles[article]', 'There is an article bundle selector.');
|
||||
$this->assertField('bundles[page]', 'There is a page bundle selector.');
|
||||
$this->drupalPostForm(NULL, array('bundles[page]' => 'page', 'bundles[article]' => 'article'), t('Submit'));
|
||||
$this->drupalPostForm(NULL, ['bundles[page]' => 'page', 'bundles[article]' => 'article'], t('Submit'));
|
||||
// @see \Drupal\condition_test\FormController::submitForm()
|
||||
$this->assertText('Bundle: page');
|
||||
$this->assertText('Bundle: article');
|
||||
|
|
|
@ -15,7 +15,7 @@ abstract class DatabaseWebTestBase extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('database_test');
|
||||
public static $modules = ['database_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
|
|
@ -16,7 +16,7 @@ class SelectPagerDefaultTest extends DatabaseWebTestBase {
|
|||
* Note that we have to make an HTTP request to a test page handler
|
||||
* because the pager depends on GET parameters.
|
||||
*/
|
||||
function testEvenPagerQuery() {
|
||||
public function testEvenPagerQuery() {
|
||||
// To keep the test from being too brittle, we determine up front
|
||||
// what the page count should be dynamically, and pass the control
|
||||
// information forward to the actual query on the other side of the
|
||||
|
@ -33,14 +33,14 @@ class SelectPagerDefaultTest extends DatabaseWebTestBase {
|
|||
}
|
||||
|
||||
for ($page = 0; $page <= $num_pages; ++$page) {
|
||||
$this->drupalGet('database_test/pager_query_even/' . $limit, array('query' => array('page' => $page)));
|
||||
$this->drupalGet('database_test/pager_query_even/' . $limit, ['query' => ['page' => $page]]);
|
||||
$data = json_decode($this->getRawContent());
|
||||
|
||||
if ($page == $num_pages) {
|
||||
$correct_number = $count - ($limit * $page);
|
||||
}
|
||||
|
||||
$this->assertEqual(count($data->names), $correct_number, format_string('Correct number of records returned by pager: @number', array('@number' => $correct_number)));
|
||||
$this->assertEqual(count($data->names), $correct_number, format_string('Correct number of records returned by pager: @number', ['@number' => $correct_number]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ class SelectPagerDefaultTest extends DatabaseWebTestBase {
|
|||
* Note that we have to make an HTTP request to a test page handler
|
||||
* because the pager depends on GET parameters.
|
||||
*/
|
||||
function testOddPagerQuery() {
|
||||
public function testOddPagerQuery() {
|
||||
// To keep the test from being too brittle, we determine up front
|
||||
// what the page count should be dynamically, and pass the control
|
||||
// information forward to the actual query on the other side of the
|
||||
|
@ -67,14 +67,14 @@ class SelectPagerDefaultTest extends DatabaseWebTestBase {
|
|||
}
|
||||
|
||||
for ($page = 0; $page <= $num_pages; ++$page) {
|
||||
$this->drupalGet('database_test/pager_query_odd/' . $limit, array('query' => array('page' => $page)));
|
||||
$this->drupalGet('database_test/pager_query_odd/' . $limit, ['query' => ['page' => $page]]);
|
||||
$data = json_decode($this->getRawContent());
|
||||
|
||||
if ($page == $num_pages) {
|
||||
$correct_number = $count - ($limit * $page);
|
||||
}
|
||||
|
||||
$this->assertEqual(count($data->names), $correct_number, format_string('Correct number of records returned by pager: @number', array('@number' => $correct_number)));
|
||||
$this->assertEqual(count($data->names), $correct_number, format_string('Correct number of records returned by pager: @number', ['@number' => $correct_number]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,11 +83,11 @@ class SelectPagerDefaultTest extends DatabaseWebTestBase {
|
|||
*
|
||||
* This is a regression test for #467984.
|
||||
*/
|
||||
function testInnerPagerQuery() {
|
||||
public function testInnerPagerQuery() {
|
||||
$query = db_select('test', 't')
|
||||
->extend('Drupal\Core\Database\Query\PagerSelectExtender');
|
||||
$query
|
||||
->fields('t', array('age'))
|
||||
->fields('t', ['age'])
|
||||
->orderBy('age')
|
||||
->limit(5);
|
||||
|
||||
|
@ -97,7 +97,7 @@ class SelectPagerDefaultTest extends DatabaseWebTestBase {
|
|||
$ages = $outer_query
|
||||
->execute()
|
||||
->fetchCol();
|
||||
$this->assertEqual($ages, array(25, 26, 27, 28), 'Inner pager query returned the correct ages.');
|
||||
$this->assertEqual($ages, [25, 26, 27, 28], 'Inner pager query returned the correct ages.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,37 +105,37 @@ class SelectPagerDefaultTest extends DatabaseWebTestBase {
|
|||
*
|
||||
* This is a regression test for #467984.
|
||||
*/
|
||||
function testHavingPagerQuery() {
|
||||
public function testHavingPagerQuery() {
|
||||
$query = db_select('test', 't')
|
||||
->extend('Drupal\Core\Database\Query\PagerSelectExtender');
|
||||
$query
|
||||
->fields('t', array('name'))
|
||||
->fields('t', ['name'])
|
||||
->orderBy('name')
|
||||
->groupBy('name')
|
||||
->having('MAX(age) > :count', array(':count' => 26))
|
||||
->having('MAX(age) > :count', [':count' => 26])
|
||||
->limit(5);
|
||||
|
||||
$ages = $query
|
||||
->execute()
|
||||
->fetchCol();
|
||||
$this->assertEqual($ages, array('George', 'Ringo'), 'Pager query with having expression returned the correct ages.');
|
||||
$this->assertEqual($ages, ['George', 'Ringo'], 'Pager query with having expression returned the correct ages.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirms that every pager gets a valid, non-overlapping element ID.
|
||||
*/
|
||||
function testElementNumbers() {
|
||||
public function testElementNumbers() {
|
||||
|
||||
$request = Request::createFromGlobals();
|
||||
$request->query->replace(array(
|
||||
$request->query->replace([
|
||||
'page' => '3, 2, 1, 0',
|
||||
));
|
||||
]);
|
||||
\Drupal::getContainer()->get('request_stack')->push($request);
|
||||
|
||||
$name = db_select('test', 't')
|
||||
->extend('Drupal\Core\Database\Query\PagerSelectExtender')
|
||||
->element(2)
|
||||
->fields('t', array('name'))
|
||||
->fields('t', ['name'])
|
||||
->orderBy('age')
|
||||
->limit(1)
|
||||
->execute()
|
||||
|
@ -147,7 +147,7 @@ class SelectPagerDefaultTest extends DatabaseWebTestBase {
|
|||
$name = db_select('test', 't')
|
||||
->extend('Drupal\Core\Database\Query\PagerSelectExtender')
|
||||
->element(1)
|
||||
->fields('t', array('name'))
|
||||
->fields('t', ['name'])
|
||||
->orderBy('age')
|
||||
->limit(1)
|
||||
->execute()
|
||||
|
@ -156,7 +156,7 @@ class SelectPagerDefaultTest extends DatabaseWebTestBase {
|
|||
|
||||
$name = db_select('test', 't')
|
||||
->extend('Drupal\Core\Database\Query\PagerSelectExtender')
|
||||
->fields('t', array('name'))
|
||||
->fields('t', ['name'])
|
||||
->orderBy('age')
|
||||
->limit(1)
|
||||
->execute()
|
||||
|
|
|
@ -15,18 +15,18 @@ class SelectTableSortDefaultTest extends DatabaseWebTestBase {
|
|||
* Note that we have to make an HTTP request to a test page handler
|
||||
* because the pager depends on GET parameters.
|
||||
*/
|
||||
function testTableSortQuery() {
|
||||
$sorts = array(
|
||||
array('field' => t('Task ID'), 'sort' => 'desc', 'first' => 'perform at superbowl', 'last' => 'eat'),
|
||||
array('field' => t('Task ID'), 'sort' => 'asc', 'first' => 'eat', 'last' => 'perform at superbowl'),
|
||||
array('field' => t('Task'), 'sort' => 'asc', 'first' => 'code', 'last' => 'sleep'),
|
||||
array('field' => t('Task'), 'sort' => 'desc', 'first' => 'sleep', 'last' => 'code'),
|
||||
public function testTableSortQuery() {
|
||||
$sorts = [
|
||||
['field' => t('Task ID'), 'sort' => 'desc', 'first' => 'perform at superbowl', 'last' => 'eat'],
|
||||
['field' => t('Task ID'), 'sort' => 'asc', 'first' => 'eat', 'last' => 'perform at superbowl'],
|
||||
['field' => t('Task'), 'sort' => 'asc', 'first' => 'code', 'last' => 'sleep'],
|
||||
['field' => t('Task'), 'sort' => 'desc', 'first' => 'sleep', 'last' => 'code'],
|
||||
// more elements here
|
||||
|
||||
);
|
||||
];
|
||||
|
||||
foreach ($sorts as $sort) {
|
||||
$this->drupalGet('database_test/tablesort/', array('query' => array('order' => $sort['field'], 'sort' => $sort['sort'])));
|
||||
$this->drupalGet('database_test/tablesort/', ['query' => ['order' => $sort['field'], 'sort' => $sort['sort']]]);
|
||||
$data = json_decode($this->getRawContent());
|
||||
|
||||
$first = array_shift($data->tasks);
|
||||
|
@ -43,25 +43,25 @@ class SelectTableSortDefaultTest extends DatabaseWebTestBase {
|
|||
* If a tablesort's orderByHeader is called before another orderBy, then its
|
||||
* header happens first.
|
||||
*/
|
||||
function testTableSortQueryFirst() {
|
||||
$sorts = array(
|
||||
array('field' => t('Task ID'), 'sort' => 'desc', 'first' => 'perform at superbowl', 'last' => 'eat'),
|
||||
array('field' => t('Task ID'), 'sort' => 'asc', 'first' => 'eat', 'last' => 'perform at superbowl'),
|
||||
array('field' => t('Task'), 'sort' => 'asc', 'first' => 'code', 'last' => 'sleep'),
|
||||
array('field' => t('Task'), 'sort' => 'desc', 'first' => 'sleep', 'last' => 'code'),
|
||||
public function testTableSortQueryFirst() {
|
||||
$sorts = [
|
||||
['field' => t('Task ID'), 'sort' => 'desc', 'first' => 'perform at superbowl', 'last' => 'eat'],
|
||||
['field' => t('Task ID'), 'sort' => 'asc', 'first' => 'eat', 'last' => 'perform at superbowl'],
|
||||
['field' => t('Task'), 'sort' => 'asc', 'first' => 'code', 'last' => 'sleep'],
|
||||
['field' => t('Task'), 'sort' => 'desc', 'first' => 'sleep', 'last' => 'code'],
|
||||
// more elements here
|
||||
|
||||
);
|
||||
];
|
||||
|
||||
foreach ($sorts as $sort) {
|
||||
$this->drupalGet('database_test/tablesort_first/', array('query' => array('order' => $sort['field'], 'sort' => $sort['sort'])));
|
||||
$this->drupalGet('database_test/tablesort_first/', ['query' => ['order' => $sort['field'], 'sort' => $sort['sort']]]);
|
||||
$data = json_decode($this->getRawContent());
|
||||
|
||||
$first = array_shift($data->tasks);
|
||||
$last = array_pop($data->tasks);
|
||||
|
||||
$this->assertEqual($first->task, $sort['first'], format_string('Items appear in the correct order sorting by @field @sort.', array('@field' => $sort['field'], '@sort' => $sort['sort'])));
|
||||
$this->assertEqual($last->task, $sort['last'], format_string('Items appear in the correct order sorting by @field @sort.', array('@field' => $sort['field'], '@sort' => $sort['sort'])));
|
||||
$this->assertEqual($first->task, $sort['first'], format_string('Items appear in the correct order sorting by @field @sort.', ['@field' => $sort['field'], '@sort' => $sort['sort']]));
|
||||
$this->assertEqual($last->task, $sort['last'], format_string('Items appear in the correct order sorting by @field @sort.', ['@field' => $sort['field'], '@sort' => $sort['sort']]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ class SelectTableSortDefaultTest extends DatabaseWebTestBase {
|
|||
* Specifically that no sort is set in a tableselect, and that header links
|
||||
* are correct.
|
||||
*/
|
||||
function testTableSortDefaultSort() {
|
||||
public function testTableSortDefaultSort() {
|
||||
$this->drupalGet('database_test/tablesort_default_sort');
|
||||
|
||||
// Verify that the table was displayed. Just the header is checked for
|
||||
|
|
|
@ -14,19 +14,19 @@ class TemporaryQueryTest extends DatabaseWebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('database_test');
|
||||
public static $modules = ['database_test'];
|
||||
|
||||
/**
|
||||
* Returns the number of rows of a table.
|
||||
*/
|
||||
function countTableRows($table_name) {
|
||||
public function countTableRows($table_name) {
|
||||
return db_select($table_name)->countQuery()->execute()->fetchField();
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirms that temporary tables work and are limited to one request.
|
||||
*/
|
||||
function testTemporaryQuery() {
|
||||
public function testTemporaryQuery() {
|
||||
$this->drupalGet('database_test/db_query_temporary');
|
||||
$data = json_decode($this->getRawContent());
|
||||
if ($data) {
|
||||
|
@ -38,8 +38,8 @@ class TemporaryQueryTest extends DatabaseWebTestBase {
|
|||
}
|
||||
|
||||
// Now try to run two db_query_temporary() in the same request.
|
||||
$table_name_test = db_query_temporary('SELECT name FROM {test}', array());
|
||||
$table_name_task = db_query_temporary('SELECT pid FROM {test_task}', array());
|
||||
$table_name_test = db_query_temporary('SELECT name FROM {test}', []);
|
||||
$table_name_task = db_query_temporary('SELECT pid FROM {test_task}', []);
|
||||
|
||||
$this->assertEqual($this->countTableRows($table_name_test), $this->countTableRows('test'), 'A temporary table was created successfully in this request.');
|
||||
$this->assertEqual($this->countTableRows($table_name_task), $this->countTableRows('test_task'), 'A second temporary table was created successfully in this request.');
|
||||
|
@ -50,7 +50,7 @@ class TemporaryQueryTest extends DatabaseWebTestBase {
|
|||
-- Let's select some rows into a temporary table
|
||||
SELECT name FROM {test}
|
||||
";
|
||||
$table_name_test = db_query_temporary($sql, array());
|
||||
$table_name_test = db_query_temporary($sql, []);
|
||||
$this->assertEqual($this->countTableRows($table_name_test), $this->countTableRows('test'), 'Leading white space and comments do not interfere with temporary table creation.');
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,9 @@ use Drupal\user\RoleInterface;
|
|||
|
||||
/**
|
||||
* Provides helper methods for Entity cache tags tests.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use \Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase instead.
|
||||
*/
|
||||
abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
|
||||
|
||||
|
@ -68,18 +71,18 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
|
|||
if ($this->entity->getEntityType()->get('field_ui_base_route')) {
|
||||
// Add field, so we can modify the field storage and field entities to
|
||||
// verify that changes to those indeed clear cache tags.
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => 'configurable_field',
|
||||
'entity_type' => $this->entity->getEntityTypeId(),
|
||||
'type' => 'test_field',
|
||||
'settings' => array(),
|
||||
))->save();
|
||||
'settings' => [],
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => $this->entity->getEntityTypeId(),
|
||||
'bundle' => $this->entity->bundle(),
|
||||
'field_name' => 'configurable_field',
|
||||
'label' => 'Configurable field',
|
||||
'settings' => array(),
|
||||
'settings' => [],
|
||||
])->save();
|
||||
|
||||
// Reload the entity now that a new field has been added to it.
|
||||
|
@ -110,11 +113,11 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
|
|||
* @see \Drupal\simpletest\TestBase::getInfo()
|
||||
*/
|
||||
protected static function generateStandardizedInfo($entity_type_label, $group) {
|
||||
return array(
|
||||
return [
|
||||
'name' => "$entity_type_label entity cache tags",
|
||||
'description' => "Test the $entity_type_label entity's cache tags.",
|
||||
'group' => $group,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,7 +173,7 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
|
|||
* @see \Drupal\system\Tests\Entity\EntityCacheTagsTestBase::createEntity()
|
||||
*/
|
||||
protected function getAdditionalCacheTagsForEntity(EntityInterface $entity) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -205,7 +208,7 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
|
|||
protected function selectViewMode($entity_type) {
|
||||
$view_modes = \Drupal::entityManager()
|
||||
->getStorage('entity_view_mode')
|
||||
->loadByProperties(array('targetEntityType' => $entity_type));
|
||||
->loadByProperties(['targetEntityType' => $entity_type]);
|
||||
|
||||
if (empty($view_modes)) {
|
||||
return 'default';
|
||||
|
@ -241,46 +244,46 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
|
|||
|
||||
// Add a field of the given type to the given entity type's "foo" bundle.
|
||||
$field_name = $referenced_entity->getEntityTypeId() . '_reference';
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => $entity_type,
|
||||
'type' => 'entity_reference',
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'target_type' => $referenced_entity->getEntityTypeId(),
|
||||
),
|
||||
))->save();
|
||||
],
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => $entity_type,
|
||||
'bundle' => $bundle,
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'handler' => 'default',
|
||||
'handler_settings' => array(
|
||||
'target_bundles' => array(
|
||||
'handler_settings' => [
|
||||
'target_bundles' => [
|
||||
$referenced_entity->bundle() => $referenced_entity->bundle(),
|
||||
),
|
||||
'sort' => array('field' => '_none'),
|
||||
],
|
||||
'sort' => ['field' => '_none'],
|
||||
'auto_create' => FALSE,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
])->save();
|
||||
if (!$this->entity->getEntityType()->hasHandlerClass('view_builder')) {
|
||||
entity_get_display($entity_type, $bundle, 'full')
|
||||
->setComponent($field_name, array(
|
||||
->setComponent($field_name, [
|
||||
'type' => 'entity_reference_label',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
}
|
||||
else {
|
||||
$referenced_entity_view_mode = $this->selectViewMode($this->entity->getEntityTypeId());
|
||||
entity_get_display($entity_type, $bundle, 'full')
|
||||
->setComponent($field_name, array(
|
||||
->setComponent($field_name, [
|
||||
'type' => 'entity_reference_entity_view',
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'view_mode' => $referenced_entity_view_mode,
|
||||
),
|
||||
))
|
||||
],
|
||||
])
|
||||
->save();
|
||||
}
|
||||
|
||||
|
@ -288,28 +291,28 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
|
|||
$label_key = \Drupal::entityManager()->getDefinition($entity_type)->getKey('label');
|
||||
$referencing_entity = $this->container->get('entity_type.manager')
|
||||
->getStorage($entity_type)
|
||||
->create(array(
|
||||
->create([
|
||||
$label_key => 'Referencing ' . $entity_type,
|
||||
'status' => 1,
|
||||
'type' => $bundle,
|
||||
$field_name => array('target_id' => $referenced_entity->id()),
|
||||
));
|
||||
$field_name => ['target_id' => $referenced_entity->id()],
|
||||
]);
|
||||
$referencing_entity->save();
|
||||
|
||||
// Create an entity that does not reference the entity being tested.
|
||||
$non_referencing_entity = $this->container->get('entity_type.manager')
|
||||
->getStorage($entity_type)
|
||||
->create(array(
|
||||
->create([
|
||||
$label_key => 'Non-referencing ' . $entity_type,
|
||||
'status' => 1,
|
||||
'type' => $bundle,
|
||||
));
|
||||
]);
|
||||
$non_referencing_entity->save();
|
||||
|
||||
return array(
|
||||
return [
|
||||
$referencing_entity,
|
||||
$non_referencing_entity,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -343,14 +346,14 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
|
|||
// 'user.permissions' is a required cache context, and responses that vary
|
||||
// by this cache context when requested by anonymous users automatically
|
||||
// also get this cache tag, to ensure correct invalidation.
|
||||
$page_cache_tags = Cache::mergeTags(['rendered'], ['config:user.role.anonymous']);
|
||||
$page_cache_tags = Cache::mergeTags(['http_response', 'rendered'], ['config:user.role.anonymous']);
|
||||
// If the block module is used, the Block page display variant is used,
|
||||
// which adds the block config entity type's list cache tags.
|
||||
$page_cache_tags = Cache::mergeTags($page_cache_tags, \Drupal::moduleHandler()->moduleExists('block') ? ['config:block_list'] : []);
|
||||
|
||||
$page_cache_tags_referencing_entity = in_array('user.permissions', $this->getAccessCacheContextsForEntity($this->referencingEntity)) ? ['config:user.role.anonymous'] : [];
|
||||
|
||||
$view_cache_tag = array();
|
||||
$view_cache_tag = [];
|
||||
if ($this->entity->getEntityType()->hasHandlerClass('view_builder')) {
|
||||
$view_cache_tag = \Drupal::entityManager()->getViewBuilder($entity_type)
|
||||
->getCacheTags();
|
||||
|
@ -641,7 +644,7 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
|
|||
|
||||
// Verify cache hits.
|
||||
$referencing_entity_cache_tags = Cache::mergeTags($this->referencingEntity->getCacheTags(), \Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags());
|
||||
$referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, ['rendered']);
|
||||
$referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, ['http_response', 'rendered']);
|
||||
|
||||
$nonempty_entity_listing_cache_tags = Cache::mergeTags($this->entity->getEntityType()->getListCacheTags(), $this->getAdditionalCacheTagsForEntityListing());
|
||||
$nonempty_entity_listing_cache_tags = Cache::mergeTags($nonempty_entity_listing_cache_tags, $page_cache_tags);
|
||||
|
|
|
@ -37,6 +37,7 @@ trait EntityDefinitionTestTrait {
|
|||
$keys = $entity_type->getKeys();
|
||||
$keys['revision'] = 'revision_id';
|
||||
$entity_type->set('entity_keys', $keys);
|
||||
$entity_type->set('revision_table', 'entity_test_update_revision');
|
||||
|
||||
$this->state->set('entity_test_update.entity_type', $entity_type);
|
||||
}
|
||||
|
@ -50,6 +51,7 @@ trait EntityDefinitionTestTrait {
|
|||
$keys = $entity_type->getKeys();
|
||||
unset($keys['revision']);
|
||||
$entity_type->set('entity_keys', $keys);
|
||||
$entity_type->set('revision_table', NULL);
|
||||
|
||||
$this->state->set('entity_test_update.entity_type', $entity_type);
|
||||
}
|
||||
|
@ -86,6 +88,24 @@ trait EntityDefinitionTestTrait {
|
|||
$this->state->set('entity_test_update.entity_type', $entity_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the 'entity_test_update' entity type to revisionable and
|
||||
* translatable.
|
||||
*/
|
||||
protected function updateEntityTypeToRevisionableAndTranslatable() {
|
||||
$entity_type = clone $this->entityManager->getDefinition('entity_test_update');
|
||||
|
||||
$keys = $entity_type->getKeys();
|
||||
$keys['revision'] = 'revision_id';
|
||||
$entity_type->set('entity_keys', $keys);
|
||||
$entity_type->set('translatable', TRUE);
|
||||
$entity_type->set('data_table', 'entity_test_update_data');
|
||||
$entity_type->set('revision_table', 'entity_test_update_revision');
|
||||
$entity_type->set('revision_data_table', 'entity_test_update_revision_data');
|
||||
|
||||
$this->state->set('entity_test_update.entity_type', $entity_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new base field to the 'entity_test_update' entity type.
|
||||
*
|
||||
|
@ -202,9 +222,9 @@ trait EntityDefinitionTestTrait {
|
|||
* @see \Drupal\entity_test\EntityTestStorageSchema::getEntitySchema()
|
||||
*/
|
||||
protected function addEntityIndex() {
|
||||
$indexes = array(
|
||||
'entity_test_update__new_index' => array('name', 'user_id'),
|
||||
);
|
||||
$indexes = [
|
||||
'entity_test_update__new_index' => ['name', 'test_single_property'],
|
||||
];
|
||||
$this->state->set('entity_test_update.additional_entity_indexes', $indexes);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,11 +17,11 @@ class EntityFormTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('entity_test', 'language');
|
||||
public static $modules = ['entity_test', 'language'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$web_user = $this->drupalCreateUser(array('administer entity_test content', 'view test entity'));
|
||||
$web_user = $this->drupalCreateUser(['administer entity_test content', 'view test entity']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Add a language.
|
||||
|
@ -31,7 +31,7 @@ class EntityFormTest extends WebTestBase {
|
|||
/**
|
||||
* Tests basic form CRUD functionality.
|
||||
*/
|
||||
function testFormCRUD() {
|
||||
public function testFormCRUD() {
|
||||
// All entity variations have to have the same results.
|
||||
foreach (entity_test_entity_types() as $entity_type) {
|
||||
$this->doTestFormCRUD($entity_type);
|
||||
|
@ -53,7 +53,7 @@ class EntityFormTest extends WebTestBase {
|
|||
*
|
||||
* @see entity_test_entity_form_display_alter()
|
||||
*/
|
||||
function testEntityFormDisplayAlter() {
|
||||
public function testEntityFormDisplayAlter() {
|
||||
$this->drupalGet('entity_test/add');
|
||||
$altered_field = $this->xpath('//input[@name="field_test_text[0][value]" and @size="42"]');
|
||||
$this->assertTrue(count($altered_field) === 1, 'The altered field has the correct size value.');
|
||||
|
@ -69,28 +69,28 @@ class EntityFormTest extends WebTestBase {
|
|||
$name1 = $this->randomMachineName(8);
|
||||
$name2 = $this->randomMachineName(10);
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'name[0][value]' => $name1,
|
||||
'field_test_text[0][value]' => $this->randomMachineName(16),
|
||||
);
|
||||
];
|
||||
|
||||
$this->drupalPostForm($entity_type . '/add', $edit, t('Save'));
|
||||
$entity = $this->loadEntityByName($entity_type, $name1);
|
||||
$this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array('%entity_type' => $entity_type)));
|
||||
$this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', ['%entity_type' => $entity_type]));
|
||||
|
||||
$edit['name[0][value]'] = $name2;
|
||||
$this->drupalPostForm($entity_type . '/manage/' . $entity->id() . '/edit', $edit, t('Save'));
|
||||
$entity = $this->loadEntityByName($entity_type, $name1);
|
||||
$this->assertFalse($entity, format_string('%entity_type: The entity has been modified.', array('%entity_type' => $entity_type)));
|
||||
$this->assertFalse($entity, format_string('%entity_type: The entity has been modified.', ['%entity_type' => $entity_type]));
|
||||
$entity = $this->loadEntityByName($entity_type, $name2);
|
||||
$this->assertTrue($entity, format_string('%entity_type: Modified entity found in the database.', array('%entity_type' => $entity_type)));
|
||||
$this->assertNotEqual($entity->name->value, $name1, format_string('%entity_type: The entity name has been modified.', array('%entity_type' => $entity_type)));
|
||||
$this->assertTrue($entity, format_string('%entity_type: Modified entity found in the database.', ['%entity_type' => $entity_type]));
|
||||
$this->assertNotEqual($entity->name->value, $name1, format_string('%entity_type: The entity name has been modified.', ['%entity_type' => $entity_type]));
|
||||
|
||||
$this->drupalGet($entity_type . '/manage/' . $entity->id() . '/edit');
|
||||
$this->clickLink(t('Delete'));
|
||||
$this->drupalPostForm(NULL, array(), t('Delete'));
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
$entity = $this->loadEntityByName($entity_type, $name2);
|
||||
$this->assertFalse($entity, format_string('%entity_type: Entity not found in the database.', array('%entity_type' => $entity_type)));
|
||||
$this->assertFalse($entity, format_string('%entity_type: Entity not found in the database.', ['%entity_type' => $entity_type]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -104,33 +104,33 @@ class EntityFormTest extends WebTestBase {
|
|||
$name1_ro = $this->randomMachineName(9);
|
||||
$name2_ro = $this->randomMachineName(11);
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'name[0][value]' => $name1,
|
||||
'field_test_text[0][value]' => $this->randomMachineName(16),
|
||||
);
|
||||
];
|
||||
|
||||
$this->drupalPostForm($entity_type_id . '/add', $edit, t('Save'));
|
||||
$entity = $this->loadEntityByName($entity_type_id, $name1);
|
||||
$this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array('%entity_type' => $entity_type_id)));
|
||||
$this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', ['%entity_type' => $entity_type_id]));
|
||||
|
||||
// Add a translation to the newly created entity without using the Content
|
||||
// translation module.
|
||||
$entity->addTranslation('ro', ['name' => $name1_ro])->save();
|
||||
$translated_entity = $this->loadEntityByName($entity_type_id, $name1)->getTranslation('ro');
|
||||
$this->assertEqual($translated_entity->name->value, $name1_ro, format_string('%entity_type: The translation has been added.', array('%entity_type' => $entity_type_id)));
|
||||
$this->assertEqual($translated_entity->name->value, $name1_ro, format_string('%entity_type: The translation has been added.', ['%entity_type' => $entity_type_id]));
|
||||
|
||||
$edit['name[0][value]'] = $name2_ro;
|
||||
$this->drupalPostForm('ro/' . $entity_type_id . '/manage/' . $entity->id() . '/edit', $edit, t('Save'));
|
||||
$translated_entity = $this->loadEntityByName($entity_type_id, $name1)->getTranslation('ro');
|
||||
$this->assertTrue($translated_entity, format_string('%entity_type: Modified translation found in the database.', array('%entity_type' => $entity_type_id)));
|
||||
$this->assertEqual($translated_entity->name->value, $name2_ro, format_string('%entity_type: The name of the translation has been modified.', array('%entity_type' => $entity_type_id)));
|
||||
$this->assertTrue($translated_entity, format_string('%entity_type: Modified translation found in the database.', ['%entity_type' => $entity_type_id]));
|
||||
$this->assertEqual($translated_entity->name->value, $name2_ro, format_string('%entity_type: The name of the translation has been modified.', ['%entity_type' => $entity_type_id]));
|
||||
|
||||
$this->drupalGet('ro/' . $entity_type_id . '/manage/' . $entity->id() . '/edit');
|
||||
$this->clickLink(t('Delete'));
|
||||
$this->drupalPostForm(NULL, array(), t('Delete Romanian translation'));
|
||||
$this->drupalPostForm(NULL, [], t('Delete Romanian translation'));
|
||||
$entity = $this->loadEntityByName($entity_type_id, $name1);
|
||||
$this->assertNotNull($entity, format_string('%entity_type: The original entity still exists.', array('%entity_type' => $entity_type_id)));
|
||||
$this->assertFalse($entity->hasTranslation('ro'), format_string('%entity_type: Entity translation does not exist anymore.', array('%entity_type' => $entity_type_id)));
|
||||
$this->assertNotNull($entity, format_string('%entity_type: The original entity still exists.', ['%entity_type' => $entity_type_id]));
|
||||
$this->assertFalse($entity->hasTranslation('ro'), format_string('%entity_type: Entity translation does not exist anymore.', ['%entity_type' => $entity_type_id]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,7 +141,7 @@ class EntityFormTest extends WebTestBase {
|
|||
// correctly picked up.
|
||||
$entity_storage = $this->container->get('entity.manager')->getStorage($entity_type);
|
||||
$entity_storage->resetCache();
|
||||
$entities = $entity_storage->loadByProperties(array('name' => $name));
|
||||
$entities = $entity_storage->loadByProperties(['name' => $name]);
|
||||
return $entities ? current($entities) : NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class EntityTranslationFormTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('entity_test', 'language', 'node');
|
||||
public static $modules = ['entity_test', 'language', 'node'];
|
||||
|
||||
protected $langcodes;
|
||||
|
||||
|
@ -29,12 +29,12 @@ class EntityTranslationFormTest extends WebTestBase {
|
|||
\Drupal::state()->set('entity_test.translation', TRUE);
|
||||
|
||||
// Create test languages.
|
||||
$this->langcodes = array();
|
||||
$this->langcodes = [];
|
||||
for ($i = 0; $i < 2; ++$i) {
|
||||
$language = ConfigurableLanguage::create(array(
|
||||
$language = ConfigurableLanguage::create([
|
||||
'id' => 'l' . $i,
|
||||
'label' => $this->randomString(),
|
||||
));
|
||||
]);
|
||||
$this->langcodes[$i] = $language->id();
|
||||
$language->save();
|
||||
}
|
||||
|
@ -43,14 +43,14 @@ class EntityTranslationFormTest extends WebTestBase {
|
|||
/**
|
||||
* Tests entity form language.
|
||||
*/
|
||||
function testEntityFormLanguage() {
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||
public function testEntityFormLanguage() {
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
$web_user = $this->drupalCreateUser(array('create page content', 'edit own page content', 'administer content types'));
|
||||
$web_user = $this->drupalCreateUser(['create page content', 'edit own page content', 'administer content types']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Create a node with language LanguageInterface::LANGCODE_NOT_SPECIFIED.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['title[0][value]'] = $this->randomMachineName(8);
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalGet('node/add/page');
|
||||
|
@ -75,21 +75,21 @@ class EntityTranslationFormTest extends WebTestBase {
|
|||
|
||||
// Enable language selector.
|
||||
$this->drupalGet('admin/structure/types/manage/page');
|
||||
$edit = array('language_configuration[language_alterable]' => TRUE, 'language_configuration[langcode]' => LanguageInterface::LANGCODE_NOT_SPECIFIED);
|
||||
$edit = ['language_configuration[language_alterable]' => TRUE, 'language_configuration[langcode]' => LanguageInterface::LANGCODE_NOT_SPECIFIED];
|
||||
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
|
||||
$this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.');
|
||||
$this->assertRaw(t('The content type %type has been updated.', ['%type' => 'Basic page']), 'Basic page content type has been updated.');
|
||||
|
||||
// Create a node with language.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$langcode = $this->langcodes[0];
|
||||
$edit['title[0][value]'] = $this->randomMachineName(8);
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$edit['langcode[0][value]'] = $langcode;
|
||||
$this->drupalPostForm('node/add/page', $edit, t('Save'));
|
||||
$this->assertText(t('Basic page @title has been created.', array('@title' => $edit['title[0][value]'])), 'Basic page created.');
|
||||
$this->assertText(t('Basic page @title has been created.', ['@title' => $edit['title[0][value]']]), 'Basic page created.');
|
||||
|
||||
// Verify that the creation message contains a link to a node.
|
||||
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'node/'));
|
||||
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']);
|
||||
$this->assert(isset($view_link), 'The message area contains a link to a node');
|
||||
|
||||
// Check to make sure the node was created.
|
||||
|
|
|
@ -34,7 +34,7 @@ abstract class EntityUnitTestBase extends KernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $generatedIds = array();
|
||||
protected $generatedIds = [];
|
||||
|
||||
/**
|
||||
* The state service.
|
||||
|
@ -65,7 +65,7 @@ abstract class EntityUnitTestBase extends KernelTestBase {
|
|||
// Only check the modules, if the $modules property was not inherited.
|
||||
$rp = new \ReflectionProperty($class, 'modules');
|
||||
if ($rp->class == $class) {
|
||||
foreach (array_intersect(array('node', 'comment'), $class::$modules) as $module) {
|
||||
foreach (array_intersect(['node', 'comment'], $class::$modules) as $module) {
|
||||
$this->installEntitySchema($module);
|
||||
}
|
||||
if (in_array('forum', $class::$modules, TRUE)) {
|
||||
|
@ -82,7 +82,7 @@ abstract class EntityUnitTestBase extends KernelTestBase {
|
|||
$class = get_parent_class($class);
|
||||
}
|
||||
|
||||
$this->installConfig(array('field'));
|
||||
$this->installConfig(['field']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,13 +96,13 @@ abstract class EntityUnitTestBase extends KernelTestBase {
|
|||
* @return \Drupal\user\Entity\User
|
||||
* The created user entity.
|
||||
*/
|
||||
protected function createUser($values = array(), $permissions = array()) {
|
||||
protected function createUser($values = [], $permissions = []) {
|
||||
if ($permissions) {
|
||||
// Create a new role and apply permissions to it.
|
||||
$role = Role::create(array(
|
||||
$role = Role::create([
|
||||
'id' => strtolower($this->randomMachineName(8)),
|
||||
'label' => $this->randomMachineName(8),
|
||||
));
|
||||
]);
|
||||
$role->save();
|
||||
user_role_grant_permissions($role->id(), $permissions);
|
||||
$values['roles'][] = $role->id();
|
||||
|
@ -128,7 +128,7 @@ abstract class EntityUnitTestBase extends KernelTestBase {
|
|||
*/
|
||||
protected function reloadEntity(EntityInterface $entity) {
|
||||
$controller = $this->entityManager->getStorage($entity->getEntityTypeId());
|
||||
$controller->resetCache(array($entity->id()));
|
||||
$controller->resetCache([$entity->id()]);
|
||||
return $controller->load($entity->id());
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ abstract class EntityUnitTestBase extends KernelTestBase {
|
|||
protected function getHooksInfo() {
|
||||
$key = 'entity_test.hooks';
|
||||
$hooks = $this->state->get($key);
|
||||
$this->state->set($key, array());
|
||||
$this->state->set($key, []);
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ abstract class EntityUnitTestBase extends KernelTestBase {
|
|||
* The module to install.
|
||||
*/
|
||||
protected function installModule($module) {
|
||||
$this->enableModules(array($module));
|
||||
$this->enableModules([$module]);
|
||||
$this->refreshServices();
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ abstract class EntityUnitTestBase extends KernelTestBase {
|
|||
* The module to uninstall.
|
||||
*/
|
||||
protected function uninstallModule($module) {
|
||||
$this->disableModules(array($module));
|
||||
$this->disableModules([$module]);
|
||||
$this->refreshServices();
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ abstract class EntityWithUriCacheTagsTestBase extends EntityCacheTagsTestBase {
|
|||
}
|
||||
$expected_cache_tags = Cache::mergeTags($cache_tag, $view_cache_tag);
|
||||
$expected_cache_tags = Cache::mergeTags($expected_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity));
|
||||
$expected_cache_tags = Cache::mergeTags($expected_cache_tags, array($render_cache_tag));
|
||||
$expected_cache_tags = Cache::mergeTags($expected_cache_tags, [$render_cache_tag]);
|
||||
$this->verifyRenderCache($cid, $expected_cache_tags, $redirected_cid);
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ class UpdateApiEntityDefinitionUpdateTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that entity updates are correctly reported in the status report page.
|
||||
*/
|
||||
function testStatusReport() {
|
||||
public function testStatusReport() {
|
||||
// Create a test entity.
|
||||
$entity = EntityTest::create(['name' => $this->randomString(), 'user_id' => mt_rand()]);
|
||||
$entity->save();
|
||||
|
|
|
@ -17,22 +17,22 @@ class AlterTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'form_test');
|
||||
public static $modules = ['block', 'form_test'];
|
||||
|
||||
/**
|
||||
* Tests execution order of hook_form_alter() and hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function testExecutionOrder() {
|
||||
public function testExecutionOrder() {
|
||||
$this->drupalGet('form-test/alter');
|
||||
// Ensure that the order is first by module, then for a given module, the
|
||||
// id-specific one after the generic one.
|
||||
$expected = array(
|
||||
$expected = [
|
||||
'block_form_form_test_alter_form_alter() executed.',
|
||||
'form_test_form_alter() executed.',
|
||||
'form_test_form_form_test_alter_form_alter() executed.',
|
||||
'system_form_form_test_alter_form_alter() executed.',
|
||||
);
|
||||
$content = preg_replace('/\s+/', ' ', Xss::filter($this->content, array()));
|
||||
];
|
||||
$content = preg_replace('/\s+/', ' ', Xss::filter($this->content, []));
|
||||
$this->assert(strpos($content, implode(' ', $expected)) !== FALSE, 'Form alter hooks executed in the expected order.');
|
||||
}
|
||||
|
||||
|
|
|
@ -18,19 +18,19 @@ class ArbitraryRebuildTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('text', 'form_test');
|
||||
public static $modules = ['text', 'form_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Auto-create a field for testing.
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'entity_type' => 'user',
|
||||
'field_name' => 'test_multiple',
|
||||
'type' => 'text',
|
||||
'cardinality' => -1,
|
||||
'translatable' => FALSE,
|
||||
))->save();
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => 'user',
|
||||
'field_name' => 'test_multiple',
|
||||
|
@ -38,21 +38,21 @@ class ArbitraryRebuildTest extends WebTestBase {
|
|||
'label' => 'Test a multiple valued field',
|
||||
])->save();
|
||||
entity_get_form_display('user', 'user', 'register')
|
||||
->setComponent('test_multiple', array(
|
||||
->setComponent('test_multiple', [
|
||||
'type' => 'text_textfield',
|
||||
'weight' => 0,
|
||||
))
|
||||
])
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a basic rebuild with the user registration form.
|
||||
*/
|
||||
function testUserRegistrationRebuild() {
|
||||
$edit = array(
|
||||
public function testUserRegistrationRebuild() {
|
||||
$edit = [
|
||||
'name' => 'foo',
|
||||
'mail' => 'bar@example.com',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('user/register', $edit, 'Rebuild');
|
||||
$this->assertText('Form rebuilt.');
|
||||
$this->assertFieldByName('name', 'foo', 'Entered username has been kept.');
|
||||
|
@ -62,11 +62,11 @@ class ArbitraryRebuildTest extends WebTestBase {
|
|||
/**
|
||||
* Tests a rebuild caused by a multiple value field.
|
||||
*/
|
||||
function testUserRegistrationMultipleField() {
|
||||
$edit = array(
|
||||
public function testUserRegistrationMultipleField() {
|
||||
$edit = [
|
||||
'name' => 'foo',
|
||||
'mail' => 'bar@example.com',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('user/register', $edit, t('Add another item'));
|
||||
$this->assertText('Test a multiple valued field', 'Form has been rebuilt.');
|
||||
$this->assertFieldByName('name', 'foo', 'Entered username has been kept.');
|
||||
|
|
|
@ -17,16 +17,16 @@ class CheckboxTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('form_test');
|
||||
public static $modules = ['form_test'];
|
||||
|
||||
function testFormCheckbox() {
|
||||
public function testFormCheckbox() {
|
||||
// Ensure that the checked state is determined and rendered correctly for
|
||||
// tricky combinations of default and return values.
|
||||
foreach (array(FALSE, NULL, TRUE, 0, '0', '', 1, '1', 'foobar', '1foobar') as $default_value) {
|
||||
foreach ([FALSE, NULL, TRUE, 0, '0', '', 1, '1', 'foobar', '1foobar'] as $default_value) {
|
||||
// Only values that can be used for array indices are supported for
|
||||
// #return_value, with the exception of integer 0, which is not supported.
|
||||
// @see \Drupal\Core\Render\Element\Checkbox::processCheckbox().
|
||||
foreach (array('0', '', 1, '1', 'foobar', '1foobar') as $return_value) {
|
||||
foreach (['0', '', 1, '1', 'foobar', '1foobar'] as $return_value) {
|
||||
$form_array = \Drupal::formBuilder()->getForm('\Drupal\form_test\Form\FormTestCheckboxTypeJugglingForm', $default_value, $return_value);
|
||||
$form = \Drupal::service('renderer')->renderRoot($form_array);
|
||||
if ($default_value === TRUE) {
|
||||
|
@ -48,33 +48,33 @@ class CheckboxTest extends WebTestBase {
|
|||
$checked = ($default_value === '1foobar');
|
||||
}
|
||||
$checked_in_html = strpos($form, 'checked') !== FALSE;
|
||||
$message = format_string('#default_value is %default_value #return_value is %return_value.', array('%default_value' => var_export($default_value, TRUE), '%return_value' => var_export($return_value, TRUE)));
|
||||
$message = format_string('#default_value is %default_value #return_value is %return_value.', ['%default_value' => var_export($default_value, TRUE), '%return_value' => var_export($return_value, TRUE)]);
|
||||
$this->assertIdentical($checked, $checked_in_html, $message);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that $form_state->getValues() is populated correctly for a
|
||||
// checkboxes group that includes a 0-indexed array of options.
|
||||
$results = json_decode($this->drupalPostForm('form-test/checkboxes-zero/1', array(), 'Save'));
|
||||
$this->assertIdentical($results->checkbox_off, array(0, 0, 0), 'All three in checkbox_off are zeroes: off.');
|
||||
$this->assertIdentical($results->checkbox_zero_default, array('0', 0, 0), 'The first choice is on in checkbox_zero_default');
|
||||
$this->assertIdentical($results->checkbox_string_zero_default, array('0', 0, 0), 'The first choice is on in checkbox_string_zero_default');
|
||||
$edit = array('checkbox_off[0]' => '0');
|
||||
$results = json_decode($this->drupalPostForm('form-test/checkboxes-zero/1', [], 'Save'));
|
||||
$this->assertIdentical($results->checkbox_off, [0, 0, 0], 'All three in checkbox_off are zeroes: off.');
|
||||
$this->assertIdentical($results->checkbox_zero_default, ['0', 0, 0], 'The first choice is on in checkbox_zero_default');
|
||||
$this->assertIdentical($results->checkbox_string_zero_default, ['0', 0, 0], 'The first choice is on in checkbox_string_zero_default');
|
||||
$edit = ['checkbox_off[0]' => '0'];
|
||||
$results = json_decode($this->drupalPostForm('form-test/checkboxes-zero/1', $edit, 'Save'));
|
||||
$this->assertIdentical($results->checkbox_off, array('0', 0, 0), 'The first choice is on in checkbox_off but the rest is not');
|
||||
$this->assertIdentical($results->checkbox_off, ['0', 0, 0], 'The first choice is on in checkbox_off but the rest is not');
|
||||
|
||||
// Ensure that each checkbox is rendered correctly for a checkboxes group
|
||||
// that includes a 0-indexed array of options.
|
||||
$this->drupalPostForm('form-test/checkboxes-zero/0', array(), 'Save');
|
||||
$this->drupalPostForm('form-test/checkboxes-zero/0', [], 'Save');
|
||||
$checkboxes = $this->xpath('//input[@type="checkbox"]');
|
||||
|
||||
$this->assertIdentical(count($checkboxes), 9, 'Correct number of checkboxes found.');
|
||||
foreach ($checkboxes as $checkbox) {
|
||||
$checked = isset($checkbox['checked']);
|
||||
$name = (string) $checkbox['name'];
|
||||
$this->assertIdentical($checked, $name == 'checkbox_zero_default[0]' || $name == 'checkbox_string_zero_default[0]', format_string('Checkbox %name correctly checked', array('%name' => $name)));
|
||||
$this->assertIdentical($checked, $name == 'checkbox_zero_default[0]' || $name == 'checkbox_string_zero_default[0]', format_string('Checkbox %name correctly checked', ['%name' => $name]));
|
||||
}
|
||||
$edit = array('checkbox_off[0]' => '0');
|
||||
$edit = ['checkbox_off[0]' => '0'];
|
||||
$this->drupalPostForm('form-test/checkboxes-zero/0', $edit, 'Save');
|
||||
$checkboxes = $this->xpath('//input[@type="checkbox"]');
|
||||
|
||||
|
@ -82,7 +82,7 @@ class CheckboxTest extends WebTestBase {
|
|||
foreach ($checkboxes as $checkbox) {
|
||||
$checked = isset($checkbox['checked']);
|
||||
$name = (string) $checkbox['name'];
|
||||
$this->assertIdentical($checked, $name == 'checkbox_off[0]' || $name == 'checkbox_zero_default[0]' || $name == 'checkbox_string_zero_default[0]', format_string('Checkbox %name correctly checked', array('%name' => $name)));
|
||||
$this->assertIdentical($checked, $name == 'checkbox_off[0]' || $name == 'checkbox_zero_default[0]' || $name == 'checkbox_string_zero_default[0]', format_string('Checkbox %name correctly checked', ['%name' => $name]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,33 +18,33 @@ class ConfirmFormTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('form_test');
|
||||
public static $modules = ['form_test'];
|
||||
|
||||
function testConfirmForm() {
|
||||
public function testConfirmForm() {
|
||||
// Test the building of the form.
|
||||
$this->drupalGet('form-test/confirm-form');
|
||||
$site_name = $this->config('system.site')->get('name');
|
||||
$this->assertTitle(t('ConfirmFormTestForm::getQuestion(). | @site-name', array('@site-name' => $site_name)), 'The question was found as the page title.');
|
||||
$this->assertTitle(t('ConfirmFormTestForm::getQuestion(). | @site-name', ['@site-name' => $site_name]), 'The question was found as the page title.');
|
||||
$this->assertText(t('ConfirmFormTestForm::getDescription().'), 'The description was used.');
|
||||
$this->assertFieldByXPath('//input[@id="edit-submit"]', t('ConfirmFormTestForm::getConfirmText().'), 'The confirm text was used.');
|
||||
|
||||
// Test cancelling the form.
|
||||
$this->clickLink(t('ConfirmFormTestForm::getCancelText().'));
|
||||
$this->assertUrl('form-test/autocomplete', array(), "The form's cancel link was followed.");
|
||||
$this->assertUrl('form-test/autocomplete', [], "The form's cancel link was followed.");
|
||||
|
||||
// Test submitting the form.
|
||||
$this->drupalPostForm('form-test/confirm-form', NULL, t('ConfirmFormTestForm::getConfirmText().'));
|
||||
$this->assertText('The ConfirmFormTestForm::submitForm() method was used for this form.');
|
||||
$this->assertUrl('', array(), "The form's redirect was followed.");
|
||||
$this->assertUrl('', [], "The form's redirect was followed.");
|
||||
|
||||
// Test submitting the form with a destination.
|
||||
$this->drupalPostForm('form-test/confirm-form', NULL, t('ConfirmFormTestForm::getConfirmText().'), array('query' => array('destination' => 'admin/config')));
|
||||
$this->assertUrl('admin/config', array(), "The form's redirect was not followed, the destination query string was followed.");
|
||||
$this->drupalPostForm('form-test/confirm-form', NULL, t('ConfirmFormTestForm::getConfirmText().'), ['query' => ['destination' => 'admin/config']]);
|
||||
$this->assertUrl('admin/config', [], "The form's redirect was not followed, the destination query string was followed.");
|
||||
|
||||
// Test cancelling the form with a complex destination.
|
||||
$this->drupalGet('form-test/confirm-form-array-path');
|
||||
$this->clickLink(t('ConfirmFormArrayPathTestForm::getCancelText().'));
|
||||
$this->assertUrl('form-test/confirm-form', array('query' => array('destination' => 'admin/config')), "The form's complex cancel link was followed.");
|
||||
$this->assertUrl('form-test/confirm-form', ['query' => ['destination' => 'admin/config']], "The form's complex cancel link was followed.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,14 +53,14 @@ class ConfirmFormTest extends WebTestBase {
|
|||
public function testConfirmFormWithExternalDestination() {
|
||||
$this->drupalGet('form-test/confirm-form');
|
||||
$this->assertCancelLinkUrl(Url::fromRoute('form_test.route8'));
|
||||
$this->drupalGet('form-test/confirm-form', array('query' => array('destination' => 'node')));
|
||||
$this->drupalGet('form-test/confirm-form', ['query' => ['destination' => 'node']]);
|
||||
$this->assertCancelLinkUrl(Url::fromUri('internal:/node'));
|
||||
$this->drupalGet('form-test/confirm-form', array('query' => array('destination' => 'http://example.com')));
|
||||
$this->drupalGet('form-test/confirm-form', ['query' => ['destination' => 'http://example.com']]);
|
||||
$this->assertCancelLinkUrl(Url::fromRoute('form_test.route8'));
|
||||
$this->drupalGet('form-test/confirm-form', array('query' => array('destination' => '<front>')));
|
||||
$this->drupalGet('form-test/confirm-form', ['query' => ['destination' => '<front>']]);
|
||||
$this->assertCancelLinkUrl(Url::fromRoute('<front>'));
|
||||
// Other invalid destinations, should fall back to the form default.
|
||||
$this->drupalGet('form-test/confirm-form', array('query' => array('destination' => '/http://example.com')));
|
||||
$this->drupalGet('form-test/confirm-form', ['query' => ['destination' => '/http://example.com']]);
|
||||
$this->assertCancelLinkUrl(Url::fromRoute('form_test.route8'));
|
||||
}
|
||||
|
||||
|
|
|
@ -16,41 +16,41 @@ class ElementTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('form_test');
|
||||
public static $modules = ['form_test'];
|
||||
|
||||
/**
|
||||
* Tests placeholder text for elements that support placeholders.
|
||||
*/
|
||||
function testPlaceHolderText() {
|
||||
public function testPlaceHolderText() {
|
||||
$this->drupalGet('form-test/placeholder-text');
|
||||
$expected = 'placeholder-text';
|
||||
// Test to make sure non-textarea elements have the proper placeholder text.
|
||||
foreach (array('textfield', 'tel', 'url', 'password', 'email', 'number') as $type) {
|
||||
$element = $this->xpath('//input[@id=:id and @placeholder=:expected]', array(
|
||||
foreach (['textfield', 'tel', 'url', 'password', 'email', 'number'] as $type) {
|
||||
$element = $this->xpath('//input[@id=:id and @placeholder=:expected]', [
|
||||
':id' => 'edit-' . $type,
|
||||
':expected' => $expected,
|
||||
));
|
||||
$this->assertTrue(!empty($element), format_string('Placeholder text placed in @type.', array('@type' => $type)));
|
||||
]);
|
||||
$this->assertTrue(!empty($element), format_string('Placeholder text placed in @type.', ['@type' => $type]));
|
||||
}
|
||||
|
||||
// Test to make sure textarea has the proper placeholder text.
|
||||
$element = $this->xpath('//textarea[@id=:id and @placeholder=:expected]', array(
|
||||
$element = $this->xpath('//textarea[@id=:id and @placeholder=:expected]', [
|
||||
':id' => 'edit-textarea',
|
||||
':expected' => $expected,
|
||||
));
|
||||
]);
|
||||
$this->assertTrue(!empty($element), 'Placeholder text placed in textarea.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests expansion of #options for #type checkboxes and radios.
|
||||
*/
|
||||
function testOptions() {
|
||||
public function testOptions() {
|
||||
$this->drupalGet('form-test/checkboxes-radios');
|
||||
|
||||
// Verify that all options appear in their defined order.
|
||||
foreach (array('checkbox', 'radio') as $type) {
|
||||
$elements = $this->xpath('//input[@type=:type]', array(':type' => $type));
|
||||
$expected_values = array('0', 'foo', '1', 'bar', '>');
|
||||
foreach (['checkbox', 'radio'] as $type) {
|
||||
$elements = $this->xpath('//input[@type=:type]', [':type' => $type]);
|
||||
$expected_values = ['0', 'foo', '1', 'bar', '>'];
|
||||
foreach ($elements as $element) {
|
||||
$expected = array_shift($expected_values);
|
||||
$this->assertIdentical((string) $element['value'], $expected);
|
||||
|
@ -68,45 +68,45 @@ class ElementTest extends WebTestBase {
|
|||
|
||||
// Verify that all options appear in their defined order, taking a custom
|
||||
// #weight into account.
|
||||
foreach (array('checkbox', 'radio') as $type) {
|
||||
$elements = $this->xpath('//input[@type=:type]', array(':type' => $type));
|
||||
$expected_values = array('0', 'foo', 'bar', '>', '1');
|
||||
foreach (['checkbox', 'radio'] as $type) {
|
||||
$elements = $this->xpath('//input[@type=:type]', [':type' => $type]);
|
||||
$expected_values = ['0', 'foo', 'bar', '>', '1'];
|
||||
foreach ($elements as $element) {
|
||||
$expected = array_shift($expected_values);
|
||||
$this->assertIdentical((string) $element['value'], $expected);
|
||||
}
|
||||
}
|
||||
// Verify that custom #description properties are output.
|
||||
foreach (array('checkboxes', 'radios') as $type) {
|
||||
$elements = $this->xpath('//input[@id=:id]/following-sibling::div[@class=:class]', array(
|
||||
foreach (['checkboxes', 'radios'] as $type) {
|
||||
$elements = $this->xpath('//input[@id=:id]/following-sibling::div[@class=:class]', [
|
||||
':id' => 'edit-' . $type . '-foo',
|
||||
':class' => 'description',
|
||||
));
|
||||
$this->assertTrue(count($elements), format_string('Custom %type option description found.', array(
|
||||
]);
|
||||
$this->assertTrue(count($elements), format_string('Custom %type option description found.', [
|
||||
'%type' => $type,
|
||||
)));
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests wrapper ids for checkboxes and radios.
|
||||
*/
|
||||
function testWrapperIds() {
|
||||
public function testWrapperIds() {
|
||||
$this->drupalGet('form-test/checkboxes-radios');
|
||||
|
||||
// Verify that wrapper id is different from element id.
|
||||
foreach (array('checkboxes', 'radios') as $type) {
|
||||
$element_ids = $this->xpath('//div[@id=:id]', array(':id' => 'edit-' . $type));
|
||||
$wrapper_ids = $this->xpath('//fieldset[@id=:id]', array(':id' => 'edit-' . $type . '--wrapper'));
|
||||
$this->assertTrue(count($element_ids) == 1, format_string('A single element id found for type %type', array('%type' => $type)));
|
||||
$this->assertTrue(count($wrapper_ids) == 1, format_string('A single wrapper id found for type %type', array('%type' => $type)));
|
||||
foreach (['checkboxes', 'radios'] as $type) {
|
||||
$element_ids = $this->xpath('//div[@id=:id]', [':id' => 'edit-' . $type]);
|
||||
$wrapper_ids = $this->xpath('//fieldset[@id=:id]', [':id' => 'edit-' . $type . '--wrapper']);
|
||||
$this->assertTrue(count($element_ids) == 1, format_string('A single element id found for type %type', ['%type' => $type]));
|
||||
$this->assertTrue(count($wrapper_ids) == 1, format_string('A single wrapper id found for type %type', ['%type' => $type]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests button classes.
|
||||
*/
|
||||
function testButtonClasses() {
|
||||
public function testButtonClasses() {
|
||||
$this->drupalGet('form-test/button-class');
|
||||
// Just contains(@class, "button") won't do because then
|
||||
// "button--foo" would contain "button". Instead, check
|
||||
|
@ -120,7 +120,7 @@ class ElementTest extends WebTestBase {
|
|||
/**
|
||||
* Tests the #group property.
|
||||
*/
|
||||
function testGroupElements() {
|
||||
public function testGroupElements() {
|
||||
$this->drupalGet('form-test/group-details');
|
||||
$elements = $this->xpath('//div[@class="details-wrapper"]//div[@class="details-wrapper"]//label');
|
||||
$this->assertTrue(count($elements) == 1);
|
||||
|
@ -162,7 +162,7 @@ class ElementTest extends WebTestBase {
|
|||
$result = $this->xpath('//input[@id="edit-autocomplete-2" and contains(@data-autocomplete-path, "form-test/autocomplete-2/value")]');
|
||||
$this->assertEqual(count($result), 0, 'Ensure that the user does not have access to the autocompletion');
|
||||
|
||||
$user = $this->drupalCreateUser(array('access autocomplete test'));
|
||||
$user = $this->drupalCreateUser(['access autocomplete test']);
|
||||
$this->drupalLogin($user);
|
||||
$this->drupalGet('form-test/autocomplete');
|
||||
|
||||
|
|
|
@ -16,13 +16,13 @@ class ElementsLabelsTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('form_test');
|
||||
public static $modules = ['form_test'];
|
||||
|
||||
/**
|
||||
* Test form elements, labels, title attributes and required marks output
|
||||
* correctly and have the correct label option class if needed.
|
||||
*/
|
||||
function testFormLabels() {
|
||||
public function testFormLabels() {
|
||||
$this->drupalGet('form_test/form-labels');
|
||||
|
||||
// Check that the checkbox/radio processing is not interfering with
|
||||
|
@ -99,7 +99,7 @@ class ElementsLabelsTest extends WebTestBase {
|
|||
/**
|
||||
* Tests different display options for form element descriptions.
|
||||
*/
|
||||
function testFormDescriptions() {
|
||||
public function testFormDescriptions() {
|
||||
$this->drupalGet('form_test/form-descriptions');
|
||||
|
||||
// Check #description placement with #description_display='after'.
|
||||
|
@ -126,7 +126,7 @@ class ElementsLabelsTest extends WebTestBase {
|
|||
/**
|
||||
* Test forms in theme-less environments.
|
||||
*/
|
||||
function testFormsInThemeLessEnvironments() {
|
||||
public function testFormsInThemeLessEnvironments() {
|
||||
$form = $this->getFormWithLimitedProperties();
|
||||
$render_service = $this->container->get('renderer');
|
||||
// This should not throw any notices.
|
||||
|
@ -137,12 +137,12 @@ class ElementsLabelsTest extends WebTestBase {
|
|||
* Return a form with element with not all properties defined.
|
||||
*/
|
||||
protected function getFormWithLimitedProperties() {
|
||||
$form = array();
|
||||
$form = [];
|
||||
|
||||
$form['fieldset'] = array(
|
||||
$form['fieldset'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Fieldset',
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@ class ElementsTableSelectTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('form_test');
|
||||
public static $modules = ['form_test'];
|
||||
|
||||
/**
|
||||
* Test the display of checkboxes when #multiple is TRUE.
|
||||
*/
|
||||
function testMultipleTrue() {
|
||||
public function testMultipleTrue() {
|
||||
|
||||
$this->drupalGet('form_test/tableselect/multiple-true');
|
||||
|
||||
|
@ -31,37 +31,37 @@ class ElementsTableSelectTest extends WebTestBase {
|
|||
// Test for the presence of the Select all rows tableheader.
|
||||
$this->assertFieldByXPath('//th[@class="select-all"]', NULL, 'Presence of the "Select all" checkbox.');
|
||||
|
||||
$rows = array('row1', 'row2', 'row3');
|
||||
$rows = ['row1', 'row2', 'row3'];
|
||||
foreach ($rows as $row) {
|
||||
$this->assertFieldByXPath('//input[@type="checkbox"]', $row, format_string('Checkbox for value @row.', array('@row' => $row)));
|
||||
$this->assertFieldByXPath('//input[@type="checkbox"]', $row, format_string('Checkbox for value @row.', ['@row' => $row]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the presence of ajax functionality for all options.
|
||||
*/
|
||||
function testAjax() {
|
||||
$rows = array('row1', 'row2', 'row3');
|
||||
public function testAjax() {
|
||||
$rows = ['row1', 'row2', 'row3'];
|
||||
// Test checkboxes (#multiple == TRUE).
|
||||
foreach ($rows as $row) {
|
||||
$element = 'tableselect[' . $row . ']';
|
||||
$edit = array($element => TRUE);
|
||||
$edit = [$element => TRUE];
|
||||
$result = $this->drupalPostAjaxForm('form_test/tableselect/multiple-true', $edit, $element);
|
||||
$this->assertFalse(empty($result), t('Ajax triggers on checkbox for @row.', array('@row' => $row)));
|
||||
$this->assertFalse(empty($result), t('Ajax triggers on checkbox for @row.', ['@row' => $row]));
|
||||
}
|
||||
// Test radios (#multiple == FALSE).
|
||||
$element = 'tableselect';
|
||||
foreach ($rows as $row) {
|
||||
$edit = array($element => $row);
|
||||
$edit = [$element => $row];
|
||||
$result = $this->drupalPostAjaxForm('form_test/tableselect/multiple-false', $edit, $element);
|
||||
$this->assertFalse(empty($result), t('Ajax triggers on radio for @row.', array('@row' => $row)));
|
||||
$this->assertFalse(empty($result), t('Ajax triggers on radio for @row.', ['@row' => $row]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the display of radios when #multiple is FALSE.
|
||||
*/
|
||||
function testMultipleFalse() {
|
||||
public function testMultipleFalse() {
|
||||
$this->drupalGet('form_test/tableselect/multiple-false');
|
||||
|
||||
$this->assertNoText(t('Empty text.'), 'Empty text should not be displayed.');
|
||||
|
@ -69,16 +69,16 @@ class ElementsTableSelectTest extends WebTestBase {
|
|||
// Test for the absence of the Select all rows tableheader.
|
||||
$this->assertNoFieldByXPath('//th[@class="select-all"]', '', 'Absence of the "Select all" checkbox.');
|
||||
|
||||
$rows = array('row1', 'row2', 'row3');
|
||||
$rows = ['row1', 'row2', 'row3'];
|
||||
foreach ($rows as $row) {
|
||||
$this->assertFieldByXPath('//input[@type="radio"]', $row, format_string('Radio button for value @row.', array('@row' => $row)));
|
||||
$this->assertFieldByXPath('//input[@type="radio"]', $row, format_string('Radio button for value @row.', ['@row' => $row]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the display when #colspan is set.
|
||||
*/
|
||||
function testTableselectColSpan() {
|
||||
public function testTableselectColSpan() {
|
||||
$this->drupalGet('form_test/tableselect/colspan');
|
||||
|
||||
$this->assertText(t('Three'), 'Presence of the third column');
|
||||
|
@ -93,7 +93,7 @@ class ElementsTableSelectTest extends WebTestBase {
|
|||
// radio, one cell in the first column, one cell in the second column,
|
||||
// and two cells in the third column which has colspan 2.
|
||||
for ( $i = 0; $i <= 1; $i++) {
|
||||
$this->assertEqual(count($table_body[0]->tr[$i]->td), 5, format_string('There are five cells in row @row.', array('@row' => $i)));
|
||||
$this->assertEqual(count($table_body[0]->tr[$i]->td), 5, format_string('There are five cells in row @row.', ['@row' => $i]));
|
||||
}
|
||||
// The third row should have 3 cells, one for the radio, one spanning the
|
||||
// first and second column, and a third in column 3 (which has colspan 3).
|
||||
|
@ -103,7 +103,7 @@ class ElementsTableSelectTest extends WebTestBase {
|
|||
/**
|
||||
* Test the display of the #empty text when #options is an empty array.
|
||||
*/
|
||||
function testEmptyText() {
|
||||
public function testEmptyText() {
|
||||
$this->drupalGet('form_test/tableselect/empty-text');
|
||||
$this->assertText(t('Empty text.'), 'Empty text should be displayed.');
|
||||
}
|
||||
|
@ -111,10 +111,10 @@ class ElementsTableSelectTest extends WebTestBase {
|
|||
/**
|
||||
* Test the submission of single and multiple values when #multiple is TRUE.
|
||||
*/
|
||||
function testMultipleTrueSubmit() {
|
||||
public function testMultipleTrueSubmit() {
|
||||
|
||||
// Test a submission with one checkbox checked.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['tableselect[row1]'] = TRUE;
|
||||
$this->drupalPostForm('form_test/tableselect/multiple-true', $edit, 'Submit');
|
||||
|
||||
|
@ -136,7 +136,7 @@ class ElementsTableSelectTest extends WebTestBase {
|
|||
/**
|
||||
* Test submission of values when #multiple is FALSE.
|
||||
*/
|
||||
function testMultipleFalseSubmit() {
|
||||
public function testMultipleFalseSubmit() {
|
||||
$edit['tableselect'] = 'row1';
|
||||
$this->drupalPostForm('form_test/tableselect/multiple-false', $edit, 'Submit');
|
||||
$this->assertText(t('Submitted: row1'), 'Selected radio button');
|
||||
|
@ -145,7 +145,7 @@ class ElementsTableSelectTest extends WebTestBase {
|
|||
/**
|
||||
* Test the #js_select property.
|
||||
*/
|
||||
function testAdvancedSelect() {
|
||||
public function testAdvancedSelect() {
|
||||
// When #multiple = TRUE a Select all checkbox should be displayed by default.
|
||||
$this->drupalGet('form_test/tableselect/advanced-select/multiple-true-default');
|
||||
$this->assertFieldByXPath('//th[@class="select-all"]', NULL, 'Display a "Select all" checkbox by default when #multiple is TRUE.');
|
||||
|
@ -166,22 +166,22 @@ class ElementsTableSelectTest extends WebTestBase {
|
|||
/**
|
||||
* Test the whether the option checker gives an error on invalid tableselect values for checkboxes.
|
||||
*/
|
||||
function testMultipleTrueOptionchecker() {
|
||||
public function testMultipleTrueOptionchecker() {
|
||||
|
||||
list($header, $options) = _form_test_tableselect_get_data();
|
||||
|
||||
$form['tableselect'] = array(
|
||||
$form['tableselect'] = [
|
||||
'#type' => 'tableselect',
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
);
|
||||
];
|
||||
|
||||
// Test with a valid value.
|
||||
list(, , $errors) = $this->formSubmitHelper($form, array('tableselect' => array('row1' => 'row1')));
|
||||
list(, , $errors) = $this->formSubmitHelper($form, ['tableselect' => ['row1' => 'row1']]);
|
||||
$this->assertFalse(isset($errors['tableselect']), 'Option checker allows valid values for checkboxes.');
|
||||
|
||||
// Test with an invalid value.
|
||||
list(, , $errors) = $this->formSubmitHelper($form, array('tableselect' => array('non_existing_value' => 'non_existing_value')));
|
||||
list(, , $errors) = $this->formSubmitHelper($form, ['tableselect' => ['non_existing_value' => 'non_existing_value']]);
|
||||
$this->assertTrue(isset($errors['tableselect']), 'Option checker disallows invalid values for checkboxes.');
|
||||
|
||||
}
|
||||
|
@ -190,23 +190,23 @@ class ElementsTableSelectTest extends WebTestBase {
|
|||
/**
|
||||
* Test the whether the option checker gives an error on invalid tableselect values for radios.
|
||||
*/
|
||||
function testMultipleFalseOptionchecker() {
|
||||
public function testMultipleFalseOptionchecker() {
|
||||
|
||||
list($header, $options) = _form_test_tableselect_get_data();
|
||||
|
||||
$form['tableselect'] = array(
|
||||
$form['tableselect'] = [
|
||||
'#type' => 'tableselect',
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
'#multiple' => FALSE,
|
||||
);
|
||||
];
|
||||
|
||||
// Test with a valid value.
|
||||
list(, , $errors) = $this->formSubmitHelper($form, array('tableselect' => 'row1'));
|
||||
list(, , $errors) = $this->formSubmitHelper($form, ['tableselect' => 'row1']);
|
||||
$this->assertFalse(isset($errors['tableselect']), 'Option checker allows valid values for radio buttons.');
|
||||
|
||||
// Test with an invalid value.
|
||||
list(, , $errors) = $this->formSubmitHelper($form, array('tableselect' => 'non_existing_value'));
|
||||
list(, , $errors) = $this->formSubmitHelper($form, ['tableselect' => 'non_existing_value']);
|
||||
$this->assertTrue(isset($errors['tableselect']), 'Option checker disallows invalid values for radio buttons.');
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ class ElementsTableSelectTest extends WebTestBase {
|
|||
$form_id = $this->randomMachineName();
|
||||
$form_state = new FormState();
|
||||
|
||||
$form['op'] = array('#type' => 'submit', '#value' => t('Submit'));
|
||||
$form['op'] = ['#type' => 'submit', '#value' => t('Submit')];
|
||||
// The form token CSRF protection should not interfere with this test, so we
|
||||
// bypass it by setting the token to FALSE.
|
||||
$form['#token'] = FALSE;
|
||||
|
@ -252,7 +252,7 @@ class ElementsTableSelectTest extends WebTestBase {
|
|||
|
||||
// Return the processed form together with form_state and errors
|
||||
// to allow the caller lowlevel access to the form.
|
||||
return array($form, $form_state, $errors);
|
||||
return [$form, $form_state, $errors];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue