Skip to content
Menu
Open World News Open World News
  • Privacy Policy
Open World News Open World News

Category: News

Specbee: How to create custom tokens in Drupal

Posted on April 9, 2024 by Michael G
It’s stuff like these that make Drupal not just powerful, but also highly customizable and user-friendly. What are we talking about? Tokens! It’s one of the most versatile and super handy Drupal modules.​​ Sometimes, users need to establish a specific pattern to programmatically retrieve values. In these instances, tokens come to the rescue, providing a seamless solution. Read on to find out more about tokens and how you can create custom tokens for your Drupal website.

What are Tokens
Tokens in Drupal are primarily used for dynamically inserting data into content, such as user information, node details, or site settings. They make content more personalized and automated without manual intervention, streamlining the editing process and enhancing user experiences. For example, they can be used while sending emails during webform submissions or content moderation.
Before creating custom tokens you need to have the Drupal tokens module installed on your Drupal site. This contributed module already comes with some predefined tokens. These defined tokens can be used globally.

Steps to Create Custom Tokens
Step 1: Create a custom moduleTo create a custom token in Drupal, we either need to develop a new custom module or incorporate it into an existing one. For example, let’s name the module “Custom Token,” and the corresponding directory would be named “custom_token.” After creating this folder, we should generate a “custom_token.info.yml” file, where we’ll specify the module details.
name: Custom token
type: module
description: Provides custom tokens.
package: tokens
core_version_requirement: ^10Step 2: Clear the cacheAfter adding this code, clear the cache and refresh the page to apply the changes. Next, search for the custom token module and install it.

Step 3: Create the custom tokenOnce the module is installed, create a file named “custom_token.tokens.inc” within the folder. Inside this file, we’ll define the custom tokens. In the given scenario, there’s a webform for reviewing article content, and a link to this webform is added to the detailed page of articles. Now, the URL to the webform appears as follows:‘webform/contact_new/test?article=1’. The article field is also auto-filled based on the token.

Here, the article author is a hidden field that should auto-fill after form submission. Additionally, the article author is a field within the article content type. To dynamically retrieve this data, we need to create a custom token.
The code that will be added inside the “tokens.inc” file is provided below.
<?php
/**
* @file
* File to add custom token.
*/
use DrupalCoreRenderBubbleableMetadata;
/**
* Implements hook_token_info().
*/
function custom_token_token_info() {
  $types[‘article’] = [
    ‘name’ => t(‘Custom token’),
    ‘description’ => t(‘Define custom tokens.’),
  ];
  $tokens[‘article_title’] = [
    ‘name’ => t(‘Article title’),
    ‘description’ => t(‘Token to get current article title.’),
  ];
  $tokens[‘article_author’] = [
    ‘name’ => t(‘Article author’),
    ‘description’ => t(‘Token to get current article author.’),
  ];
  return [
    ‘types’ => $types,
    ‘tokens’ => [‘article’ => $tokens],
  ];
}
/**
* Implements hook_tokens().
*/
function custom_token_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  $replacements = [];
  if ($type == ‘article’) {
    $nid = Drupal::request()->query->get(‘article’);
    if ($nid) {
      $node_details = Drupal::entityTypeManager()->getStorage(‘node’)->load($nid);
    }
    foreach ($tokens as $name => $original) {
      // Find the desired token by name.
      switch ($name) {
        case ‘article_author’:
          if ($node_details) {
            $user_id = $node_details->field_author->target_id;
            if ($user_id) {
              $user_details = Drupal::entityTypeManager()->getStorage(‘user’)->load($user_id);
              $replacements[$original] = $user_details->name->value;
            }
          }
          break;
          case ‘article_title’:
          if ($node_details) {
            $replacements[$original] = $node_details->label();
          }
          break;
      }
    }
  }
  return $replacements;
}And this is how we can craft custom tokens to suit our specific needs. Once implemented, the webform results will seamlessly display the auto-filled value.

Final Thoughts
Drupal’s power lies not just in its functionality, but in its adaptability and ease of use. Tokens are an example of this versatility, since they offer a way to dynamically retrieve data as well as personalize content. Tokens streamline processes and improve user experience, whether they are used for user information, node details, or site settings.

Abstract methods and NotImplementedError in Ruby

Posted on April 9, 2024 by Michael G
Ruby’s NotImplementedError exception is often used as a placeholder in abstract classes for methods that should be implemented by subclasses. But did you know that this is not how this exception class was intended to be used?

20 years since “and we’re just starting”: undeadly.org turns 20 (2024-04-09)

Posted on April 9, 2024 by Michael G
It’s been 20 years since the first undeadly.org post appeared.

At that point in our history, we had been enjoying frequent updates to the OpenBSD Journal at the deadly.org site for more than four years, and most of us thought it was an April’s Fool prank when the the editors announced that they were ceasing publication, effective immediately on April 1st, 2004.

Fortunately, Daniel Hartmeier quickly realized the announcement was not a joke, and went to work on a functionally equivalent CGI binary written in C and negotiated to take over the archive of existing articles. The rescued (resurrected?) site went live at undeadly.org on April 9th, 2004.

At the time, the eagerly anticipated upcoming release was OpenBSD 3.5 (which we covered on April 30th of that year). As the release song strongly hints, the introduction of the CARP redundancy protocol was a major item in that release. The release also introduced the OpenBSD/amd64 platform, and included a number of improvements in hardware support and security, with privilege separation introduced in several daemons and important utilities. All the details can be had at the OpenBSD 3.5 release page.

It’s been 20 years, what have we got to show for it?

We hope you have been enjoying the site’s updates, and we hope that undeadly.org has been a positive factor in promoting all things OpenBSD. The site and its editors have every intention of going on running the site.

If you want to help out, please submit items about OpenBSD that you find noteworthy.

We value your submissions even more than your comments.

All the best from the undeadly.org editors.

Open Source AI Definition – Weekly update April 8

Posted on April 9, 2024 by Michael G
Stay updated with the co-design process of the Open Source AI Definition.

Intel’s ambitious Meteor Lake iGPU

Posted on April 9, 2024 by Michael G
Intel and AMD both tried to ship iGPUs fast enough to compete with low end discrete cards over the past 10 years with mixed results. Recently though, powerful iGPUs have been thrown back into the spotlight. Handhelds like Valve’s Steam Deck and ASUS’s ROG Ally demonstrated that consumers are willing to accept compromises to play games on the go. AMD has dominated that market so far. Valve’s Steam Deck uses AMD’s Van Gogh APU, and the ROG Ally uses the newer Phoenix APU. Unlike Van Gogh, Phoenix is a general purpose mobile chip with both a powerful CPU and GPU. Phoenix doesn’t stop at targeting the handheld segment, and threatens Intel’s laptop market share too. In response, Meteor Lake brings a powerful iGPU to the party. It has the equivalent of 128 EUs and clocks up to 2.25 GHz, making it modestly wider and much faster than Raptor Lake’s 96 EU, 1.5 GHz iGPU. Raptor Lake’s Xe-LP graphics architecture gets replaced by Xe-LPG, a close relative of the Xe-HPG architecture used in Intel’s A770 discrete GPU. At the system level, Meteor Lake moves to a GPU integration scheme that better suits a chiplet configuration where the iGPU gets significant transistor and area budget. I’ll be testing Meteor Lake’s iGPU with the Core Ultra 7 155H, as implemented in the ASUS Zenbook 14. I purchased the device myself in late February. ↫ Chips and Cheese I’m absolutely here for the resurgence in capable integrated GPUs, both for PC gaming on the go and for better graphics performance even in thinner, smaller laptops. I would love to have just a bit more graphics power on my thin and small laptop so I can do some basic gaming with it.

News & Views Live: मनोज-जरांगे पाटील यांना राजकीय पक्ष गृहीत धरत आहेत का? Loksabha Election 2024

Posted on April 8, 2024 by Michael G
Loksabha Election 2024 News & Views Live: मनोज-जरांगे पाटील यांना राजकीय पक्ष गृहीत धरत आहेत का?

#loksabhaelection2024 #maharashtrapolitics #maharashtranews #lokmat

Sachin Joshi with Ashish Jadhao Live

Subscribe to Our Channel
https://www.youtube.com/user/LokmatNews?sub_confirmation=1

आमचा video आवडल्यास धन्यवाद. Like, Share and Subscribe करायला विसरू नका!

मित्रांसोबत गप्पा मारताना विश्वसनीय, संशोधनावर आधारीत माहिती सादर करायची असेल तर लोकमतचे चॅनल सबस्क्राईब करा. कारण या चॅनलवर तुम्हाला पाहायला मिळतील अतिशय अभ्यासू, वेगळ्या अँगलच्या बातम्या ! राजकारण, क्राईम, मनोरंजन आणि क्रीडा क्षेत्रातील अनुभवी पत्रकार तुमच्यासाठी आणत आहेत दर्जेदार आणि जाणते करणाऱ्या बातम्या….

Click Here For Latest News & Updates►http://www.lokmat.com

To Stay Updated Download the Lokmat App►
Android Google Play: http://bit.ly/LokmatApp

Like Us On Facebook ► https://www.facebook.com/lokmat
Follow Us on Twitter ►https://twitter.com/LOKMAT
Instagram ►https://www.instagram.com/lokmat

Lokmat | epaper lokmat com | google lokmat | lokmat com | lokmat company | lokmat epaper app | lokmat online | lokmat live | lokmat marathi live | lokmat marathi live video | marathi batmya | marathi batmya live | batmya marathi live today | marathi news live | marathi news video | lokmat marathi batmya live | lokmat marathi breaking news | lokmat marathi batmya lava | lokmat marathi batmya channel | lokmat marathi batmya live youtube | marathi batmya video | lokmat marathi video live | lokmat marathi batmya live video | lokmat marathi live dakhava | lokmat marathi batmya live today | lokmat marathi batmya latest

Os robôs da Disney estão prestes a ficar (bem) mais impressionantes

Posted on April 8, 2024 by Michael G
Os robôs da Disney estão prestes a ficar (bem) mais impressionantes

Microsoft to open major new London AI hub in Paddington

Posted on April 8, 2024 by Michael G
London’s status as Europe’s foremost centre of excellence for artificial intelligence got a boost today after Microsoft unveiled plans for a major new AI hub in Paddington.

How to Install WordPress with Hestia Control Panel – ITQAVN.NET

Posted on April 8, 2024 by Michael G
How to Install WordPress with Hestia Control Panel – ITQAVN.NET
Link: https://itqavn.net/huong-dan-cai-wordpress-tren-hestiacp-hestia-control-panel/

First Indian record of the Neptis philyra species of butterfly identified through Wiki Loves Butterfly

Posted on April 8, 2024 by Michael G
Wiki Loves Butterfly (WLB), a field documentation and digital conservation project, has been run by a dedicated group of volunteers from India, who are passionate…
  • Previous
  • 1
  • …
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • …
  • 821
  • Next

Recent Posts

  • [TUT] LoRa & LoRaWAN – MikroTik wAP LR8 kit mit The Things Network verbinden [4K | DE]
  • Mercado aguarda Powell e olha Trump, dados e Haddad | MINUTO TOURO DE OURO – 11/02/25
  • Dan Levy Gets Candid About Learning How To Act Differently After Schitt’s Creek: ‘It’s Physically…
  • Building a Rock Shelter & Overnight Stay in Heavy Snow 🏕️⛰️
  • Les milliardaires Elon Musk et Xavier Niel s’insultent copieusement

Categories

  • Android
  • Linux
  • News
  • Open Source
©2025 Open World News | Powered by Superb Themes
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT