PreviousNext: Using Drupal's Entity Definition Update Manager to add bundle support to an existing content entity

Planet Drupal - 4 November 2019 - 7:11pm

On a client project we were using a custom Drupal content entity to model some lightweight reusable content.

The content entity was originally single use and did not support bundles (e.g. node entities have node-type bundles).

As the project evolved, we needed to add bundle support for the custom entity-type, despite it already being in production use.

Read on to find out how we achieved this.

by Lee Rowlands / 5 November 2019

In this example, lets call the content entity a 'set' and the bundles a 'set type'.

Create the bundle configuration entity

As we wanted this content entity to support adding new bundles via the UI, a configuration entity makes sense to allow site-builders to create the various bundles as required, so we created a new configuration entity called 'set type' as per the examples, although we used a route provider instead of a routing file. We made sure to add the bundle_of annotation to the config entity.

bundle_of = "set",Updating the content entity's annotation and fields

Once this was done, the next step was to update the content entity's annotation. We added the 'bundle' key and the 'bundle_entity_type' annotation

bundle_entity_type = "set_type", * entity_keys = { * "id" = "id", * "label" = "name", * "uuid" = "uuid", * "uid" = "user_id", * "bundle" = "type", * "langcode" = "langcode", * },

We didn't need to add a new field for our baseFieldDefinition to our content entity because we just deferred to the parent implementation. But we made sure to match up the description, label etc as desired - and that we called setInitialValue. As we're planning to add a new column to the entity's tables in the database, we need to populate the type column for existing records. Now with entities that don't support bundles, Drupal defaults to the entity ID for the bundle. e.g. for the 'user' entity, the bundle is always 'user' because User entities don't support bundles. So we knew our existing 'set' entities would have to have a bundle of 'set' too. But our new ones could have whatever we liked. So this is why our field definition for 'type' had to have look like so

$fields['type']->setInitialValue('set')Update hooks to get everything in place

Since Drupal 8.7, support for automatic entity updates has been removed, so whilst adding the field, entity keys and updating the annotation works for a new install (hint, there won't be one) it doesn't help our existing production and QA sites - so we need an update hook to bring our existing entity-type and field definitions into sync with the code versions, which also takes care of the required database table changes.

So the steps we need to do here are:

  1. install the config entity type
  2. create a new instance of it for the existing entities
  3. add the new field definition for the type field to the content entity
  4. update the content entity definition
Installing the config entity type

The docs for installing a new entity type make it clear what we need to do. Our code ended up something like this:

/** * Adds the set type. */ function your_module_update_8001() { \Drupal::entityDefinitionUpdateManager() ->installEntityType(new ConfigEntityType([ 'id' => 'set_type', 'label' => new TranslatableMarkup('Set type'), 'label_collection' => new TranslatableMarkup('Set types'), 'label_singular' => new TranslatableMarkup('set type'), 'label_plural' => new TranslatableMarkup('set types'), 'label_count' => [ 'singular' => '@count set type', 'plural' => '@count set types', ], 'handlers' => [ 'list_builder' => 'Drupal\your_module\SetTypeListBuilder', 'form' => [ 'default' => 'Drupal\your_module\Form\SetTypeForm', 'delete' => 'Drupal\Core\Entity\EntityDeleteForm', ], 'route_provider' => [ 'html' => 'Drupal\Core\Entity\Routing\AdminHtmlRouteProvider', ], ], 'admin_permission' => 'administer set type entities', 'entity_keys' => [ 'id' => 'id', 'label' => 'name', ], 'links' => [ 'add-form' => '/admin/structure/sets/add', 'delete-form' => '/admin/structure/sets/manage/{pane_set_type}/delete', 'reset-form' => '/admin/structure/sets/manage/{pane_set_type}/reset', 'overview-form' => '/admin/structure/sets/manage/{pane_set_type}/overview', 'edit-form' => '/admin/structure/sets/manage/{pane_set_type}', 'collection' => '/admin/structure/sets', ], 'config_export' => [ 'name', 'id', 'description', ], ])); }Creating the first bundle

In our first update hook we installed the config entity, now we need to make one for the existing entities, because bundle-less entities use the entity type ID as the bundle, we make sure our new type has the same ID as the entity-type.

/** * Adds a new config entity for the default set type. */ function your_module_update_8002() { $type = SetType::create([ 'id' => 'set', 'name' => 'Set', 'description' => 'Provides set panes', ]); $type->save(); }Adding the new field definition and updating the entity definition

The documentation for adding a new field definition is again very useful here, so we follow along to install our new field definition. And similarly the documentation for updating an entity type here, so our final update hook looks like this:

/** * Updates defintion for set entity. */ function your_module_update_8003() { $updates = \Drupal::entityDefinitionUpdateManager(); $definition = BaseFieldDefinition::create('entity_reference') ->setLabel('Set type') ->setSetting('target_type', 'set_type') ->setRequired(TRUE) ->setReadOnly(TRUE) ->setInitialValue('set') ->setDefaultValue('set'); $updates->installFieldStorageDefinition('type', 'your_module', 'your_module', $definition); $type = $updates->getEntityType('your_module'); $keys = $type->getKeys(); $keys['bundle'] = 'type'; $type->set('entity_keys', $keys); $type->set('bundle_entity_type', 'pane_set_type'); $updates->updateEntityType($type); }

And that's it we're done.

Wrapping up

Kudos to those who created the documentation for this, as well as my colleagues Sam Becker, Jibran Ijaz and Daniel Phin who helped me along the way. Hopefully, you find this post useful if you're ever in the same boat.

Tagged Content entities, Drupal 8, Entity Definition Update Manager, Bundles
Categories: Drupal

Another major streamer leaves Twitch, this time for YouTube

Social/Online Games - Gamasutra - 4 November 2019 - 2:52pm

Several notable names in streaming departed Twitch to exclusively set up shop on competing platform Mixer over the last month or so, and it looks like that light Twitch exodus is yet ongoing. ...

Categories: Game Theory & Design

Jeff Kaplan: Leaks impact developer morale more than anything else

Social/Online Games - Gamasutra - 4 November 2019 - 1:27pm

Overwatch game director Jeff Kaplan explores the impact leaks have on developers when high-profile announcements are uncovered before their big planned reveal. ...

Categories: Game Theory & Design

Section Purger

New Drupal Modules - 4 November 2019 - 12:54pm

This module allows Section’s global, distributed caching layer to quickly respond to invalidation events from a Drupal instance in exactly the same way that Drupal’s internal cache or a local varnish cache running on the host machine does, ensuring that the content in Section’s global caching layer is always up to date.

Categories: Drupal


New Drupal Modules - 4 November 2019 - 12:24pm

A SmartThings SmartApp for Drupal integration of device values.

This module provides drupal fields containing the real-time value of SmartThings device values. It contains a webhook (SmartThings SmartApp) that connects to a SmartThings Hub using the SmartThings API.


Categories: Drupal

Inline Block Title Automatic - Symmetric Translation

New Drupal Modules - 4 November 2019 - 12:05pm

This module enhances Inline Block Title Automatic, making it compatible with Layout Builder Symmetric Translations. When this module is enabled, content authors are no longer required to provide a title when translating a custom block.

This module, like Layout Builder Symmetric Translations, is a stopgap until layout builder translation lands in core.

Categories: Drupal

Video: Addiction science and advice for devs on promoting healthy play

Social/Online Games - Gamasutra - 4 November 2019 - 11:58am

In this 2019 GDC talk Oxford's Andrew Przybylski explains why the APA and the WHO have called for studies investigating video game addiction, and what devs can do to help promote healthy play. ...

Categories: Game Theory & Design

Hook 42: Drupal Core Initiative Meetings Recap - October 28 - November 01, 2019

Planet Drupal - 4 November 2019 - 10:30am
Drupal Core Initiative Meetings Recap - October 28 - November 01, 2019 Lindsey Gemmill Mon, 11/04/2019 - 18:30
Categories: Drupal

Improbable and Tencent Cloud team up to help devs bring games to China

Social/Online Games - Gamasutra - 4 November 2019 - 9:13am

Improbable's partnership with Tencent Cloud both brings its platform to devs in China and sets up a program to aid teams to build games for the Chinese market. ...

Categories: Game Theory & Design

Acro Media: Making Drupal Code Standards Work for You With PhpStorm & phpcs/phpcbf

Planet Drupal - 4 November 2019 - 7:45am
A proactive approach for cleaner Drupal coding

So you are stuck in the cruft, struggling to create some semblance of sanity within a sea of code-rot. Code standards sound like a great idea for your project, but perhaps automated enforcement tools look like more of a pain than they're worth. This post is intended for Drupal developers using PhpStorm who need fast, flexible, standards enforcement tools.

Maintaining a stringent standard for your codebase is a battle. On one hand, your code is cleaner, more unified, and easier to maintain. On the other hand, these little formatting rules cause frustration and time loss - especially if a tiny slip causes you to waste a full pipeline cycle just to pass an automated standards check. As they say, the best defence is a strong offence, and the tools proposed here will help you find and fix standards violations before they reach a pipeline.

Drupal recommends a tool called PHP Code Sniffer, aka phpcs, to scan your files for Drupal Code Standards violations. Thankfully, it also comes with a companion tool called PHP Code Beautifier and Fixer, aka phpcbf, which fixes the small, tedious violations for you.

The goal of this post is to get phpcs and phpcbf under your fingertips and into your habits. Only once you have hotkeys set-up to run these tools while coding will they become useful — instead of just annoying.

The steps are as follows:

  1. Install and set-up phpcs
  2. Create a custom combination of rulesets
  3. Integrate with PhpStorm for hotkeys and syntax highlighting
1. Install and set-up phpcs

It may seem straightforward to install phpcs globally via Composer or apt, or to simply require it in your current composer project. However, a global install is not easy to customize and share. Instead, I recommend using a standalone repo that is specifically for your code standards tools. When your standards stand alone, they are easier to edit, share with teammates, and transfer to new work environments.

Here’s a simple repo to get you started:

  1. If you currently have phpcs or phpcbf installed globally, uninstall them before proceeding.

  2. Quick install with example repo:

    git clone
    cd drupal_code_standards
    composer install
  3. Once composer has installed phpcs for you, add it to your global path with:

    export PATH=$PATH:~/PATH/TO/drupal_code_standards/vendor/bin
    NOTE: Adjust accordingly for your shell and OS of choice.

  4. Next, you must tell phpcs which rulesets you have installed use.

    The optional tool phpcodesniffer-composer-installer will automatically detect rulesets in your composer package and set your phpcs & phpcbf installed_paths for you. This is part of the example repo and the next step should have been done for you during "composer install".

    However, to set installed paths to rulesets manually run:

    phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer,vendor/phpcompatibility/php-compatibility/PHPCompatibility

    Then confirm that phpcs knows about the rulesets within the installed paths with:

    phpcs -i

    You should see this list that confirms your rulesets:

    The installed coding standards are ... PHPCompatibility, Drupal and DrupalPractice

    You may need to set installed paths for phpcbf as well using the same process.

2. Create a custom combination of rulesets

Out of the box, phpcs can only run one standard at a time. This is a problem when working with Drupal because we have 2 standards to follow. For this post I have added a third standard, PHPCompatibility, which is helpful when upgrading php versions on legacy projects.

  1. To combine standards we first create a custom ruleset that references multiple rulesets. Note that this is already included in the example repo as phpcs-custom-standards.xml.

    <?xml version="1.0"?>
    <ruleset name="Custom code standards">
    <rule ref="Drupal"/>
    <rule ref="DrupalPractice"/>
    <rule ref="PHPCompatibility"/>
  2. Then set this standard as your default. Use an absolute path to ensure your standard will be found no matter what context phpcs is called from.

    phpcs --config-set default_standard ~/PATH/TO/drupal_code_standards/phpcs-custom-standard.xml See the example standard for a few other helpful settings.
3. Integrate with PhpStorm for hotkeys and syntax highlighting

There are two levels of integration with PhpStorm: Passive and Active.


Passive code analysis with PhpStorm Inspections will give you syntax highlighting and hover-over explanations of the file you are currently working on.

This is quite helpful when dealing with one file at a time, but when you need to get an entire directory to pass standards, you need a way to hunt for violations.


Active analysis when you use phpcs to scan many files at once. You can do this through the terminal with a command like:

phpcs ~/module # Scans all applicable files in dir.
phpcs ~/module/example.php # Scans only a specific file.

However, it’s a pain to open a terminal window, navigate to the file you are working on, and then type a command. You’ll probably forget or neglect to check your work because of these extra steps involved. A better way to run phpcs is to set-up hotkeys within PhpStorm to scan your files instantly.

Configure PhpStorm inspections
  1. Register phpcs and phpcbf as PHP Quality Tools.

    Settings | Languages and Frameworks | PHP | Quality Tools | Code Sniffer

  2. Enable the inspection.

    Settings | Editor | Inspection | PHP | Quality Tools

  • Set the extension list to match what Drupal standard sets: source

  • DO NOT set the "Installed standard paths", as this overrides what you have previously set in the command line.
  • The refresh list button on "Coding Standard" should mimic what "phpcs -i" shows. Choose "Custom" Coding Standard and then click the ellipses to choose the path to your custom standards file (i.e. phpcs-custom-standards.xml).
  • Click OK and your inspections should be working!
Configure hotkeys
  1. Register phpcs and phpcbf as external tools.

    Settings | Tools | External Tools

    The "$FilePath" argument runs the tool against the file you are currently working on, or against a selected folder when in project view.

  2. Double check that this step works by running the tool from the main menu.

    Tools | External Tools | phpcs

  3. This is the special sauce. Configure a keyboard shortcut for your new tools.

    Settings | Keymap | External Tools

  4. Right click on the external tool you just registered and add a keyboard shortcut. "Ctrl+Alt+Shift+Comma" was simply a combination that was not used anywhere else in my setup.

Bringing it all together

Now you can actively use phpcs and phpcbf while you code! I frequently use the phpcbf hotkey while writing new code to do the tedious stuff for me, such as creating doc blocks and pushing whitespace around. Here's an example:

With phpcs and phpcbf now under your fingertips you are set to be much more assertive in your application of code standards!

Taking it to the next level

If you are using Gitlab for CI/CD, which I hope you are, another great strategy for enforcing standards is to create a pre-deployment job that scans your custom code for violations. This will keep your team (and you) in check by stopping standards violations from being auto-deployed.

After a few super annoying pipeline failures for minor syntax errors, you will want this next level of enforcement — git pre-commit hooks. I highly recommend using grumphp to manage this for you.

Best of luck keeping your code readable and up to snuff!

End-to-end Drupal services

As a full service Drupal agency, Acro Media has significant expertise in digital commerce architecture, ecommerce design, customer experience, software development and hosting architecture. If you’re looking for a Drupal agency dedicated to code and project quality, check us out. We would love the opportunity to talk.

Categories: Drupal

The Art Of Traps: Making The Rogue Cry

Gnome Stew - 4 November 2019 - 7:32am

Even the simplest of traps can be lethal when done right.

Traps. We all know what they are and how they work. Bait something with the proverbial carrot, the machinations whir, boom! Trap sprung, prey caught. Simple enough in theory but have you ever looked at your traps and wondered, “Gee, this isn’t a very good trap! What am I doing wrong?” Well I’m going to dissect your problems and show you the correct way to go about trap-making to the point your rogue curl into a ball and learn to fear your evil reign whenever you even mention a pressure plate!

To make the best traps, you have to follow a few rules that seem obvious but are often forgotten. As much as you might think that your trap is perfect, you have to remember that three or more people will be actively trying to solve your clever tricks by either bashing it, brute forcing through it, deactivating it, or simply ignoring it. Traps have to be made with the party in mind. Some will excel at trap busting and can speed-run through a mega dungeon in one session if they are good enough. Others will struggle with any kind of trap you throw at them and forget they can actually take the time to search around them or use their resources creatively. Knowing your party’s strengths and weaknesses is half the battle with actually making the traps the true challenge you’ll be facing. Of course, this can vary greatly depending on what characters you are GMing.

So before I mention anything else, I have to bring up the rogue. Why? In most games that have a rogue or rogue-like character, they tend to be the most dextrous and the most adept at finding traps and disabling them. Some even go to great lengths to excel at this type of skill set and become trap maniacs, hoping that the Perception checks they make every five minutes will reveal something for their spidery little hands to mess around with. Varying on what system you are playing, the rogue will most likely be your sworn enemy if you are a trap-loving GM. Go beyond my suggestions because those rogues will ruin. Your. Day.

Go beyond my suggestions because those rogues will ruin. Your. Day. Share13Tweet1Reddit1Email

The first and biggest rule you have to remember about traps is that they can’t be solved by just a roll of the dice. Imagine. You are going through a dungeon with your group, hoping to set off a pitfall trap on them when the party rogue uses a Spot or Perception check to look around. They roll. They succeed. The trap has been ruined in a short minute and they navigate about it in one way or another. A simple example but one seen too often. If you’re going to be setting up traps, you have to make it more advanced than that.

Layering on traps can be an effective tool for this issue, having the party focus on one trap when pow! Another trap activates right after they think they’ve solved the first one! If you’re in a bind with simpler traps, like when using kobold or goblin enemies, have them roll more dice instead. Layers of camouflage covering different sections of the trap or multiple aspects and mechanical parts can require several rolls being involved to deactivate it. Even if they get one part right, they will still have more chances to fail, giving the trap more presence and an actual risk involved. Do they risk setting it off at that point? Do they try another route? This gives some interesting decisions and can dynamically change a dungeon layout. Using one easily passable trap to trick the party to set off another one is also a great method. A pitfall that has a hidden pressure plate right after you cross it is a great example. A good rule of thumb when doing this however is to consider how much it will take to beat the trap in question and will it be worth it for your particular party to interact with.

The next thing to consider is how many traps you place in your campaign. One trap, two traps, three thousand traps, the same thing will always happen. Once that first trap happens, the rogue goes Perception super sleuth and slogs the party down by demanding a new roll every ten feet they move. Nobody likes this and much less you who might have eight or so traps in the dungeon still waiting. It’s a tiring process and even if in character they don’t do this, there is a lingering overhead thought amongst the group of the possibility of more traps. It’s always a difficult task to balance out meta knowledge in your groups but a few simple tricks can help alleviate this.

Having your party deal with traps only once in awhile and in specific places like dungeons and ruins is the easiest solution and can actually be used to perk up some of the less involved members in a group too. Sometimes the biggest trap can be the illusion that you have a trap readied for them, though this can backfire easily with more paranoid players. You can also give those who do constant trap checking a bit more leeway when looking for traps. If they roll to check for traps in say a normal room, you can give them one check and describe that the whole room is safe even if they might just be doing just one area. Not only does it hasten the pace but requires less work to describe the area and can ease tensions for the group. Keep in mind that you should aim to create a balance for your group so that they will actually move more than fifty feet in a session but still be wary of situations you present to them. This takes at least a few trial traps to see how they react but you’ll eventually learn what’s good for them and use that knowledge to improve your future sessions.

Explosion traps are fun, but the fourth one in a row gets boring.

Pitfalls are fun and all but basic traps like them, no matter how many you have or how well they are incorporated in a dungeon, will fall flat once a player knows how to navigate them properly. A wooden board over the pit. Throwing heavy rocks onto pressure plates. Using the ten foot pole to hit far reaching parts and switches. Those are classic workarounds but in more recent table tops, these are the poor man’s choices with the sheer plethora of spells, magic items, and abilities often at their disposal. So when the players fly over your pitfall trap for the third time in a row, it’s time to consider your options.

Subverting the expectations of the players is key to a good series of traps. Take what they conventionally know about a trap and twist it on its end! That pit they are trying to cross? It actually has a transparent ooze that uses its tendrils to swipe at passing prey, party included. The arrow trap that trails down the hall? Malfunctioned and shoots in a cone shape now. The pressure plate that was discovered on the floor? It’s magical and certain races activate it instead of just anyone, confusing the orc and surprising the gnome. In fact, using spells against the party for your traps can be tremendous fun, especially spells that aren’t necessarily damage dealers. Nobody expects the giant rolling boulder to actually just be an illusion after all. Surprising your party and setting solid but fair rules on how your traps work can be rewarding for both players and GM if done correctly.

Less a rule and more a suggestion is that not every trap should be meant for the rogue to solve. This might trigger the red alert for some of you but consider this. The party has no rogue. The rogue is more of an assassin build. Or for whatever reason, they didn’t get the trap necessary skills needed to perform at their very best. It happens and sometimes parties get rather lopsided in their composition.You may be stuck with all front-liners or your group is more based around magic or social themes. Rarely will a group be perfectly well-rounded so it’s good to consider traps that even without a rogue can be solved utilizing the party’s strengths.

Of course all of this stems from an understanding of who is in your party and how much you know about your players and their characters. Even the most shy will be able to contribute in some way if you make a trap that only their character can solve. Have a strength-based trap that would require the barbarian to lift up a portcullis for an extended period of time. Use a series of precarious platforms a monk could hop upon to get the switch in the back of the room. The wizard may need to solve a series of arcane writings in just the right order so the party doesn’t get thrown into an extradimensional maze. Incorporating traps that other party members would excel at can set a great variety for the party and give you a better arsenal at your disposal. Not only that but you can easily get the whole group involved with one or two well thought out traps instead of just having them rely on one person to get the job done.

Rarely will a group be perfectly well-rounded so it’s good to consider traps that … can be solved utilizing the party’s strengths Share13Tweet1Reddit1Email

I shouldn’t have to mention this one but don’t let your party know about your traps. It is not up to you to remind the party that they have the ability to ask you what they see around them. You’ve worked hard on these traps and, in the nature of their design, they are meant to surprise their victims with often lethal consequences. So after spending time and creative resources, are you going to point out to the party without any reason or provocation about the “slightly raised rock” in the middle of the path? It might be a personal experience but I’ve seen plenty of GM’s reveal such information to my party and, of course, we pounce on it, leading to them having less than desirable results.

Make sure to keep your traps hidden or else you’ll be setting up for immediate failure. What I don’t mean is that you have to have every trap secreted away behind a Perception check. What I mean is that if you put a sign that points down two paths and it says “One is trapped”, don’t have a footnote where it points to the right side that screams that the trap is down that road. They should know that going down into a long forgotten ruin will bound to be trapped and they should take precautions beforehand to deal with them. Keeping them a secret is also incredibly satisfying, especially when the trap fully works and everything falls into line against the party.

You are the GM of a massive, ever expanding world of canonical content and homebrew designs. Use every resource and every clever idea at your disposal. Look at real life examples and older editions of your choice of game for inspiration. Find something interesting and incorporate it into the most insidious thing your party can encounter. If your party finishes the session talking about how they activated a trap or how they overcame one then you have achieved the apex of what it means to make a proper experience for your party. The biggest thing we can achieve in our time of playing any tabletop is the memories we make out of it. So I hope that the advice I’ve given will prove to work for you in some way or another, making plenty of memorable splatter death falls and Indiana Jones style situations. If any of you have these stories, don’t be shy and share them in the comments below!

Categories: Game Theory & Design

The Problems with Modern Horror Game Design - by Josh Bycer Blogs - 4 November 2019 - 7:10am
Despite the resurgence of horror games in recent years, the state of the horror genre still is lacking when it comes to generating terror.
Categories: Game Theory & Design

The Mystical History of Tarot Cards (History of Game Design) - by Caleb Compton Blogs - 4 November 2019 - 7:10am
Happy Halloween! From their ancient egyptian origins to their use in modern divination, and everything in between, today's history of game design will look at the full story of the mysterious Tarot deck.
Categories: Game Theory & Design

Reaching Global Audiences: When and How to Grow Effectively in New Territories - by Sven Lubek Blogs - 4 November 2019 - 7:08am
Taking app marketing strategies from Eastern to Western markets isn't as straight-forward as one would think. Here, we take an inside look at actual RPG mobile app campaigns with global game publishers to highlight the successes and challenges.
Categories: Game Theory & Design

Unity Addressables Pooling: Jump In! - by Ruben Torres Bonet Blogs - 4 November 2019 - 7:06am
If you plan on jumping into Unity Addressables Pooling, be careful. You better make sure the object pool is not empty.
Categories: Game Theory & Design

The Indie Dev&#039;s Guide to the Chinese Market - by Damien Yoccoz Blogs - 4 November 2019 - 7:04am
Article outline 1 - Characteristics of the Chinese gaming market 2 - Four ways to reach a Chinese audience 3 - Anatomy of a game designed for the Chinese market 
Categories: Game Theory & Design

Kickstarter — Lessons learned from a 300% funded solo project - by Jonas Manke Blogs - 4 November 2019 - 5:43am
I’m a solo developer from Germany and I ran a Kickstarter campaign for my game as a solo indie dev Omno last year that ended up getting over 300% funded with a pledge total of over $100,000 USD.
Categories: Game Theory & Design Blog: Mismatched Entity Error

Planet Drupal - 4 November 2019 - 5:06am
If you are getting a "Mismatched entity and/or field definitions" error in your Drupal status page, then this maybe the solution you are looking for.
Categories: Drupal

Jacob Rockowitz: Webform module supports creating custom elements using HTML and SVG markup

Planet Drupal - 4 November 2019 - 4:24am


The Webform module for Drupal 8 provides support for basic, advanced, and composite inputs/elements. Developers can also create custom elements and composites via code. Sometimes end-users need an interactive visual mechanism to select a complex option like a map location. The Image select element is limited to allowing users to select horizontally-aligned images.

HTML5 and SVG allow designers and site builders to build visually rich and interactive elements. To convert rich interactive HTML/SVG elements into a form input, there needs to be some PHP and JavaScript glue code that captures a user's selection and sets it as a webform submission value.

Besides capturing the end-users selection, the PHP and JavaScript code must also ensure that the interactive HTML/SVG element is accessible to users with disabilities.



The general concept for creating a custom 'options' element' is to allow site builders to provide HTML/SVG markup that is dynamically converted into a select-able and accessible Webform element.

Below is a straightforward example of some HTML markup that can be enhanced.

SVG support requires the same data-id and data-name attributes being added to the HTML markup. Below is an example of a single clickable element in SVG.


The HTML/SVG markup must provide an option value or text attribute that can be used to create a list of available options. The default recommended 'value' attribute names are 'data-option-value', 'data-value', 'data-id', or 'id'. The default recommended 'text' attribute names are 'data-option-text', 'data-text', 'data-name', 'name', or 'title'. The Webform module uses these value/text attribute names to parse and detect the custom element's available...Read More

Categories: Drupal

Web Wash: Getting Started with React in Drupal 8

Planet Drupal - 4 November 2019 - 4:00am

If you’ve done any web development in the last couple of years, then I’m sure you noticed that JavaScript libraries and frameworks have become popular. The three that come to mind are React, Vue.js, Angular but there are many, many more.

These libraries and frameworks are great for building complex JavaScript applications. Also, being written in JavaScript means they can easily be embedded into a Drupal site.

In this tutorial, I’ll show you how to embed and compile a React application using two methods: Lavavel Mix and Webpack. If you want to use React then you’ll realize very quickly that you can’t just write JavaScript and have it work out-of-the-box, it needs to be compiled. That’s why I’ll show you two ways you can compile React locally without using a CDN.

This tutorial is targeted towards developers who know how to create a Drupal module, use the npm command and know basic React.

A copy of all the code can be found at

Categories: Drupal


Subscribe to As If Productions aggregator