Specbee: Have you leveraged Drupal’s Computed Field Module yet? – Get started now with this quick guide

Planet Drupal - 11 hours 43 min ago
Have you leveraged Drupal’s Computed Field Module yet? – Get started now with this quick guide Sahana N 10 Dec, 2019 Top 10 best practices for designing a perfect UX for your mobile app

Computed Field Module is extremely beneficial to a Drupal developer at various events. There are times when you have tons of Fields, a few of which can be consolidated into one field. Sometimes, you might need a field that is a computation of two or more fields, which does not need user inputs. Or you might just want to store the current user’s data directly into the database. 
When you want to populate content automatically without user inputs in Drupal, we can leverage the Computed Field Module for Drupal 8. This module is a very powerful field module that allows us to insert custom calculated/computed fields via PHP code. These values can be either stored directly in the database or can be calculated while using node views. 

This module comes with a security warning as the custom code entered in the field is going to be saved in the database. Adding PHP code in the text area (“Insert your working code here”) without the use of Hooks in custom modules, is a huge threat to the security of your website. This module is recommended to be used by developers with good skills and knowledge in PHP and Drupal APIs. It is also recommended that you first test your PHP code in the Body field of a Drupal page.

Installing the Drupal 8 Computed Field Module:

Initially, you will need to download the Drupal Computed Field module from this link - or you can  Install with the Composer :  composer require 'drupal/computed_field:^2.0'

Once you have installed the module, navigate to extent and enable the Computed field module. 

               Figure 1- Enable the Computed Field ModuleUsing Computed Field to automatically populate content

Step1 - Once you have enabled the module, navigate to Structure -> content- type -> select your content type. For now, I have selected the Article content type.

Step 2 - Go to Manage fields, add field of type Computed field. There are 5 types of computed fields - 

  • Computed (decimal): This field automatically populates as decimal value based on the php code.
  • Computed (float): This field automatically populates a floating value based on the php code.
  • Computed(integer): This field automatically populates an integer valued based on the php code. 
  • Computed (text): This field automatically populates a string values based on the php code.
  • Computed (text, long): This field is the same as Computed text but takes more text.
           Figure 2 - Select the Field Type

Time to Try it out! Let us now automatically calculate and populate the age of a person based on their Date of Birth that the user has entered.

Step 3 -  First, we will have to add the Computed Field. In our case I am going to calculate the Age of a person so I will add the field by navigating to 
Configuration -> Account settings -> Manage fields. Lets’ select the Computed (integer) field to populate the Age automatically.

             Figure 3 - Add the Computed (integer) Field

When we add the Computed (integer) field and give a Label (name of the calculated field), click on Save. We will then see this window as shown in the image below.

            Figure 4 - Setting up the Drupal Computed Field


Step 4 -  In the settings window, you can add an optional Help text that instructs the user on what the calculated field value is about. The most important part, however, is the text-area called “Code (PHP) to compute the integer value”. Here is where we write the custom code to calculate the Age (in this case). Below the text area you will see some security warnings and some suggestions/recommendations. Also mentioned are a few example variables that can be used in the PHP code. In our case, I am going to write the PHP custom code to calculate Age in the PHP code text area. To automatically populate the Age.

           Figure 5 - Calculating the Age within the PHP Code text area

Inside the PHP code text area, we can also use “if” conditions to populate the content automatically.

Step 5 - After writing the custom code for the Compute Field, hit the save button. Next, lets’ test this by entering the Date of Birth.

           Figure 6- Entering the Date of Birth


Step 6 - After saving the content the Age will be populated automatically (as shown in the image below)

           Figure 7 - Calculated Age presented to the user

This is a very simple example of using the Drupal 8 Computed Field Module but similarly you can populate values with various types of computations and custom code. 

The Computed Field module is a very useful module in Drupal 8 that proves handy in various scenarios. Especially when you need to populate a field whose value depends on a computation of two or more fields. However, the module also comes with its own security risks since it allows for PHP code to be inserted via a Web user interface. Hence, it is always recommended to be used and implemented by developers with sound skills in PHP and Drupal. There are other similar modules like the Views PHP (Drupal 7), the Math Field (for Drupal 7) and the Field Token Value modules. Nonetheless, the Drupal Computed Field Module is exactly what you need sometimes. 

We are a leading Drupal development company and amongst the top contributors to the Drupal community. We would love to know more about your next Drupal project! Contact us now.

Drupal Planet Shefali ShettyApr 05, 2017 Subscribe For Our Newsletter And Stay Updated Subscribe

Leave us a Comment

  Shefali ShettyApr 05, 2017 Recent Posts Image Have you leveraged Drupal’s Computed Field Module yet? – Get started now with this quick guide Image How these Drupal SEO Modules (and tips) can boost your Website Ranking Image A quick guide to Drupal Sitemaps (and why you need one) Looking to optimize your Drupal site for SEO in the best way possible ? Talk to us Featured Success Stories

Know more about our technology driven approach to recreate the content management workflow for [24]


Find out how we transformed the digital image of world’s largest healthcare provider, an attribute that defined their global presence in the medical world.


Develop an internal portal aimed at encouraging sellers at Flipkart to obtain latest insights with respect to a particular domain.

Categories: Drupal

Minecraft update brings cross-platform play to PlayStation 4

Social/Online Games - Gamasutra - 9 December 2019 - 12:24pm

Microsoft-owned Mojang has received the go-ahead to give PlayStation 4 players the ability to play alongside those playing on Xbox One, Switch, and mobile. ...

Categories: Game Theory & Design

Video: Writing for Lord Shaxx, Destiny's supportive space coach

Social/Online Games - Gamasutra - 9 December 2019 - 12:20pm

At GDC 2019 Bungie's Jonathan To discusses Lord Shaxx's creation as Crucible announcer in the Destiny series, and how the character grew from supporting character to fan favorite. ...

Categories: Game Theory & Design

Establishing Vision - by Stanislav Costiuc Blogs - 9 December 2019 - 8:23am
When starting out to develop a game, it is very important to set up a structured creative direction during pre-production. One of the most needed elements is a strong vision, which we're going to discuss here.
Categories: Game Theory & Design

Kliuless #61: Sony's First 25 Years - by Kenneth Liu Blogs - 9 December 2019 - 8:22am
Each week I compile a gaming industry insights newsletter that I publish broadly. Opinions are mine.
Categories: Game Theory & Design

Writings on the Wall: Sharing Accessible Narratives Through Environmental Design - by Sukhraj Johal Blogs - 9 December 2019 - 8:22am
How can designers leverage the environment in their games to share accessible narratives to players? This article examines how The Last of Us, God of War (2018), and Inside create compelling narratives through environmental design.
Categories: Game Theory & Design

Video game purism and mixed media. - by arne neumann Blogs - 9 December 2019 - 8:20am
A historical look at video games, how they went from simple interactive games to incorporating traditional forms of media and where the current technological developments might lead us.
Categories: Game Theory & Design

Narrative Design and Videogame Writing for Screenwriters - by Sande Chen Blogs - 9 December 2019 - 8:17am
In this article, game writer Sande Chen reports on NYU Game Center Professor Clara Fernandez-Vara's narrative design master class at the Writers Guild of America, East.
Categories: Game Theory & Design

Understanding player behavior - What to read - by Henri Brouard Blogs - 9 December 2019 - 8:17am
Five books to read to better understand player psychology and behavior.
Categories: Game Theory & Design

How Audio Design Enhances Diablo 2 - by David Craddock Blogs - 9 December 2019 - 8:16am
Diablo 2's audio team reflects on what the game's soundscape brought to Blizzard North's legendary sequel.
Categories: Game Theory & Design

Yandex motnya Christmas garland

New Drupal Modules - 9 December 2019 - 8:15am

Christmas garland

Categories: Drupal

Creating Customization in Game Design - by Josh Bycer Blogs - 9 December 2019 - 8:14am
Customization is a powerful option to give games depth, but it requires a careful eye when it comes to balancing an ever-growing number of choices.
Categories: Game Theory & Design

Week One, Day One - by Jose Pablo Castro Jimenez Blogs - 9 December 2019 - 7:50am
First post in a series on how I am tracking a rooky indie game creator journey
Categories: Game Theory & Design

Emotional Context In Decision Design - by Artur Ganszyniec Blogs - 9 December 2019 - 7:49am
Wanderlust Travel Stories is an anthology of interactive travel literature we published in fall 2019. In this article, I share how we used context and personal perspective to make choices relevant for the player and easier to implement.
Categories: Game Theory & Design

Historians play Tannenberg - by Bob Whitaker Blogs - 9 December 2019 - 7:48am
Historians Bob Whitaker and Chris Kempshall play and discuss the multiplayer WWI game Tannenberg. Topics include the Battle of Tannenberg, the Eastern Front in WWI, and the recent history of First World War games more generally.
Categories: Game Theory & Design

Webform Navigation

New Drupal Modules - 9 December 2019 - 7:37am

The goal of this module is to provide the ability to navigate forward and backward through a web form using the Webform Progress tracker (aka wizard progress bar) supplied by the webform module on multi-page web forms. It also allows for the ability to bypass validation when the user presses the "next" button as they navigate through the form.

Categories: Drupal

Recommend nodes

New Drupal Modules - 9 December 2019 - 7:28am

This project is for the node recommendation.

Categories: Drupal

Zivtech: Why You Should Upgrade to Drupal 8 (Even With Drupal 9 On the Way)

Planet Drupal - 9 December 2019 - 5:30am

With Drupal 9 set to be released later next year, upgrading to Drupal 8 may seem like a lost cause. However, beyond the fact that Drupal 8 is superior to its predecessors, it will also make the inevitable upgrade to Drupal 9, and future releases, much easier. 

Acquia puts it best in this eBook, where they cover common hangups that may prevent migration to Drupal 8 and the numerous reasons to push past them.

The Benefits of Drupal 8

To put it plainly, Drupal 8 is better. Upon its release, the upgrade shifted the way Drupal operates and has only improved through subsequent patches and iterations, most recently with the release of Drupal 8.8.0

Some new features of Drupal 8 that surpass those of Drupal 7 include improved page building tools and content authoring, multilingual support, and the inclusion of JSON:API as part of Drupal core. We discussed some of these additions in a previous blog post

Remaining on Drupal 7 means hanging on to a less capable CMS. Drupal 8 is simply more secure with better features.

What Does Any of This Have to Do With Drupal 9?

With an anticipated release date of June 3, 2020, Drupal 9 will see the CMS pivot to an iterative release model, moving away from the incremental releases that have made upgrading necessary in the past. That means that migrating to Drupal 8 is the last major migration Drupal sites will have to undertake. As Acquia points out, one might think “Why can’t I just wait to upgrade to Drupal 9?” 

Read more
Categories: Drupal

World of Mappers, Part 1 - by James Deighan Blogs - 9 December 2019 - 4:43am
Usually, all the cartridges in our retro game collections look pretty much the same from the outside. But are they the same inside?
Categories: Game Theory & Design Blog: Our blog posts from November 2019

Planet Drupal - 9 December 2019 - 3:03am

The year has come to a close - and what a year it has been! For Agiledrop as well as for Drupal, this has been a truly amazing and successful year - and yet, we feel it is only a prelude to all that’s coming in 2020. To properly end the year, here’s a recap of all our posts from last month - enjoy!

Categories: Drupal


Subscribe to As If Productions aggregator