Commit a758d229 authored by Salvador Molina's avatar Salvador Molina

Issue #2875701 by Munavijayalakshmi, slv_, dhruveshdtripathi: Convert module...

Issue #2875701 by Munavijayalakshmi, slv_, dhruveshdtripathi: Convert module to use short array syntax (new coding standard)
parent 5bd7d2a4
......@@ -61,10 +61,10 @@ class UserHomepageResetButtonForm extends FormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['submit'] = array(
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Unset configured homepage'),
);
];
return $form;
}
......@@ -74,10 +74,10 @@ class UserHomepageResetButtonForm extends FormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
// Set the custom path for the user to none on the user_homepage table.
if ($this->userHomepageManager->unsetUserHomepage($this->account->id())) {
drupal_set_message($this->t('Your homepage was unset successfully.'));
$this->messenger()->addMessage($this->t('Your homepage was unset successfully.'));
}
else {
drupal_set_message($this->t('Your homepage could not be unset. Try again later.'));
$this->messenger()->addError($this->t('Your homepage could not be unset. Try again later.'));
}
}
......
......@@ -61,10 +61,10 @@ class UserHomepageSaveButtonForm extends FormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['submit'] = array(
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save as homepage'),
);
];
return $form;
}
......@@ -77,10 +77,10 @@ class UserHomepageSaveButtonForm extends FormBase {
// Create or Update entry for the user on the user_homepage table.
if ($this->userHomepageManager->setUserHomepage($this->account->id(), $homepage_path)) {
drupal_set_message($this->t('Page saved successfully as homepage.'));
$this->messenger()->addMessage($this->t('Page saved successfully as homepage.'));
}
else {
drupal_set_message($this->t("Page could not be saved as homepage. Try again later.", 'error'));
$this->messenger()->addError($this->t("Page could not be saved as homepage. Try again later."));
}
}
......
......@@ -20,7 +20,7 @@ class UserHomepageResetButtonBlock extends BlockBase {
* {@inheritdoc}
*/
public function build() {
$build = array();
$build = [];
if (Drupal::currentUser()->hasPermission('configure own homepage')) {
$userHomepageManager = Drupal::service('user_homepage.manager');
$userHomepage = $userHomepageManager->getUserHomepage(Drupal::currentUser()->id());
......
......@@ -24,10 +24,10 @@ class UserHomepageSaveButtonBlock extends BlockBase {
$userHomepageManager = Drupal::service('user_homepage.manager');
if ($userHomepageManager->buildHomepagePathFromCurrentRequest() === $userHomepageManager->getUserHomepage(Drupal::currentUser()->id())) {
$build['current_homepage_text'] = array(
$build['current_homepage_text'] = [
'#type' => 'processed_text',
'#text' => $this->t('This is your homepage.'),
);
];
}
else {
$formBuilder = Drupal::formBuilder();
......
......@@ -55,7 +55,7 @@ class UserHomepageManager implements UserHomepageManagerInterface {
* {@inheritdoc}
*/
public function getUserHomepage($uid) {
$args = array(':uid' => $uid);
$args = [':uid' => $uid];
$query = $this->connection->query("SELECT path FROM {user_homepage} WHERE uid = :uid", $args);
$homepage_path = $query->fetchField() ?: NULL;
return $homepage_path;
......@@ -69,17 +69,17 @@ class UserHomepageManager implements UserHomepageManagerInterface {
// A merge operation tackles the Insert or Update action, as appropriate.
$merge_query = $this->connection->merge('user_homepage');
$merge_result = $merge_query
->key(array('uid' => $uid))
->fields(array(
->key(['uid' => $uid])
->fields([
'uid' => $uid,
'path' => $path,
))
])
->execute();
}
catch (Exception $e) {
return FALSE;
}
return (in_array($merge_result, array($merge_query::STATUS_INSERT, $merge_query::STATUS_UPDATE)));
return (in_array($merge_result, [$merge_query::STATUS_INSERT, $merge_query::STATUS_UPDATE]));
}
/**
......@@ -103,10 +103,10 @@ class UserHomepageManager implements UserHomepageManagerInterface {
public function buildHomepagePathFromCurrentRequest() {
// Set options for the internal url of the current path. 'alias' is set to
// TRUE to prevent the Url class from transforming the path into its alias.
$options = array(
$options = [
'query' => $this->requestStack->getCurrentRequest()->query->all(),
'alias' => TRUE,
);
];
$homepage_url = Url::fromUri('internal:' . $this->currentPathStack->getPath(), $options)->toString();
return $homepage_url;
......@@ -118,7 +118,7 @@ class UserHomepageManager implements UserHomepageManagerInterface {
public function resolveUserRedirection(AccountInterface $account) {
if ($homepage = $this->getUserHomepage($account->id())) {
$parsed_homepage = parse_url($homepage);
$options = array();
$options = [];
if (isset($parsed_homepage['query'])) {
parse_str($parsed_homepage['query'], $options['query']);
}
......
......@@ -40,7 +40,7 @@ class UserHomepageResetHomepageTest extends BrowserTestBase {
Drupal::database()
->merge('user_homepage')
->key('uid', $this->user->id())
->fields(array('uid' => $this->user->id(), 'path' => '/node'))
->fields(['uid' => $this->user->id(), 'path' => '/node'])
->execute();
// Add the 'reset' homepage button to a theme region.
......
......@@ -84,16 +84,16 @@ class UserHomepageSaveHomepageTest extends BrowserTestBase {
$this->drupalLogout();
}
$this->drupalGet('user/login', array('query' => array('destination' => $destination)));
$this->drupalGet('user/login', ['query' => ['destination' => $destination]]);
$this->assertSession()->statusCodeEquals(200);
$this->submitForm(array(
'name' => $account->getUsername(),
$this->submitForm([
'name' => $account->getDisplayName(),
'pass' => $account->passRaw,
), t('Log in'));
], t('Log in'));
// @see BrowserTestBase::drupalUserIsLoggedIn()
$account->sessionId = $this->getSession()->getCookie($this->getSessionName());
$this->assertTrue($this->drupalUserIsLoggedIn($account), new FormattableMarkup('User %name successfully logged in.', array('name' => $account->getAccountName())));
$this->assertTrue($this->drupalUserIsLoggedIn($account), new FormattableMarkup('User %name successfully logged in.', ['name' => $account->getAccountName()]));
$this->loggedInUser = $account;
$this->container->get('current_user')->setAccount($account);
......
......@@ -45,7 +45,7 @@ class UserHomepageManagerTest extends KernelTestBase {
// Ensure null is returned if there is no homepage set.
$this->assertNull($this->userHomepageManager->getUserHomepage(2));
Drupal::database()->insert('user_homepage')->fields(array('uid' => 2, 'path' => '/test?param=param'))->execute();
Drupal::database()->insert('user_homepage')->fields(['uid' => 2, 'path' => '/test?param=param'])->execute();
$this->assertEquals('/test?param=param', $this->userHomepageManager->getUserHomepage(2));
}
......@@ -64,7 +64,7 @@ class UserHomepageManagerTest extends KernelTestBase {
$this->assertEquals('/new-path', $actual);
// Ensure FALSE is returned when a problem / Exception occurs.
$wrong_args_format = array('wrong', 'arguments', 'format');
$wrong_args_format = ['wrong', 'arguments', 'format'];
$this->assertFalse($this->userHomepageManager->setUserHomepage($wrong_args_format, '/path?'));
}
......@@ -98,7 +98,7 @@ class UserHomepageManagerTest extends KernelTestBase {
* Tests user redirect after login is resolved correctly.
*/
public function testResolveUserRedirection() {
$account = new UserSession(array('uid' => 1));
$account = new UserSession(['uid' => 1]);
// Check no redirection is done if user doesn't have a homepage.
$this->assertFalse($this->userHomepageManager->resolveUserRedirection($account));
......
......@@ -9,24 +9,24 @@
* Implements hook_schema().
*/
function user_homepage_schema() {
$schema['user_homepage'] = array(
$schema['user_homepage'] = [
'description' => "Stores custom homepages of site users.",
'fields' => array(
'uid' => array(
'fields' => [
'uid' => [
'description' => 'The User ID for which a custom homepage is stored.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'path' => array(
],
'path' => [
'description' => 'The internal path stored as homepage.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
'primary key' => array('uid'),
);
],
],
'primary key' => ['uid'],
];
return $schema;
}
......@@ -28,20 +28,20 @@ function user_homepage_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Help page for the user_homepage module.
case 'help.page.user_homepage':
$link_options = array(
'attributes' => array('target' => '_blank'),
$link_options = [
'attributes' => ['target' => '_blank'],
'fragment' => 'module-user_homepage',
);
];
$user_homepage_permission = Link::createFromRoute(t('Configure own homepage'), 'user.admin_permissions', array(), $link_options)->toString();
$user_homepage_permission = Link::createFromRoute(t('Configure own homepage'), 'user.admin_permissions', [], $link_options)->toString();
$help_text = '<p>' . t("The User Homepage module lets users with the
\"!user_homepage_permission'\" permission choose a specific page of the
site as their homepage. Users with a homepage will be redirected to this
page upon successful login on the site.",
array(
[
'!user_homepage_permission' => $user_homepage_permission,
)) . '</p>';
]) . '</p>';
$help_text .= '<p>' . t("The module provides two blocks. One of them
allows users to save the current page as their homepage, and the other
allows them to reset their homepage so that they are no longer
......@@ -53,9 +53,9 @@ function user_homepage_help($route_name, RouteMatchInterface $route_match) {
$block_layout_page = Link::createFromRoute(t('Block layout'), 'block.admin_display')->toString();
$help_text .= t('The blocks can be configured and placed in any theme
region from the !block_layout_page page.',
array(
[
'!block_layout_page' => $block_layout_page,
));
]);
return $help_text;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment