Don't Understand Drupal Code

by M Pabilona   Last Updated January 13, 2018 23:07 PM

I'm completely new to Drupal module development and am struggling to understand the basic code in Drupal. I followed tutorials on how to create a module and was successful in building a couple simple ones that just creates a page with some hardcoded data. Now my struggles is when reading other modules that were contributed.

Take for example the code below I got from an entity php in the contributed Commerce module:

public function getFieldMap($variation_type_id = NULL);

public function clearCaches();

/**
* Creates an attribute field for the given attribute.
*
* @param \Drupal\commerce_product\Entity\ProductAttributeInterface $attribute
*   The product attribute.
* @param string $variation_type_id
*   The product variation type ID.
*/
public function createField(ProductAttributeInterface $attribute, $variation_type_id);

public function canDeleteField(ProductAttributeInterface $attribute, $variation_type_id);

I just picked a couple functions. I see these functions above getting declared, but I don't see anywhere any of the functions are called. My understanding of Object Oriented Programming is you create a Class, and within that Class you can have Methods and Properties. But when you declare Methods or Properties, shouldn't these properties be called to be used or utilized? Does Drupal call these declared functions by default so any function you create in your controller, php files, entity files get called by Drupal?

I also see some php files in Drupal where there's just a bunch of "Protected $Variable", which I don't get why it's being declared in one file, but not sure where it's being called.

Is Drupal code different and has a certain way of working? Please no criticism on how stupid my question can be. I'm not asking for a lecture, but just for a brief explanation. I sincerely appreciate any answers you can provide. I just need to get a basic understanding of how codes in a module work exactly. I've been to many tutorials and read a lot on Drupal.org, but haven't really come across a resource I could understand.

Thank you for your time.

Tags : entities


Related Questions




How to create a custom template for entities?

Updated April 07, 2015 03:03 AM


Drupal 8 Custom Entities from a UI?

Updated July 14, 2015 15:03 PM