Build a custom block in Drupal 8
Saturday, June 16, 2018 - 07:05
The code in this example is placed in /src/Plugin/Block/DemoBlock.php file in a module called Dribbit.
<?php
/**
* Created by PhpStorm.
* User: Dribbit
* Date: 16/06/18
* Time: 07:06
*/
namespace Drupal\dribbit\Plugin\Block;
use \Drupal\Core\Block\BlockBase;
/**
* Provides a demmo block.
*
* @Block(
* id = "dribbit_demo_block",
* admin_label = @Translation("Dribbit demo block"),
* category = @Translation("Dribbit")
* )
*/
class DemoBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
return [
'#markup' => 'Hello world'
];
}
}