You are here

function hook_coffee_commands in Coffee 8

Same name and namespace in other branches
  1. 7.2 coffee.api.php \hook_coffee_commands()

Extend the Coffee functionality with your own commands and items.

Here's an example of how to add content to Coffee.

2 functions implement hook_coffee_commands()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

coffee_coffee_commands in ./coffee.coffee.inc
Implements hook_coffee_commands().
coffee_test_coffee_commands in tests/modules/coffee_test/coffee_test.module
Implements hook_coffee_commands().
2 invocations of hook_coffee_commands()
CoffeeCommandsTest::testHookCoffeeCommands in tests/src/Kernel/CoffeeCommandsTest.php
Tests hook_coffee_commands().
CoffeeController::coffeeData in src/Controller/CoffeeController.php
Outputs the data that is used for the Coffee autocompletion in JSON.

File

./coffee.api.php, line 21
Hooks provided by Coffee module.

Code

function hook_coffee_commands() {
  $commands = [];

  // Basic example, for 1 result.
  $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')) {
    $view
      ->setDisplay();
    $view
      ->preExecute();
    $view
      ->execute();
    foreach ($view->result as $row) {
      $entity = $row->_entity;
      $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(),
      ];
    }
  }
  return $commands;
}