Category Archives: Drupal

Objectives We want to add on a node page layout a block which uses a field from the currently rendered content (node). We want this block to be translated the same as the currently rendered entity. As a anonymous user, we want it to respect the published settings of the currently rendered entity. As an […]

The road to custom scrollbars Reminiscing. I am currently working on a website for a video game reviews project I have had with an old friend of mine (FuuDoh). Obviously, I have switched to Drupal to get a result quicker than what I would get with the PHP only solution I have been working on […]

Additional Information Instructions made on Drupal 8.5.x. Will break text align buttons in the CKEditor toolbar: Issue on Drupal.org The default behaviour of CKEditor is the following: Enter: inserts a paragraph directly in the WYSIWYG, Shift + Enter: inserts a line […]

When using Search API Page, I needed to theme the search form in the bootstrap structure. The cleanest answer I have found is to add some variables to trigger the bootstrap overrides on the search form.

This article is about the default admin_page, admin_block and admin_block_content templates which serves as the base of the content display on some system configuration pages such as the one on this image: The code

PHP

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

<?php

namespaceDrupal\your_module\Controller;

useDrupal;

useDrupal\Core\Controller\ControllerBase;

useDrupal\Core\Url;

classYourModuleControllerextendsControllerBase{

protected$database;

functioncontent(){

// Render array to return

$mainRenderArray=[];

// admin_page style (half width)

$mainRenderArray[]=[

'#theme'=>'admin_page',

'#blocks'=>[

// Array of admin_block

[

'title'=>$this->t('A block, on the left'),

'position'=>'left',

'content'=>[

'#theme'=>'admin_block_content',

'#content'=>[

[

'title'=>'Do something',

'url'=>Url::fromRoute('your_module.some.example.route'),

'description'=>$this->t('This will link to a route.')

],

[

'title'=>'Navigate to a nice blog',

'url'=>Url::fromUri('https://blog.dakwamine.fr'),

'description'=>$this->t('This will link to a URI, external in this case.')

],

[

'title'=>'Go to contents page',

'url'=>Url::fromUri('internal:/admin/content'),

'description'=>$this->t('Also works for internal URI.')

]

]

]

],

[

'title'=>$this->t('Another block, on the right'),

'position'=>'right',

'content'=>[

'#theme'=>'admin_block_content',

'#content'=>[

[

'title'=>'Another link to a route',

'url'=>Url::fromRoute('your_module.another.route'),

'description'=>$this->t('Yup.')

],

[

'title'=>'Website example link',

'url'=>Url::fromUri('https://website.example'),

'description'=>$this->t('Goes on website.example.')

],

]

]

]

],

];

// admin_block style (full width)

$mainRenderArray[]=[

'#theme'=>'admin_block',

'#block'=>[

'title'=>$this->t('Full width block'),

'content'=>[

'#theme'=>'admin_block_content',

'#content'=>[

[

'title'=>'Another link',

'url'=>Url::fromUri('internal:/admin/people'),

'description'=>$this->t('A link to the people page.')

],

[

'title'=>'Another link again',

'url'=>Url::fromUri('https://website.example'),

'description'=>$this->t('Goes on website.example.')

],

]

],

],

];

return$mainRenderArray;

}

}

Explanation If you use admin_page, you will be able to define the column in which the blocks dwell: left or […]

Introduction Delighted hook_schema is one of those methods where you are happy to have a usable documentation on the api website. It is pretty much self-explanatory and you don’t have to look for hours on third parties websites to get some usable information. 🙂 hook_schema on api.drupal.org and don’t forget to select your Drupal version! […]

Additional Information Tested to work on Drupal 8.2.x. For some reason, no_striping doesn’t work as expected in 8.2.x (it is ignored). The script which handles the render array conversion to twig ready variables is located here: core\includes\theme.inc. The twig template which renders the table on the default theme is here: core\themes\classy\templates\dataset\table.html.twig.

Instructions I will be creating a dedicated module using Drupal Console for this event subscriber. But feel free to use your own if you already have one! (don’t forget to backup) Access the drupal root folder in command line. Generate a new module:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

dakwamine@debian-drupal:/var/www/html/drupal$ drupal generate:module

Enter the new module name:

> Test Module

Enter the module machine name [test_module]:

>

Enter the module Path [/modules/custom]:

>

Enter module description [My Awesome Module]:

>

Enter package name [Custom]:

>

Enter Drupal Core version [8.x]:

>

Do you want to generate a .module file (yes/no) [yes]:

> no

Define module as feature (yes/no) [no]:

>

Do you want to add a composer.json file to your module (yes/no) [yes]:

> no

Would you like to add module dependencies (yes/no) [no]:

>

Do you confirm generation? (yes/no) [yes]:

>

Generated or updated files

Site path: /var/www/html/drupal

1 - modules/custom/test_module/test_module.info.yml

Generate the event subscriber. We will subscribe to the kernel.request event: […]

Additional Information Declare the services your class will use in the .services.yml file of your module. Unlike plugin type class service dependency injection, there is no create method to define the needed services. The __construct signature needs to respect the declared arguments from the .services.yml file. Originally made and tested on […]