Presentation in state as presented
This commit is contained in:
parent
846b68aed9
commit
57e4c16287
6 changed files with 324 additions and 1 deletions
|
@ -10,7 +10,7 @@ New England Drupal Camp @ Rhode Island College
|
|||
Providence, RI
|
||||
November 16, 2024
|
||||
#NEDCamp2024
|
||||
9am, Gaige Hall 201
|
||||
9am, Gaige Hall 206
|
||||
|
||||
benjamin "mlncn" melançon
|
||||
ben@agaric.coop
|
||||
|
@ -279,6 +279,34 @@ Note: This is how people in the same situation will find your module. Currently
|
|||
|
||||
---
|
||||
|
||||
##### There's a module that *almost* does exactly what you want
|
||||
|
||||
* Contribute a patch!
|
||||
* Port it to Drupal 8/9!
|
||||
|
||||
Note: Even if your patch is not accepted nor is there any way given to build on the module, you can fork the module— maintain your own copy. Indeed, this is the standard way of contributing now, with an Issue Fork.
|
||||
|
||||
---
|
||||
|
||||
](https://www.drupal.org/project/comment_notify/issues/2850935)
|
||||
|
||||
---
|
||||
|
||||
|
||||
](https://www.drupal.org/project/comment_notify/issues/2976478)
|
||||
|
||||
Note: This strategy is not without risks. David was made a maintainer of Comment Notify, and now routinely fixes issues there all himself. Still, that's generally better for *everyone* than to make your own module with duplicate functionality.
|
||||
|
||||
---
|
||||
|
||||
Act Two
|
||||
|
||||
### How Not To Have to Make a Whole Module
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
### Be a part of something bigger
|
||||
(but not as big as all of Drupal)
|
||||
|
||||
|
@ -314,6 +342,22 @@ Note: Doing your own by extending an existing plugin or copying and modifying an
|
|||
|
||||
---
|
||||
|
||||
Act Three
|
||||
|
||||
### How To Figure Out How To Make a Module
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
### When to make a module
|
||||
|
||||

|
||||
|
||||
Note: You've identified to the best of your ability that there's definitely not something out there that does what you want to do. I personally do not advocate introspection at this point: Why am i trying to do something that no one else is trying to do? Credit: lego heart is credited to Llama-Muffin-Kelly on DeviantArt but only see it on Pinterest
|
||||
|
||||
---
|
||||
|
||||
### Steal, and keep stealing
|
||||
|
||||
----
|
||||
|
@ -341,8 +385,57 @@ Note: Grep. Even when i am fully using an IDE for everything else, i grep in th
|
|||
|
||||
---
|
||||
|
||||
### Building blocks
|
||||
|
||||
* Hooks
|
||||
* Form alter
|
||||
* Node insert
|
||||
* Plugins
|
||||
* Block
|
||||
* Formatter
|
||||
* Services
|
||||
* Route subscriber
|
||||
* Event subscriber
|
||||
|
||||
Note: The three main ways to mess with Drupal 8 and 9: hooks, plugins, and services, with a couple examples in each. Both examples of what technically to do and how to do general things. For example: Doing something with a form? You want hook_form_alter() or one of its variants.
|
||||
|
||||
---
|
||||
|
||||
How to figure out how to make a module
|
||||
|
||||
## Learning to learn
|
||||
|
||||
* Drupal documentation
|
||||
* Drupal contributed modules
|
||||
* Drupal core and *its* modules
|
||||
* Debugger
|
||||
* Drupal forums and issues
|
||||
* Drupal.StackExchange.com
|
||||
* The rest of the Internet
|
||||
* Code search / grep
|
||||
|
||||
Note: Where to start if i don't cover it in this session. And the debugger to more quickly find methods and functions, or even step through code, in contributed modules, core, and the module you're working on!
|
||||
|
||||
---
|
||||
|
||||
|
||||
### Building a Contrib-Worthy Modern Drupal (10, 11, 12…) Module
|
||||
|
||||
#### What module to make?
|
||||
|
||||
* One you need.
|
||||
* One not already made!
|
||||
|
||||
Note: To summarize: ^^
|
||||
|
||||
---
|
||||
|
||||
#### Write up what you plan to do
|
||||
|
||||
[groups.drupal.org/contributed-module-ideas](https://groups.drupal.org/contributed-module-ideas)
|
||||
|
||||
Note: Is one place
|
||||
|
||||
---
|
||||
|
||||
File issues for your own modules.
|
||||
|
@ -351,6 +444,236 @@ Note: It helps you think through what you are planning to do, it makes features
|
|||
|
||||
---
|
||||
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
```yaml
|
||||
name: "Project Copyright"
|
||||
type: module
|
||||
description: "Generate a block with the copyright leyend."
|
||||
core_version_requirement: ^8 || ^9 || ^10 || ^11 || ^12
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace Drupal\copyright\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
|
||||
/**
|
||||
* Provides a block with the copyright legend.
|
||||
*
|
||||
* @Block(
|
||||
* id = "copyright_block",
|
||||
* admin_label = @Translation("Copyright"),
|
||||
* )
|
||||
*/
|
||||
class Copyright extends BlockBase {
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function build() {
|
||||
return [
|
||||
'#markup' => $this->t('Copyright © @year All rights reserved', ['@year' => date('Y')]),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
|
||||
Note: Hooks are magic portals that let any module appear in another part of Drupal and do something. More technically, a hook is tied to some sort of Drupal event and is an opportunity for our module to take action. There were 251+ hooks in Drupal 7 core. After a concerted effort in the development of Drupal 8 to remove hooks and replace them with more modern and widespread (outside Drupal) programming practices such as plugins and services... There are now 288 hooks in Drupal 8.8. To be fair, we moved some big contributed modules like Views into Drupal core ... but even after that, we've added 25 hooks to core since Drupal 8.2 (and only deprecated 9, which are removed in Drupal 9). Hooks are still very much a part of Drupal. Every contributed module can provide hooks, too.
|
||||
|
||||
|
||||
---
|
||||
|
||||
Hooks work by naming convention.
|
||||
|
||||
To implement a hook, take the 'hook' part off the hook name and replace it with your module's (machine) name.
|
||||
|
||||
---
|
||||
|
||||
## Resources
|
||||
|
||||
Most of these links go to a page on [Drupal's API reference which is also a great place to go for an overview](https://api.drupal.org/api/drupal/9.0.x) of what tools are available to you as you pick through the pieces Drupal offers and assemble your module.
|
||||
|
||||
https://api.drupal.org/api/drupal/core%21core.api.php/group/extending/
|
||||
|
||||
---
|
||||
|
||||
### Key hooks
|
||||
|
||||
* [hook form_alter](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21form.api.php/function/hook_form_alter/9.0.x )
|
||||
* [hook_entity_extra_field_info](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21entity.api.php/function/hook_entity_extra_field_info/9.0.x ) + a 'field' site builders can use in entity view modes, such as to combine entity data and format it for display. Or you can replace those three hooks with one plugin by using the [Extra field module](https://www.drupal.org/project/extra_field )
|
||||
|
||||
### All the hooks
|
||||
|
||||
* [api.drupal.org/api/drupal/core!core.api.php/group/hooks](https://api.drupal.org/api/drupal/core!core.api.php/group/hooks/)
|
||||
|
||||
|
||||
Note: A note on all these links: I've linked to the Drupal 9.0 version. These hooks all work in Drupal 8.x also. Drupal.org [inadvertently for quite a while treated 8.2 as the end-all-and-be-all version of Drupal](https://www.drupal.org/project/apidrupalorg/issues/3085999 ); this has been mitigated and is being fixed but Google is still likely to take you to 8.2 when searching for documentation on a hook. Just switch to the version you're using, or the latest version of Drupal if
|
||||
|
||||
|
||||
---
|
||||
|
||||
|
||||
### The Rest of the Internet
|
||||
|
||||
* Duck Duck Go (!g for Google results)
|
||||
* [ddg.co](https://duckduckgo.com/)
|
||||
* [agaric.coop/blog](https://agaric.coop/blog)
|
||||
* Your own notes
|
||||
|
||||
---
|
||||
|
||||
### Copy or have technology copy for you
|
||||
|
||||
* A module that was generated with Drupal Console https://www.drupal.org/project/ckeditor_youtube/ - simple and used by many, and slowly got more complex
|
||||
|
||||
Note: Shows how a lot of this is boilerplate.
|
||||
|
||||
|
||||
---
|
||||
|
||||
### Field Formatter
|
||||
|
||||
|
||||
* A module bringing in a PHP library and getting crazy (started with simple field formatter, can use this or another module to demo that) - https://drupal.org/project/inotherwords
|
||||
|
||||
Note: @TODO bring in, cleaned up and not confusing
|
||||
|
||||
---
|
||||
|
||||
### Services: Event Subscriber
|
||||
|
||||
https://gitlab.com/find-it-program-locator/findit_library_sync/-/blob/8.x-1.x/migrations/findit_library_sync_events.yml#L5
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Why contribute?
|
||||
|
||||
* Right thing to do
|
||||
* I asked you to
|
||||
* People may contribute to it
|
||||
* Someone may take it over and upgrade it or improve it greatly
|
||||
|
||||
|
||||
---
|
||||
|
||||
[](https://www.drupal.org/project/workflow_buttons/issues/3120524)
|
||||
|
||||
Note: Or someone may make a tiny improvement that makes everyone's lives better.
|
||||
|
||||
---
|
||||
|
||||
## Nice touches
|
||||
|
||||
`workflow_buttons.info.yml`
|
||||
|
||||
```diff
|
||||
type: module
|
||||
description: 'Provide workflow buttons for content moderation instead of a select dropdown of states.'
|
||||
core_version_requirement: ^8 || ^9
|
||||
core: 8.x
|
||||
+configure: workflow_buttons.settings
|
||||
|
||||
dependencies:
|
||||
- drupal:system (>=8.4)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### How to develop while sharing the same code you're using
|
||||
|
||||
Your module `composer.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "drupal/cyborgtranslate",
|
||||
"description": "Trigger Google translate and Drupal interface translation at the same time, allowing sections of your site's localization to be done by humans and the rest by machines.",
|
||||
"keywords": ["drupal", "translation", "multilingual", "localization", "google translate"],
|
||||
"type": "drupal-module",
|
||||
"license": "GPL-2.0+",
|
||||
"homepage": "https://www.drupal.org/project/cyborgtranslate",
|
||||
"minimum-stability": "dev",
|
||||
"support": {
|
||||
"issues": "https://www.drupal.org/project/issues/cyborgtranslate",
|
||||
"source": "https://gitlab.com/agaric/drupal/cyborgtranslate/tree/8.x-1.x"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Note: Composer makes a lot of stuff seem more complicated, but it makes it easier to contribute. Trust me... this will only be three screens of gibberish. It's also possible to read from other sources, not just Drupal.org. In this case, for example, we are getting the project from our GitLab mirror, which we have so people can submit merge requests if they would like.
|
||||
|
||||
---
|
||||
|
||||
Your project root `composer.json`:
|
||||
|
||||
|
||||
```json
|
||||
{
|
||||
"require": {
|
||||
"drupal/core": "^8.8.0",
|
||||
"drupal/cyborgtranslate": "dev-8.x-1.x as 1.x-dev",
|
||||
"drush/drush": "^9.0"
|
||||
},
|
||||
"repositories": {
|
||||
"drupal": {
|
||||
"type": "composer",
|
||||
"url": "https://packages.drupal.org/8"
|
||||
},
|
||||
"drupal/cyborgtranslate": {
|
||||
"type": "git",
|
||||
"url": "git@gitlab.com:agaric/drupal/cyborgtranslate.git"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Examples for developers project
|
||||
|
||||
[drupal.org/project/examples](https://www.drupal.org/project/examples)
|
||||
|
||||
Note: It's like it was written just for you.
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
||||
Drupal.org/planet to keep up to date with what is going on in the Drupal world.
|
||||
Drupal.tv for recording of talks at different conferences.
|
||||
Drupical.com to find out about events happening in your city.
|
||||
The official Drupal API documentation.
|
||||
The Drupal Slack to get community support.
|
||||
A video series by OSTraining on YouTube.
|
||||
Drupalize.Me for high quality (paid) material.
|
||||
UnderstandDrupal.com shameless plug
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||

|
||||
agaric.coop/wtnamft · <a href="mailto:ask@agaric.coop">ASK@AGARIC.COOP</a>
|
||||
|
||||
Note: It's a big wild world out there. Bite off a piece you can chew. Links for all of this and more on the session page.
|
||||
|
||||
---
|
||||
|
||||
To be continued…
|
||||
|
||||
Note: Let me know what you build!
|
||||
|
|
BIN
images/create-module-project.png
Normal file
BIN
images/create-module-project.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
Binary file not shown.
After Width: | Height: | Size: 880 KiB |
BIN
images/modules-search.png
Normal file
BIN
images/modules-search.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 138 KiB |
BIN
images/muppet-show-curtain.png
Normal file
BIN
images/muppet-show-curtain.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 970 KiB |
BIN
images/yml-add-content-block-action-link.png
Normal file
BIN
images/yml-add-content-block-action-link.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
Loading…
Add table
Add a link
Reference in a new issue