forked from legaudinier/Custom-Module-Presentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1527 lines (1432 loc) · 60.3 KB
/
index.html
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html>
<img src="images/Hook42Logo.png" style="margin: 2rem; height: 7%; position: absolute;" />
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Custom Modules</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/hook42.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section class="present" style="top: 226px; display: block;">
<h1 class="text__dark text__bold">
Drupal 8 Custom Module Architecture </h1>
<h3>What’s Going On? </h3>
<a href="https://github.com/legaudinier/custom-module-capable" style="font-size: 20px;">Capable Module: https://github.com/legaudinier/custom-module-capable</a>
<p>Lindsay Gaudinier at Hook 42</p>
</section>
<section>
<h3>About me</h3>
<ul>
<li class="fragment">Developer at Hook 42</li>
<li class="fragment">Swimming, cats, and the internet</li>
</ul>
<div>
<img src="images/dude.jpg" class="fragment" style="width: 450px;">
</div>
</section>
<section>
<h3>The Thought Behind the Talk</h3>
<span class="font-25">
<p class="fragment"> I had to create a custom module for the first time, and I had only modified code in the past</p>
<div class="fragment ol-image">
<img src="images/noideawhatsgoingon.gif" />
</div>
<p class="fragment">I didn't want to just know <em>how</em> to make a custom module, I wanted to know the answers to all my <em>why</em> questions</p>
</span>
</section>
<section>
<h3>Quick note: sometimes words are mentioned before they are defined. Please have patience.</h3>
</section>
<section>
<h3>Do you need a custom module?</h3>
<ul class="font-25">
<li class="fragment">5,500 + Drupal 8 contrib modules with security updates and help from the Drupal universe</li>
<li class="fragment">Might have a unique problem that contrib doesn't solve</li>
<li class="fragment">Contrib module might be too bulky and hurt site performance</li>
<li class="fragment">Bring in the functionality of many contrib modules into one custom module</li>
</ul>
</section>
<section>
<h3>We can't just start with the list of files</h3>
<span class="fragment">
<p>Nothing is ever that easy.</p>
<img src="images/crying.gif" />
</span>
</section>
<section>
<h3>PSR-4: Improved Autoloading</h3>
<ul class="font-25">
<li class="fragment">PSR stands for PHP Standard Recommendation</li>
<li class="fragment">PSR is a PHP specification that is published by the <a href="https://www.php-fig.org/">PHP Framework Interop Group (php-fig)</a> who's focus is to move "PHP foward through collaboration and standards"</li>
<li class="fragment">Drupal 8 implements the PSR-4 standard for namespaces and autoloading</li>
<li class="fragment"><a href="https://www.php-fig.org/psr/psr-4/">PSR-4</a>: "Autoloaders remove the complexity of including files by mapping namespaces to file system paths."</li>
</ul>
<img class="fragment" src="images/confused.gif" />
</section>
<section>
<h3>Autoloading</h3>
<ul>
<li class="fragment">Autoloading is the capability of loading and linking portions of a program automatically when needed. The autoloader searches through a path of directories and finds the code that defines the subroutine (method/function).</li>
<li class="fragment">Autoloading means your code does not need to include a long list of source files in your php file</li>
<li class="fragment">The magic of autoloading works because of namespacing</li>
</ul>
</section>
<section>
<h3>Namespacing</h3>
<ul>
<li class="fragment">"Namespaces are commonly structured as hierarchies to allow reuse of names in different contexts." - <a href="https://en.wikipedia.org/wiki/Namespace">Wikipedia</a></li>
<li class="fragment">Namespacing helps you avoid name collisions if you repeat the name for a function/class that was declared before</li>
<li class="fragment">Eliminates need for super long class names, points to where in the code you can find the function source</li>
</ul>
</section>
<section>
<h3>Composer</h3>
<ul>
<li class="fragment">
Dependency/package manager: software the automates the process of installing, upgrading, configuring and removing software.
</li>
<li class="fragment">
Composer is a dependency manager for PHP, that assists with locating, downloading, validating, and loading packages and ensures you have the correct package version
</li>
</ul>
</section>
<section>
<h3> Symfony</h3>
<ul>
<li class="fragment">Symfony is a PHP framework and a set of reuasable PHP components and libraries</li>
<li class="fragment">Defined as a MVC (Model, View, and Controller) framework</li>
<li class="fragment">Components are standalone PHP libraries that generate specific features</li>
</ul>
</section>
<section>
<h3>Some Symfony Components</h3>
<ul class="font-20">
<li><strong>ClassLoader:</strong> provides tools to autoload classes and cache their locations for performance</li>
<li><strong>Console:</strong> helps you create command line interfaces</li>
<li><strong>CssSelector:</strong> converts CSS selectors to XPath (XML Path language) expression</li>
<li><strong>DependencyInjection:</strong> lets you standardize and centralize the way objects are constructed</li>
<li><strong>EventDispatcher:</strong> lets components communicate with each other</li>
<li><strong>HttpFoundation:</strong> defined an object-oriented layer for the HTTP specification</li>
<li><strong>HttpKernel:</strong> converts a HTTP Request into a HTTP Respose by using a EventDispatcher component</li>
<li><strong>Process:</strong> executes commands in subprocesses, creates API for shell executions</li>
<li><strong>Routing:</strong> maps an HTTP request to a set of configurable variables</li>
<li><strong>Serializer:</strong> turn objects into specific formats (YAML) and specific formats into objects</li>
<li><strong>Translation:</strong> provides tools for internationalization</li>
<li><strong>Validator:</strong> validates following <a href="https://jcp.org/en/jsr/detail?id=303">JSR 303: Bean Validation</a></li>
<li><strong>Yaml:</strong> parses YAML strings to conver them to PHP arrays, and vice versa</li>
</ul>
</section>
<section>
<h3>Why are you telling me this?</h3>
<img src="images/why.gif" />
<ul class="font-25">
<li class="fragment">
Autoloading and namespacing play an important role in how and why we structure files and code in a module
</li>
<li class="fragment">
While Drupal Core uses Composer, you can also manage dependencies for your custom module with Composer
</li>
<li class="fragment">
While Drupal 8 does NOT use the Symfony framework, D8 uses some Symfony components
</li>
</ul>
</section>
<section>
<h3>Types of files:</h3>
<ul>
<li class="fragment">YAML (YAML Ain't Markup Language): .yml, .yaml</li>
<li class="fragment">PHP - Hypertext Preprocessor: .php </li>
<li class="fragment">Markdown: .md</li>
<li class="fragment">Javascript Object Notation (JSON): .json</li>
<li class="fragment"> Module: .module</li>
<li class="fragment"> Javascript: .js </li>
<li class="fragment"> CSS (Cascading Style Sheets): .css</li>
</ul>
</section>
<section>
<h3>Naming the module</h3>
<ul>
<li class="fragment">Start with a letter</li>
<li class="fragment">Use only lower-case letters and underscores</li>
<li class="fragment">No spaces</li>
<li class="fragment">Unique name</li>
<li class="fragment">Does not contain any reserved words: src, lib, vendor, assets, css, files, images, js, misc, templates, includes, fixtures, Drupal</li>
</ul>
</section>
<section>
<h3>The Module Skeleton</h3>
<img src="images/skeleton.gif" style="width: 400px;"/>
</section>
<section>
<h3 class="font-20">Capable Module</h3>
<div class="module-files">
<pre class="font-10">
modules
/contrib
/custom
/capable
README.md
STANDARDS.md
TESTING.md
capable.api.php
capable.info.yml
capable.libraries.yml
capable.links.menu.yml
capable.module
capable.permissions.yml
capable.routing.yml
capable.services.yml
capable.task.yml
composer.json
/config
/install
capable.settings.yml
/schema
capable.schema.yml
/css
capable.form.css
capable.miscellaneous.css
capable.module.css
capable.template.css
capable.theme.css
/js
main.js
/src
/Controller
CapableController.php
/Entity
CapableEntity.php
/Form
CapableForm.php
/Plugin
/Block
CapableBlock.php
/templates
welcome.html.twig
/tests
/src
/Functional
ExampleFunctionalTest.php
/Kernel
ExampleKernelTest.php
/Unit
ExampleUnitTest.php
</pre>
</div>
</section>
<section>
<h3>capable.info.yml</h3>
<ul>
<li class="fragment">The info.yml file lives in your root folder and tells Drupal about your module</li>
<li class="fragment">The info.yml file information can be found on the Drupal admin pages (/admin/modules)</li>
<li class="fragment">Technically, the only required file in your module (although the module won't do anything)</li>
</ul>
<span class="fragment">
<img src="images/capable-module-info-file.png" />
<div class="font-20">capable.info.yml</div>
</span>
</section>
<section>
<h3>What's going on?</h3>
<div class="left-40">
<img src="images/capable-module-info-file.png"/>
<div class="font-20">capable.info.yml</div>
</div>
<div class="right-60">
<img src="images/capable-module-info-screenshot.png"/>
<div class="font-20">/admin/modules</div>
</div>
</section>
<section>
<h3>capable.info.yml complete example</h3>
<div class="fragment left">
<img src="images/capable-module-info-file-2.png"/>
<div class="font-20">capable.info.yml</div>
</div>
<div class="right font-16">
<ul>
<li class="fragment">
<strong>depedencies:</strong>
<ul>
<li>List the other module(s) that your module depends on to work.</li>
<li>Namespacing: {project}:{module}</li>
<li>{project} is the name as it appears in the Drupal.org url (https://www.drupal.org/project/token)</li>
<li>{module} is the module machine name (token)</li>
<li>Can also include version restrictions: token:token (8.x-1.3)</li>
</ul>
</li>
<li class="fragment">
<strong>test_dependencies:</strong>
<ul>
<li>List the module(s) you need to run automated tests</li>
<li>Same namespacing as dependecies: {project}:{module} </li>
</ul>
</li>
<li class="fragment">
<strong>configure:</strong>
<ul>
<li>Specify the route to a configuration form</li>
<li>This will show on the /admin/modules pages when you expand [this needs different words or an image]</li>
</ul>
</li>
<li class="fragment">
<strong>php:</strong>
<ul>
<li>Defines the <strong>minimum</strong> PHP verison that your module requires</li>
<li>Can't enable the module if your PHP version is older</li>
</ul>
</li>
<li class="fragment">
<strong>hidden:</strong>
<ul>
<li>hidden: true, will hide your your module on the /admin/modules page</li>
<li>Why would you hide your module? Perhaps it only implements tests and you don't want it disabled</li>
</ul>
</li>
</ul>
</div>
</section>
<section>
<h3>The Controller File</h3>
<ul class="font-25">
<li class="fragment">Following PSR-4, the controller file will live inside a folder called src, and then in a folder called Controller</li>
<li class="fragment">src stands for source</li>
</ul>
<span class="fragment">
<img src="images/source-folder.png"/>
<div class="font-20">capable/src/Controller/CapableController.php</div>
</span>
<ul class="font-25" style="width: 100%">
<li class="fragment">Need to declare a namespace at the top.</li>
<li class="fragment">Namespace format: Drupal\[module name]\Controller;</li>
<li class="fragment">The controller file will work with the router file</li>
</ul>
</section>
<section>
<h3>CapableController.php</h3>
<span style="float: left;">
<img src="images/capable-controller-file.png"/>
<div class="font-20">CapableController.php</div>
</span>
<ul class="font-20" style="float: right; width: 46%;">
<li class="fragment">
<strong>namespace Drupal\capable\Controller:</strong> declaring the namespace for the capable Controller class <br />
- this must be done before any other code (except a declare statement)
</li>
<li class="fragment">
<strong>use Drupal\Core\Controller\ControllerBase: </strong> importing (aliasing) the Drupal core ControllerBase, which is being extended by CapableController class. <br />
- Do not include a leading \ <br />
- Only specify one class per use statement. <br />
- No clear rule to order for multiple use statements. <br />
- Final use statement should habe a blank line underneath it.
</li>
<li class="fragment">
<strong>class CapableController extends ControllerBase:</strong> creation of CapableController class that extends Drupal's core ControllerBase class
</li>
<li class="fragment">
<strong>public function content():</strong> take note of the name of the function, this will come back in the routing file
</li>
</ul>
</section>
<section>
<h3>The Routing File</h3>
<ul class="font-25">
<li class="fragment">A route is a path where Drupal returns some sort of content</li>
<li class="fragment">The router determines which code should be run to generate the response. </li>
<li class="fragment">The routing system is responsible for matching paths to controllers.</li>
</ul>
<span class="fragment">
<img src="images/capable-module-routing-file.png" />
<div class="font-20">capable/capable.routing.yml</div>
</span>
</section>
<section>
<h3>capable.routing.yml</h3>
<span>
<img src="images/routing-file-simple.png" />
<div class="font-20">capable.routing.yml</div>
</span>
</section>
<section>
<h3>Routing and Controller Working Together</h3>
<span class="fragment">
<img src="images/routing-file-simple-outlined.png" style="height: 150px; vertical-align: top;"/>
<div class="font-20">capable.routing.yml</div>
</span>
<span style="float: left;" class="fragment">
<img src="images/capable-controller-file-outlined.png" style="height: 270px;"/>
<div class="font-20">CapableController.php</div>
</span>
<span style="float: right;" class="fragment">
<img src="images/routing-file-screenshot.png" style="height: 275px;" />
<div class="font-20">/hello</div>
</span>
</section>
<section>
<h3>Parameters in Routes</h3>
<ul class='font-20'>
<li class="fragment">Parameters are used for URLs that may contain dynamic values. <br />
/parameters/[partial] would work for both /parameters/hello and /parameters/goodbye </li>
<li class="fragment"> The [partial] element in the url is called a slug, and is is avaible as a $partial in the controller method</li>
<li class="fragment">You can even have multiple parameters on a single route: product/[productnumber]/[color]</li>
<div class="fragment">
<span class="left">
<img src="images/router-parameters.png"/>
<div class="font-20" style="text-align: center;">capable.routing.php</div>
</span>
<span class="right">
<img src="images/controller-parameters.png"/>
<div class="font-20" style="text-align: center;">CapableController.php</div>
</span>
</div>
</ul>
</section>
<section>
<h3>Parameters in Routes</h3>
<span>
<img src="images/parameters-hello.png" style="width: 600px;" class="no-margin"/>
<div class="font-20">/parameters/hello</div>
</span>
<span>
<img src="images/parameters-goodbye.png" style="width: 600px; margin-bottom: 0px;"/>
<div class="font-20">/parameters/goodbye</div>
</span>
</section>
<section>
<h3>Module Menu Link</h3>
<p class="font-25">Menu link to the module in the Development section of the Administration >> Configuration (/admin/config)</p>
<img src="images/capable-module-links-file.png" />
<div class="font-20">/capable/capable.links.menu.yml</div>
</section>
<section>
<h3>Module Menu Link</h3>
<span>
<img src="images/capable-module-links-menu.png" class="no-margin"/>
<div class="font-20">capable.links.menu.yml</div>
</span>
<span class="left">
<img src="images/capable-module-links-routing.png"/>
<div class="font-20">capable.routing.yml</div>
</span>
<span class="right">
<img src="images/capable-module-menu-controller.png"/>
<div class="font-20">CapableController.php</div>
</span>
</section>
<section>
<h3>Module Menu Link Screenshot</h3>
<span>
<img src="images/capable-module-menu-links-screenshot.png" style="height: 500px;"/>
<div class="font-20">/admin/config</div>
</span>
</section>
<section>
<h3>Module Menu Link Flexibility</h3>
<p>You can also set the [module].links.menu.yml to link to external links or to an internal path</p>
<div class="left font-20">
External Link
<img src="images/capable-module-menu-links-external.png" />
<div class="font-20">capable.links.menu.yml</div>
</div>
<div class="right font-20">
Internal Link
<img src="images/capable-module-menu-links-internal.png"/>
<div class="font-20">capable.links.menu.yml</div>
</div>
</section>
<section>
<h3>capable.module</h3>
<ul>
<li class="fragment">
The capable.module file is optional
</li>
<li class="fragment">
Used for implementing hooks
</li>
</ul>
<img src="images/hooks.gif" class="fragment"/>
</section>
<section>
<h3>Introduction to Hooks</h3>
<ul class="font-20">
<li class="fragment">
Hooking: range of techniques that lets you change the behavior of applications by intercepting events passed between software components.
</li>
<li class="fragment">
Hook: the code that handles this interception
</li>
<li class="fragment">
Hooks in Drupal let modules interact with other modules or Drupal core
</li>
<li class="fragment">
Hooks can be thought of event listeners that fire off when a certain event triggers them, and can be used at various code execution points
</li>
<li class="fragment">
In Drupal 8, some hooks have remained the same, some have been removed, others have been modified, and some have been added. <a href="https://api.drupal.org/api/drupal/core%21core.api.php/group/hooks/8.5.x">For the entire list of core hooks, click here. </a>
</li>
<li class="fragment">
To implement a hook, replace the hook name of the function with the name of your module:
<ul>
<li>
<a href="https://api.drupal.org/api/drupal/core%21modules%21help%21help.api.php/function/hook_help/8.2.x"> hook_help()</a> → capable_help()
</li>
</ul>
</li>
</ul>
</section>
<section>
<h3>capable.module</h3>
<div style="width: 40%; float: left;" class="fragment">
<img src="images/capable-module-module-file.png" />
<div class="font-20">capable/capable.module</div>
</div>
<div style="width: 50%; float: left;" class="fragment no-margin">
<img src="images/capable-module-module-file-code.png"/>
<div class="font-20">capable.module</div>
</div>
<div style="height: 200px;" class="fragment">
<img src="images/capable-module-module-file-screenshot.png" />
<div class="font-20">/admin/help/capable</div>
</div>
</section>
<section>
<h3>Composer</h3>
<ul class="font-25">
<li class="fragment">
If your module has a dependency to a third party library hosted on <a href="https://packagist.org/">Packagist</a>, you can define this dependency
</li>
<li class="fragment">
MUST declare dependencies in your info.yml file, but composer.json can let you get more specific with constraints
</li>
<li class="fragment">
If your module does not have any dependencies, composer.json is not required, but having it will not have a negative impact
</li>
<li class="fragment">
Drupal core will NOT automatically find your custom module composer.json,
</li>
</ul>
</section>
<section>
<h3 class="font-25">Tell root composer.json about your custom module's composer.json</h3>
<ul class="font-20" style="list-style-type: none;">
<li class="fragment">1. In root composer run <code>composer require wikimedia/composer-merge-plugin</code></li>
<li class="fragment">2. Edit root composer file</li>
</ul>
<span class="fragment">
<img src="images/root-composer-file.png" class="no-margin" style="height: 500px;"/>
<p class="font-16 no-margin">root/composer.json</p>
</span>
</section>
<section>
<h3>Capable composer.json</h3>
<ul class="font-20" style="list-style-type: none;">
<li class="fragment">3. create custom module composer file</li>
</ul>
<div class="fragment">
<img src="images/composer-file-location.png" />
<div class="font-20">
capable/composer.json
</div>
</div>
</section>
<section>
<h3>Composer File</h3>
<img src="images/composer-json-file.png" />
<div class="font-20">
capable/composer.json
</div>
</section>
<section>
<h3>Composer Update</h3>
<ul class="font-20" style="list-style-type: none;">
<li class="fragment">4. Run <code>composer update</code> in your root composer.json</li>
</ul>
<div class="fragment">
<img src="images/composer-update.png" />
<div class="font-20">
capable/composer.json
</div>
</div>
</section>
<section>
<h3>Forms</h3>
<ul class="font-25">
<li class="fragment">
<a href="https://www.drupal.org/docs/8/api/form-api/introduction-to-form-api">Introduction to Form API</a>
<ul>
<li>
API: application programming interface is a set of functions and tools for building software with clearly defined methods of communication
</li>
</ul>
</li>
<li class="fragment">
Need to identify the type of form you need
</li>
<ul class="fragment">
<li>
General form: extend <a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21FormBase.php/class/FormBase/8">Form Base</a>
</li>
<li>
A configuration form that lets administrators update a module settings: extend <a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21ConfigFormBase.php/class/ConfigFormBase/8">ConfigFormBase</a>
</li>
<li>
A form for deleting content or configuation with a confirmation step: extend <a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21ConfirmFormBase.php/class/ConfirmFormBase/8">ConfirmFormBase</a>
</li>
</ul>
<li class="fragment">
Required methods:
<ul>
<li>
getFormId()
</li>
<li>
buildForm()
</li>
<li>
validateForm()
</li>
<li>
submitForm()
</li>
</ul>
</li>
</ul>
</section>
<section>
<h3>CapableForm.php</h3>
<div class="left">
<img src="images/capable-form-routing-screenshot.png" />
<div class="font-20">capable.routing.yml</div>
</div>
<div class="right">
<img src="images/capable-form-screenshot.png" />
<div class="font-20">capable/src/Form/CapableForm.php</div>
</div>
</section>
<section>
<h3>CapableForm.php</h3>
<div class="left">
<img src="images/capable-form-php-file.png" />
<div class="font-20">CapableForm.php</div>
</div>
<div class="right">
<img src="images/capable-form-screenshot-site.png" />
<div class="font-20">/capable/form</div>
</div>
</section>
<section>
<h3>Configuration</h3>
<ul class="font-25">
<li class="fragment">
Configuration is a place to store information you would like to synchronize from development to production. This information can be used in your own plugins, entities and settings.
</li>
<span class="fragment">
<li style="float: left; width: 50%; margin-right: 20px;">
Lives under a /config directory
<ul>
<li>
/install directory
</li>
<ul>
<li>
Configuration defaults live under the /config/install directory
</li>
<li>
capable.settings.yml: This file stores configuration defaults, which are assigned to the correct fields via the next file
</li>
</ul>
<li>
/schema directory
<ul>
<li>
<a href="https://en.wikipedia.org/wiki/Database_schema">Schema</a>: the organization of the structure of the database
</li>
<li>
capable.schema.yml: define a custom table for your module
</li>
</ul>
</li>
</ul>
</li>
<span style="width: 40%">
<img src="images/config-file-location.png"/>
<div class="font-20">/capable/config/install/capable.settings.yml <br />
/capable/config/schema/capable.schema.yml
</div>
</span>
</span>
</ul>
</section>
<section>
<h3>Configuration</h3>
<div style="width: 50%; float:left;">
<img src="images/config-settings.png" style="vertical-align: top;"/>
<div class="font-20">capable.settings.yml</div>
</div>
<div style="width: 47%; float:left;">
<img src="images/config-schema.png" style="vertical-align: top;"/>
<div class="font-20">capable.schema.yml</div>
</div>
<img src="images/config-database.png" />
</section>
<section>
<h3>Configuration</h3>
<div style="float: left;">
<img src="images/config-routing.png" style="vertical-align: top;"/>
<div class="font-20">capable.routing.yml</div>
</div>
<div style="float: left;">
<img src="images/config-controller.png" style="vertical-align: top;"/>
<div class="font-20">CapableContoller.php</div>
</div>
</section>
<section>
<h3>Configuration</h3>
<img src="images/config-screenshot.png" />
<div class="font-20">/module/config</div>
</section>
<section>
<h3>Permissions</h3>
<ul class="font-25">
<li class="fragment">
Permissions are defined in a [modulename].permissions.yml instead of using hook_permission()
<li class="fragment">
Static permissions: do not depend on system information
</li>
<li class="fragment">
Dynamic permissions: generated by system specific information (node type, user role)
</li>
</ul>
<div class="fragment">
<img src="images/permissions-file-location.png"/>
<div class="font-20">/capable/capable.permissions.yml</div>
</div>
</section>
<section>
<h3>Static Permission</h3>
<img src="images/capable-module-permissions-restrict-false.png" style="height: 120px" class="no-margin"/>
<div class="font-20">capable.permissions.yml</div>
<img src="images/capable-module-edit-permission-notrestricted-screenshot.png" style="height: 300px; display: table; margin-left: auto; margin-right: auto;" />
<img src="images/capable-module-edit-permission-restricted-screenshot.png" style="height: 75px" class="no-margin"/>
<div class="font-20">/admin/people/permissions</div>
</section>
<section>
<h3>Setting Permissions in Routing</h3>
<img src="images/permissions-routing-file.png" />
<div class="font-20">capable.routing.yml</div>
</section>
<section>
<h3>Services</h3>
<ul style="width: 50%; float: left; font-size: 32px;">
<li class="fragment">
A <a href="https://www.drupal.org/docs/8/api/services-and-dependency-injection">service</a> is any reusable PHP object that does something
</li>
<li class="fragment">
Managed by the services container
</li>
<li class="fragment">
Services perform operations like accessing the database, sending email or translating user interface text
</li>
<li class="fragment">
<a href="https://www.drupal.org/docs/8/api/services-and-dependency-injection/structure-of-a-service-file">[modulename].services.yml</a> will live in the root of the module
</li>
</ul>
<div class="fragment" style="float: left;">
<img src="images/services-files.png"/>
<div class="font-20">capable/src/CapableServices.php<br />
capable/capable.services.yml
</div>
</div>
</section>
<section>
<h3>Services</h3>
<div style="width: 40%; float: left;">
<img src="images/services-yml.png" style="vertical-align: top;"/>
<div class="font-20">capable.services.yml</div>
</div>
<div style="width:50%; float: left;">
<img src="images/capable-services.png" />
<div class="font-20">CapableServices.php</div>
</div>
</section>
<section>
<h3>Services</h3>
<div style="width: 50%; float: left">
<img src="images/services-router.png" style="vertical-align: top;"/>
<div class="font-20">capable.routing.yml</div>
</div>
<div style="width: 40%; float: left">
<img src="images/services-controller.png" />
<div class="font-20">CapableController.php</div>
</div>
</section>
<section>
<h3>Services</h3>
<img src="images/services-screenshot.png" />
<div class="font-20">/module/service</div>
</section>
<section>
<h3>Plugins and Custom Blocks</h3>
<div class="left font-25">
<ul>
<li class="fragment">
Plugins are small pieces of functionality that are swappable
</li>
<li class="fragment">
Plugins that perform similar functionality are of the same plugin type
</li>
<li class="fragment">
Blocks are instances of the block <a href="https://www.drupal.org/developing/api/8/plugins">plugin</a>.
</li>
<li class="fragment">
Plugin code must live in /src/Plugin/[plugin_type]/Example.php
<ul>
<li>
Blocks: /src/Plugin/Block/*
</li>
<li>
Field formatters, Field widgets: /src/Plugin/Field/*
</li>
<li>
Views plugins: /src/Plugin/views/*
</li>
</ul>
</li>
</ul>
</div>
<div class="right fragment">
<img src="images/capable-custom-block-plugin-file-location.png" />
<div class="font-20">capable/src/Plugin/Block/CapableBlock.php</div>
</div>
</section>
<section>
<h3>CapableBlock.php</h3>
<div class="left-40">
<img src="images/capable-custom-block-plugin-code.png" />
<div class="font-20">CapableBlock.php</div>
</div>
<div class="right-60">
<img src="images/capable-custom-block-plugin-screenshot.png" />
<div class="font-20">/admin/structure/block >> Capable Block</div>
</div>
</section>
<section>
<h3>Module Theming</h3>
</section>
<section>
<h3>Libraries</h3>
<ul class="font-25">
<li class="fragment">
A library is a "collection of implementations of behavior... that has a well-defined interface by which the behavior is invoked." - <a href="https://en.wikipedia.org/wiki/Library_(computing)">Wikipedia</a>
</li>
<li class="fragment">
Define one or more libraries (assets) in [modulename].libraries.yml
</li>
<li class="fragment">
Must explicitly tell Drupal the libraries you want it to load, including CSS and JS files
</li>
<li class="fragment">
Drupal 8 no longer loads jQuery on all pages on default, so you must tell Drupal that your library has a dependency on jQuery.
</li>
<li class="fragment">
Attach the library to a render array in a hook
</li>
</ul>
<img src="images/libraries.gif" class="fragment" style="height: 200px;"/>
</section>
<section>
<h3>capable.libraries.yml</h3>
<div style="float: left; width: 32%;" class="fragment">
<img src="images/capable-libraries-file-location.png" style="vertical-align: top;"/>
<div class="font-20">capable/capable.libraries.yml</div>
</div>
<div style="float: left; width: 32%;" class="fragment" >
<img src="images/capable-libraries-file.png" style="vertical-align: top;"/>
<div class="font-20">capable.libraries.yml</div>
</div>
<div style="float: left; width: 32%;" class="fragment">
<img src="images/css-js-assets.png" style="vertical-align: top;"/>
<div class="font-20">capable/css/capable.form.css <br />
capable/css/capable.miscellaneous.css <br />
capable/css/capable.module.css <br />
capable/css/capable.template.css <br />
capable/css/capable.theme.css <br />
capable/js/main.js
</div>
</div>
</section>
<section>
<h3>Load the Library</h3>
<ul class="font-25">
<li>
Attach a library in several ways:
<ol>
<li class="fragment">
<a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_element_info_alter/8.3.x" >hook_element_info_alter()</a>: a module implements this hook to alter the element type defaults defined by a module
</li>
<li class="fragment">
<a href="https://www.drupal.org/docs/8/api/render-api/render-arrays">Render array</a>: a structured array that provides data (probably nested) along with hints as to how it should be rendered
</li>
<li class="fragment">
<a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_page_attachments/8.3.x">hook_page_attachments()</a>: conditionally add assets to a page
</li>
<li class="fragment">
<a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_preprocess_HOOK/8.3.x">template_preprocess_hook()</a>: lets modules preprocess theme variables for a specific theme hook
</li>
<li class="fragment">
<a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Template%21TwigExtension.php/function/TwigExtension%3A%3AattachLibrary/8.3.x">{{ attach_library(‘example/example’) }}</a>: attaches an asset to a the twig template
</li>
</ol>
<li class="fragment">
Note: <code>drupal_add_css()</code>, <code>drupal_add_js()</code> and <code>drupal_add_library()</code> were replaced with <code> #attached</code>
</li>
</li>
</ul>
</section>
<section>
<h3>Globally Load a Library </h3>
<span class="font-20">Attach the library to all pages with hook_page_attachments in capable.module</span>
<img src="images/globally-attach-page-attachments.png" />
<div class="font-20">capable.module</div>
</section>
<section>
<h3>Globally Load a Library </h3>
<img src="images/globally-attach-screenshot.png" style="height: 300px" class="no-margin"/>
<div class="font-20">/hello</div>
<img src="images/globally-attach-file-load.png" style="height: 200px"/>
</section>
<section>
<h3>Load Library to a Form</h3>
<div>
<span class="font-20">Attach the library in the render array buildForm function in the CapableForm.php file<br />
<code>$form['#attached']['library'][] = 'module-name/library-name'</code></span>
<img src="images/form-library-attached.png" class="no-margin" />
<div class="font-20">CapableForm.php</div>
</div>
</section>
<section>
<h3>Load Library to a Form</h3>
<div style="float: left; width: 60%;">
<img src="images/form-library-attached-screenshot.png"/>
<div class="font-20">/capable/form</div>
</div>
<div style="float: left; width: 35%;">
<img src="images/form-library-loading.png"/>
</div>
</section>
<section>