238 lines
3.7 KiB
Markdown
238 lines
3.7 KiB
Markdown
+++
|
|
title = "When There's Not a Module For That"
|
|
outputs = ["Reveal"]
|
|
+++
|
|
|
|
# When There's Not a Module For That
|
|
|
|
###### mid.camp/6337
|
|
|
|
<img alt="Agaric" src="images/o-midcamp.png" class="plain" />
|
|
|
|
{{% note %}}
|
|
mid-air camp
|
|
{{% /note %}}
|
|
|
|
---
|
|
|
|
###### Presented by
|
|
|
|
**Benjamin Melançon** & **Mauricio Dinarte**
|
|
|
|
###### AKA
|
|
|
|
**[mlncn](https://agaric.coop/mlncn)** & **[dinarcon](https://agaric.coop/dinarcon)**
|
|
|
|
---
|
|
|
|
|
|
### Together,
|
|
|
|
## We are
|
|
|
|
#### ⅓
|
|
|
|
#### of
|
|
|
|
|
|
---
|
|
|
|
|
|
<img alt="Agaric" src="images/agaric-logo-stacked.png" class="plain" />
|
|
|
|
**ask@agaric.coop**
|
|
|
|
---
|
|
|
|
|
|
<img alt="Agaric" src="images/o-midcamp.png" class="plain" width="47%" />
|
|
|
|
{{% note %}}
|
|
mid-air camp
|
|
{{% /note %}}
|
|
|
|
|
|
---
|
|
|
|
|
|
> When building a Drupal site, “there’s a module for that” can be the sweetest words you can hear.
|
|
|
|
|
|
{{% note %}}
|
|
{{% /note %}}
|
|
|
|
---
|
|
|
|
|
|

|
|
|
|
|
|
{{% note %}}
|
|
Say you're creating a site where people can relive great literature that may have been inspired by a global pandemic.
|
|
{{% /note %}}
|
|
|
|
---
|
|
|
|
|
|
`frankenstein.info.yml`
|
|
|
|
```yaml
|
|
name: Frankenstein
|
|
type: module
|
|
description: "Rename save button for Frankenstein's content."
|
|
core: 8.x|9.x
|
|
```
|
|
|
|
|
|
|
|
`frankenstein.module`
|
|
|
|
```php
|
|
<?php
|
|
function frankenstein_form_node_frankenstein_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
|
|
$form['actions']['submit']['#value'] = t('Re-animate!');
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
### Where to put these files
|
|
|
|

|
|
|
|
|
|
---
|
|
|
|
|
|

|
|
|
|
|
|
---
|
|
|
|
|
|
**Enable your module:**
|
|
|
|
`drush -y en frankenstein`
|
|
|
|
|
|
---
|
|
|
|
|
|
*That slide was the most important you're going to be shown.*
|
|
|
|
# Enable your module
|
|
|
|
|
|
---
|
|
|
|
|
|

|
|
|
|
---
|
|
|
|

|
|
|
|
{{% note %}}
|
|
So you're all sitting* there thinking ... sure, that's easy if you know the exact words and symbols to *put* in that file. And you're absolutely right.
|
|
|
|
And we're going to tell you how you can figure out all of that.
|
|
|
|
The examples with the what will tell you a lot about the how.
|
|
|
|
But first, two secrets.
|
|
{{% /note %}}
|
|
|
|
---
|
|
|
|
|
|
### Now you know where to paste
|
|
|
|

|
|
|
|
{{% note %}}
|
|
(yes, the same family of sites that has helped a couple million developers figure out how to quit vim.)
|
|
|
|
Knowing where to put this code unleashes the power of Stack Overflow.
|
|
|
|
You now know enough to be dangerous.
|
|
{{% /note %}}
|
|
|
|
|
|
---
|
|
|
|
|
|
### That simple form alter has hidden gotchas
|
|
|
|
* As written, it only applies to the create (node/add) form— not the edit form.
|
|
* There's a dozen variations of the humble form alter hook, and all are valid.
|
|
|
|
{{% note %}}
|
|
{{% /note %}}
|
|
|
|
|
|
---
|
|
|
|
#### We'll cover
|
|
|
|
* 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.
|
|
|
|
{{% /note %}}
|
|
|
|
---
|
|
|
|
|
|
{{% note %}}
|
|
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.
|
|
{{% /note %}}
|
|
|
|
|
|
---
|
|
|
|
## Learning to learn
|
|
|
|
* Drupal documentation
|
|
* Duck Duck Go (!g if you need Google results)
|
|
* Debugger - look for
|
|
|
|
{{% note %}}
|
|
Where to start if i don't cover it in this session
|
|
{{% /note %}}
|
|
|
|
|
|
---
|
|
|
|
### When not to make a module
|
|
|
|
{{% note %}}
|
|
find a contrib module that does it
|
|
|
|
Should it be in a template
|
|
{{% /note %}}
|
|
|
|
|
|
---
|
|
|
|
|
|
{{% note %}}
|
|
{{% /note %}}
|
|
|
|
|
|
---
|
|
|
|
|