Created
July 21, 2021 11:32
-
-
Save d0t15t/92f2a799c74c1fb42ecf709e5d011c9d to your computer and use it in GitHub Desktop.
This file contains hidden or 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\test_module\Plugin\Block; | |
use Drupal\Core\Block\BlockBase; | |
/** | |
* Provides a 'Test block' Block. | |
* | |
* @Block( | |
* id = "test_block", | |
* admin_label = @Translation("Test block"), | |
* category = @Translation("Test block"), | |
* ) | |
* | |
* Drupal Cache Contexti | |
* https://www.drupal.org/docs/8/api/cache-api/cache-contexts | |
*/ | |
class TestBlock extends BlockBase { | |
public function build() { | |
$node = \Drupal\node\Entity\Node::load(1); | |
$node_title = $node->getTitle(); | |
return [ | |
'#markup' => $this->t('The title of node #1 is: ') . $node_title, | |
'#cache' => [ | |
'contexts' => [ | |
'url.path', | |
], | |
], | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment