Skip to content
Snippets Groups Projects
Commit 8f6a4ee2 authored by Pavan B S's avatar Pavan B S Committed by Michael Mol
Browse files

Issue #2860089 by Pavan B S: Convert module to use short array syntax (new coding standard)

parent 7e8c5c8b
No related branches found
No related tags found
2 merge requests!14Draft: Automated Project Update Bot fixes,!1Change the label class to be sr-only
......@@ -19,15 +19,15 @@ use Drupal\views\Views;
* Here's an example of how to add content to Coffee.
*/
function hook_coffee_commands() {
$commands = array();
$commands = [];
// Basic example, for 1 result.
$commands[] = array(
$commands[] = [
'value' => Url::fromRoute('my.simple.route')->toString(),
'label' => 'Simple',
// Every result should include a command.
'command' => ':simple',
);
];
// More advanced example to include view results.
if ($view = Views::getView('frontpage')) {
......@@ -37,13 +37,13 @@ function hook_coffee_commands() {
foreach ($view->result as $row) {
$entity = $row->_entity;
$commands[] = array(
$commands[] = [
'value' => $entity->toUrl()->toString(),
'label' => 'Pub: ' . $entity->label(),
// You can also specify commands that if the user enters, this command
// should show.
'command' => ':x ' . $entity->label(),
);
];
}
}
......
......@@ -11,14 +11,14 @@ use Drupal\Core\Url;
* Implements hook_coffee_commands().
*/
function coffee_coffee_commands() {
$commands = array();
$commands = [];
// Add in a link for the front page.
$commands[] = array(
$commands[] = [
'value' => Url::fromRoute('<front>')->toString(),
'label' => t('Go to front page'),
'command' => ':front',
);
];
// The command is ":add" and includes the link_title to empower the
// autocompletion.
......@@ -28,11 +28,11 @@ function coffee_coffee_commands() {
foreach ($entity_manager->getStorage('node_type')->loadMultiple() as $type) {
$node_type = $type->id();
if ($entity_manager->getAccessControlHandler('node')->createAccess($node_type)) {
$commands[] = array(
$commands[] = [
'value' => Url::fromRoute('node.add', ['node_type' => $node_type])->toString(),
'label' => $type->label(),
'command' => $command . ' ' . $type->label(),
);
];
}
}
......
......@@ -16,13 +16,13 @@ function coffee_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.coffee':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Coffee module offers quick navigation functionality as well as an extensible set of commands to let you jump around your site to desired pages very fast. The functionality is inspired by Alfred and Spotlight on Mac OS X. To activate the feature, either press the Coffee button in the toolbar or use the Alt-D keyboard shortcut (Alt + Shift + D in Opera, Alt + Ctrl + D in Windows Internet Explorer). For more information, see the <a href=":coffee">online documentation for the Coffee module</a>.', array(':coffee' => 'https://www.drupal.org/documentation/modules/coffee')) . '</p>';
$output .= '<p>' . t('The Coffee module offers quick navigation functionality as well as an extensible set of commands to let you jump around your site to desired pages very fast. The functionality is inspired by Alfred and Spotlight on Mac OS X. To activate the feature, either press the Coffee button in the toolbar or use the Alt-D keyboard shortcut (Alt + Shift + D in Opera, Alt + Ctrl + D in Windows Internet Explorer). For more information, see the <a href=":coffee">online documentation for the Coffee module</a>.', [':coffee' => 'https://www.drupal.org/documentation/modules/coffee']) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Jumping to pages in the administration menu') . '</dt>';
$output .= '<dd>' . t('Start typing either part of the path or the title of an administration page you want to jump to. If the first result is the one you were looking for, just hit enter. If not, either continue typing or pick the right result from the list. You can also use your keyboard cursor keys to pick the desired result.') . '</dd>';
$output .= '<dt>' . t('Configuring additional menus and number of results') . '</dt>';
$output .= '<dd>' . t('Coffee only searches in the administration menu by default. You can configure support for any other menu on <a href=":admin-coffee">the Coffee configuration page</a>. It is also possible to set the number of displayed results to less or more than the default 7.', array(':admin-coffee' => Url::fromRoute('coffee.configuration')->toString())) . '</dd>';
$output .= '<dd>' . t('Coffee only searches in the administration menu by default. You can configure support for any other menu on <a href=":admin-coffee">the Coffee configuration page</a>. It is also possible to set the number of displayed results to less or more than the default 7.', [':admin-coffee' => Url::fromRoute('coffee.configuration')->toString()]) . '</dd>';
$output .= '<dt>' . t('Additional commands') . '</dt>';
$output .= '<dd>' . t('Coffee also supports an extensible set of commands. The two built-in commands are <code>:front</code> which results in the front page and <code>:add</code> which provides a list of all content types to create new content with. The <code>:add</code> command may receive the name of the content type as well, therefore <code>:add:Article</code> also works. Other modules may provide further commands.') . '</dd>';
$output .= '<dt>' . t('Permissions') . '</dt>';
......@@ -52,11 +52,11 @@ function coffee_page_attachments(array &$attachments) {
* Implements hook_hook_info().
*/
function coffee_hook_info() {
$hooks = array(
'coffee_commands' => array(
$hooks = [
'coffee_commands' => [
'group' => 'coffee',
),
);
],
];
return $hooks;
}
......
......@@ -83,7 +83,7 @@ class CoffeeController extends ControllerBase {
* The json response.
*/
public function coffeeData() {
$output = array();
$output = [];
foreach ($this->config->get('coffee_menus') as $menu_name) {
$tree = $this->getMenuTreeElements($menu_name);
......@@ -92,21 +92,21 @@ class CoffeeController extends ControllerBase {
foreach ($tree as $tree_element) {
$link = $tree_element->link;
$output[$link->getRouteName()] = array(
$output[$link->getRouteName()] = [
'value' => $link->getUrlObject()->toString(),
'label' => $link->getTitle(),
'command' => $commands_group,
);
];
$tasks = $this->getLocalTasksForRoute($link->getRouteName(), $link->getRouteParameters());
foreach ($tasks as $route_name => $task) {
if (empty($output[$route_name])) {
$output[$route_name] = array(
$output[$route_name] = [
'value' => $task['url']->toString(),
'label' => $link->getTitle() . ' - ' . $task['title'],
'command' => NULL,
);
];
}
}
}
......@@ -178,7 +178,7 @@ class CoffeeController extends ControllerBase {
* - localized_options: the localized options for the local task.
*/
protected function getLocalTasksForRoute($route_name, array $route_parameters) {
$links = array();
$links = [];
$tree = $this->localTaskManager->getLocalTasksForRoute($route_name);
$route_match = \Drupal::routeMatch();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment