Created
October 16, 2020 14:41
-
-
Save pglatz/4f2d826909124dfddbd9ba3f79a424ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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