You are here

class CommonTestController in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php \Drupal\common_test\Controller\CommonTestController

Controller routines for common_test routes.

Hierarchy

Expanded class hierarchy of CommonTestController

File

core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php, line 17
Contains \Drupal\common_test\Controller\CommonTestController.

Namespace

Drupal\common_test\Controller
View source
class CommonTestController {

  /**
   * Returns links to the current page, with and without query strings.
   *
   * Using #type 'link' causes these links to be rendered with the link
   * generator.
   */
  public function typeLinkActiveClass() {
    return array(
      'no_query' => array(
        '#type' => 'link',
        '#title' => t('Link with no query string'),
        '#url' => Url::fromRoute('<current>'),
        '#options' => array(
          'set_active_class' => TRUE,
        ),
      ),
      'with_query' => array(
        '#type' => 'link',
        '#title' => t('Link with a query string'),
        '#url' => Url::fromRoute('<current>'),
        '#options' => array(
          'query' => array(
            'foo' => 'bar',
            'one' => 'two',
          ),
          'set_active_class' => TRUE,
        ),
      ),
      'with_query_reversed' => array(
        '#type' => 'link',
        '#title' => t('Link with the same query string in reverse order'),
        '#url' => Url::fromRoute('<current>'),
        '#options' => array(
          'query' => array(
            'one' => 'two',
            'foo' => 'bar',
          ),
          'set_active_class' => TRUE,
        ),
      ),
    );
  }

  /**
   * Adds a JavaScript file and a CSS file with a query string appended.
   *
   * @return string
   *   An empty string.
   */
  public function jsAndCssQuerystring() {
    $attached = array(
      '#attached' => array(
        'library' => array(
          'node/drupal.node',
        ),
        'css' => array(
          drupal_get_path('module', 'node') . '/css/node.admin.css' => array(),
          // A relative URI may have a query string.
          '/' . drupal_get_path('module', 'node') . '/node-fake.css?arg1=value1&arg2=value2' => array(),
        ),
      ),
    );
    return \Drupal::service('renderer')
      ->renderRoot($attached);
  }

  /**
   * Prints a destination query parameter.
   *
   * @return \Symfony\Component\HttpFoundation\Response
   *   A new Response object containing a string with the destination query
   *   parameter.
   */
  public function destination() {
    $destination = \Drupal::destination()
      ->getAsArray();
    $output = "The destination: " . Html::escape($destination['destination']);
    return new Response($output);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommonTestController::destination public function Prints a destination query parameter.
CommonTestController::jsAndCssQuerystring public function Adds a JavaScript file and a CSS file with a query string appended.
CommonTestController::typeLinkActiveClass public function Returns links to the current page, with and without query strings.