Score:-3

How to pass an argument to a hook without creating a custom module?

cn flag

I need to attach a theme-agnostic ("global") CSS file to the preprocess_hook() function so that any theme I use, would include that CSS.

I want to do that without creating a custom module because while I am a programmer, I am just not a PHP programmer and I find the documentation about creating custom modules overkill for this specific goal and I won't learn this entire subject just for a CSS file.

Score:0
cn flag

As a general rule, you can't use hooks without writing a custom module.

The Rules module provides a UI to access some hooks without writing code, but this is mostly limited to entity-related hooks (add, delete, update / CRUD operations).

Custom modules aren't that hard

Custom modules can be as little as ~10 lines of code; they are not hard to write. However, the core documentation is quite thorough and difficult to skim; it may be more information than what you need.

In that case, I recommend beginner-friendly (but paid) tutorials like module development with Drupalize.me.

cn flag
It's not about hard or not, it's about expertise; I am a programmer, just not a PHP programmer (maybe I should edit to clarify) and does not mean to learn the entire subject just for a CSS file.
cn flag
You have made a wrong assumption that these are hard due to being "written for programmers"; I tell you as a programmer (I can refer you to my GitHub account to go through some Bash, JavaScript and even PHP codes I wrote if you don't believe me that I am a programmer) that my problem is at least one of these reasons: **1)** My native language is not English and not Germanic, **2)** I have a hard time reading such long English texts from a computer screen, **3)** I feel bad doing things I grasp as reserved for experts. In essence, I think you should edit the answer.
cn flag
Here is a referral, just in case: https://github.com/bendqh1?tab=repositories
cn flag
@Alkalix Ok, well the mechanism Drupal provides for using hooks is modules. So the answer to your question **How to pass an argument to a hook without creating a module?** is no, you can't. However, a custom module, as noted in my answer, can be as little as 10 lines of code and can be created in less than a minute with any text editor. Creating a custom module does not require learning a bunch of Drupal APIs; basically, you create a `mymodule.info.yml` (not PHP! just YML), and then you add your custom hook code and you are done.
cn flag
My main problem is with the saying `However, the core documentation is written for programmers so it may be difficult to understand the documentation.` which I find misleading and I think should be edited. Hardness with the documentation doesn't necessarily do with being a programmer or not, at least from my life experience.
cn flag
@Alkalix That's a fair point; I updated my answer.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.