Posts

Showing posts from 2023

Drupal caching

 Use case1: You return data as a JSON API via an endpoint. Ex: /api/mydata. This data is fetched from a config form. Now, we have to cache the JSON API response and refresh it when the config form is updated. Code: $config = $this->config(MySettingsForm::my_config_name); $cacheMeta = new CacheableMetadata(); $cacheMeta->addCacheTags($config->getCacheTags()); $data = ['key' => 'value']; $response = new CacheableJsonResponse(json_encode([$data], JSON_UNESCAPED_SLASHES), 200, [], TRUE); $response->addCacheableDependency($cacheMeta); return $response; When this code is added to the controller, Drupal stores following cache id (cid) in cache_config table when the response is created for the first time. For subsequent requests the cached data is returned. When the config form is updated the cached data is refreshed using the cache id (cid) cache id: config:my_module.my_config_name 

Upgrade from D9 to D10

 Ngnix change: Change from: location @rewrite {     rewrite ^/(.*)$ /index.php?q=$1; } To: location @rewrite {     rewrite ^ /index.php; # For Drupal >= 7   }

Setting up SSH keys, Git to contribute to Drupal.org

SSH Keys:  https://www.drupal.org/drupalorg/docs/user-accounts/git-authentication-for-drupalorg-projects cd ~/.ssh ssh-keygen -t ed25519 -b 4096 -C " drupalcode.org " Enter the filename. Ex:  id_ed25519_drupalcode_org ssh-add ~/.ssh/ id_ed25519_drupalcode_org vim  id_ed25519_drupalcode_org.pub copy the contents and create a new key at  https://git.drupalcode.org/-/profile/keys Test:  ssh -T git@git.drupal.org You can also add ssh config file  vim ~/.ssh/config Save the below contents Host git.drupal.org   AddKeysToAgent yes   IdentityFile ~/.ssh/id_ed25519_drupal_org Configuring Git: https://www.drupal.org/docs/develop/git/setting-up-git-for-drupal/configuring-git-for-drupal Note: Configure your name and email address https://www.drupal.org/user/<your-id>/git Committing: Make sure username and email are correct in the folder you are committing > git config --list   credential.helper=osxkeychain init.defaultbranch=main user.email= gop...