I thank you first for reading my question.
I want to make a query to the database and display data in a custom block in Drupal 8.
I have tried different ways without success:
<?php
namespace Drupal\mi_modulo\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Bloque que muestra una lista de productos
* @Block(
* id = "get_products",
* admin_label = @Translation("get productos")
* )
*/
class getProducts extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$db = \Drupal::database();
$data = $db->select('products','t')->fields('t')->execute();
return array(
'#theme' => 'mi_modulo',
'#descripcion' => 'Lista de productos',
'#nodos' => $data
);
}
}