Skip to content

Instantly share code, notes, and snippets.

@pglatz
Created October 16, 2020 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pglatz/4f2d826909124dfddbd9ba3f79a424ba to your computer and use it in GitHub Desktop.
Save pglatz/4f2d826909124dfddbd9ba3f79a424ba to your computer and use it in GitHub Desktop.
<?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