This forum is for module development and code related questions, not general module support. For general support, use the Post installation forum.

What to use instead of a global const in procedural code?

I have something like the following in mymodule.module:

const MYMODULE_CONST = 42;

/**
 * Implements hook_myhook().
 */
function mymodule_myhook($route_name, RouteMatchInterface $route_match) {
  return(t('The answer is @const', ['@const' => MYMODULE_CONST]));
}

This is the only place I use this constant. The reason for using a PHP global const for this is to have it defined near the top of the file for easy spotting and replacement. So having it as a value inside the function is not an option.

7.72 Upgrade Caused Problem With Form #STATES.

All,

Summary: In 7.72, AJAX Callbacks affect "AND" conditional of FAPI fields that use #STATES

Routing issue

Hello there! I am trying to get used to the new way drupal 8/9 does things (I am an avid d7 developer), but having trouble finding proper documentation. 

So I am building an invoicing system for a client, and I have two routes setup in my invoicing.routing.yml file, as shown below

Using hook_entity_view_alter(), want to change the filed's title(label) with certain display_id

I've been trying to display netId through the display on the view.

So, I used hook_entity_view_alter to alter the title of the field and the field_content to be the netId.

But it doesn't seem to be working.
So, my question is 

1) Is $display->id() a machine_name of the display?

2) Is there any better way to go about?

function directories_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {

  if ($display->id() != 'team_directory') {

    return;

How to create an invitation system by email ?

Hi, I want to make a very simple custom module for users to send email invitations with templates.

Here is a module that I started :

https://git.drupalcode.org/sandbox/zenimagine-3170712/-/tree/main

Currently this module creates a blank page /user/ID/invitation

How to create an "Email address" field and a template selector ?

The "Email address" field must not keep the addresses in the database.

How to display the rendered entity of a store in a code ?

Hi, I have created a small module to display an "Agree to Terms" link in the Drupal Commerce shopping tunnel.
This link displays the store's condition page.
I want to display the rendered store entity instead of the conditions page. How to do this ?
I created in my type of store, a display named "Terms and conditions". I want to make this display in a modal window when the user clicks on the link.

Here is my code :

https://git.drupalcode.org/sandbox/zenimagine-3082137

Pages

Subscribe with RSS Subscribe to RSS - Module development and code questions