Drupal general concepts that you should know

namespace:

In simple terms, think of a namespace as a person's surname. If there are two people named "John" you can use their surnames to tell them apart.
https://stackoverflow.com/questions/3384204/what-are-namespaces

  • Solve the issues of resuable code such as classes or functions.

namespace example:
the file foo.txt can exist in both directory /home/greg and in /home/other, but two copies of foo.txt cannot co-exist in the same directory. In addition, to access the foo.txt file outside of the /home/greg directory, we must prepend the directory name to the file name using the directory separator to get /home/greg/foo.txt. This same principle extends to namespaces in the programming world.

  • Avoids namespace collisions

Name collisions example: 
you create a function named db_connect, and somebody elses code that you use in your file (i.e. an include) has the same function with the same name.

To get around that problem, you rename your function SteveWa_db_connect  which makes your code longer and harder to read.

Now you can use namespaces to keep your function name separate from anyone else's function name, and you won't have to make extra_long_named functions to get around the name collision problem.

So a namespace is like a pointer to a file path where you can find the source of the function you are working with.


Services:

A piece of global functionality. 
Its a class. 
Services are put into dependancy injection container to be used by other modules.

Example: access database, send email

Plugins:

Plugins are small pieces of functionality that are swappable
Drupal8 plugins vs Drupal7 hook
plugins are an OO replacement for info hooks and any hook associated with an info hook.

Comments

Popular posts from this blog

Programatically create layout builder section in Drupal

Code quality analysis of Drupal. Can I use Sonar?

Set up Drupal7 to Drupal8 migration in simple steps (using Drush)