Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
namespace Drupal\products\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\products\products;
use Drupal\Core\Render\Markup;
/**
* Provides route responses for the products module.
*/
class ProductsController extends ControllerBase {
protected $prod;
public function __construct() {
$this->prod = new products;
}
/**
* Returns a info page listing all products.
*
* @return array
* A simple renderable array.
*/
public function listProducts() {
$this->products = $this->prod->getProducts();
if ($this->products->statusCode != 200) {
// error
$output = '> no product found';
}
else {
$output = '<h2>List of Registered Products</h2>';
$rows = [
[Markup::create('<strong>test 1</strong>'),'test'],
[Markup::create('<s>test 2</s>'), 'test'],
[Markup::create('<div>test 3</div>'), 'test'],
];
$header = [
'title' => t('Title'),
'content' => t('Content'),
];
$build['table'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No content has been found.'),
];
$output .= render($build);
}
$element = array(
'#markup' => $build,
);
return $build;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment