l10n_server-2.x-dev/l10n_server/src/Controller/L10nServerReleasesController.php

l10n_server/src/Controller/L10nServerReleasesController.php
<?php

namespace Drupal\l10n_server\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Connection;
use Drupal\l10n_server\Entity\L10nServerProjectInterface;
use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Returns responses for L10n Server routes.
 */
class L10nServerReleasesController extends ControllerBase {

  /**
   * The database connection.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $connection;

  /**
   * The controller constructor.
   *
   * @param \Drupal\Core\Database\Connection $connection
   *   The database connection.
   */
  public function __construct(Connection $connection) {
    $this->connection = $connection;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('database')
    );
  }

  /**
   * Title callback.
   *
   * @param \Drupal\l10n_server\Entity\L10nServerProjectInterface $l10n_server_project
   *
   * @return string
   */
  public function title(L10nServerProjectInterface $l10n_server_project) {
    return $this->t('@project_name releases', [
      '@project_name' => $l10n_server_project->label()
    ]);
  }

  /**
   * Builds the response.
   *
   * @param \Drupal\l10n_server\Entity\L10nServerProjectInterface $l10n_server_project
   *
   * @return array|null
   *   A renderable array containing the view output or NULL if the build
   *   process failed.
   */
  public function build(L10nServerProjectInterface $l10n_server_project) {
    $view = Views::getView('l10n_server_releases');
    $view->setDisplay('embed_1');
    $view->setArguments([$l10n_server_project->id()]);
    $view->execute();
    return $view->render();
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc