Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / block_content / tests / modules / block_content_test / block_content_test.module
1 <?php
2
3 /**
4  * @file
5  * A dummy module for testing custom block related hooks.
6  *
7  * This is a dummy module that implements custom block related hooks to test API
8  * interaction with the block_content module.
9  */
10
11 use Drupal\block_content\Entity\BlockContent;
12
13 /**
14  * Implements hook_block_content_view().
15  */
16 function block_content_test_block_content_view(array &$build, BlockContent $block_content, $view_mode) {
17   // Add extra content.
18   $build['extra_content'] = [
19     '#markup' => '<blink>Yowser</blink>',
20   ];
21 }
22
23 /**
24  * Implements hook_block_content_presave().
25  */
26 function block_content_test_block_content_presave(BlockContent $block_content) {
27   if ($block_content->label() == 'testing_block_content_presave') {
28     $block_content->setInfo($block_content->label() . '_presave');
29   }
30   // Determine changes.
31   if (!empty($block_content->original) && $block_content->original->label() == 'test_changes') {
32     if ($block_content->original->label() != $block_content->label()) {
33       $block_content->setInfo($block_content->label() . '_presave');
34       // Drupal 1.0 release.
35       $block_content->changed = 979534800;
36     }
37   }
38 }
39
40 /**
41  * Implements hook_block_content_update().
42  */
43 function block_content_test_block_content_update(BlockContent $block_content) {
44   // Determine changes on update.
45   if (!empty($block_content->original) && $block_content->original->label() == 'test_changes') {
46     if ($block_content->original->label() != $block_content->label()) {
47       $block_content->setInfo($block_content->label() . '_update');
48     }
49   }
50 }
51
52 /**
53  * Implements hook_block_content_insert().
54  *
55  * This tests saving a block_content on block_content insert.
56  *
57  * @see \Drupal\block_content\Tests\BlockContentSaveTest::testBlockContentSaveOnInsert()
58  */
59 function block_content_test_block_content_insert(BlockContent $block_content) {
60   // Set the block_content title to the block_content ID and save.
61   if ($block_content->label() == 'new') {
62     $block_content->setInfo('BlockContent ' . $block_content->id());
63     $block_content->setNewRevision(FALSE);
64     $block_content->save();
65   }
66   if ($block_content->label() == 'fail_creation') {
67     throw new Exception('Test exception for rollback.');
68   }
69 }