Skip to main content

Blog

The entity_generate process plugin receives a value and checks if there is an entity with that name and if the term exists then uses it and if it does not then creates it (which is precisely what I need).

So, here is a snippet of the article migration YAML file using the entity_generate plugin:

id: blog migration_group: Drupal label: Blog source: plugin: d7_node node_type: blog destination: plugin: entity:node process: status: status created: created field_tags: plugin: sub_process source: field_tags process: target_id: - plugin: entity_generate source: name value_key: name bundle_key: vid bundle: tags entity_type: taxonomy_term ignore_case: true …

In our field_tags field we are using the Drupal 7  field_tags Values We are going to read the entities and pass that value into the entity_generate plugin to create the entities. In this example, there is a problem.  The d7_node migrate plugin (included in the migrate module) provides the taxonomy term IDs and this will make the entity_generate plugin create some taxonomy terms using the IDs as the term names, and this is not what we want.

So what I need to do is to get from somewhere the terms' names, not their ids. To do that I need to add an extra `source property`.

First, we need to create a new custom module and in there create a source plugin which extends the Node process plugin, something like this (let's say that our custom module’s name is my_migration):

Create the file:

my_migration/src/Plugin/migrate/source/MyNode.php

 

And the Content of MyNode file should have this code:

 

namespace Drupal\my_migration\Plugin\migrate\source; use Drupal\migrate\Row; use Drupal\node\Plugin\migrate\source\d7\Node; /** * Adds a source property with the taxonomy term names. * * @MigrateSource( * id = “my_node", * source_module = "node" * ) */ class MyNode extends Node { public function prepareRow(Row $row) { $nid = $row->getSourceProperty('nid'); // Get the taxonomy tags names. $tags = $this->getFieldValues('node', 'field_tags', $nid); $names = []; foreach ($tags as $tag) { $tids[] = $tag['tid']; } if (!$tids) { $names = []; } else { $query = $this->select('taxonomy_term_data', 't'); $query->condition('tid', $tids, 'IN'); $query->addField('t', 'name'); $result = $query->execute()->fetchCol(); $names[] = ['name' => $result['name']]; foreach ($result as $term_name) { $names[] = ['name' => $term_name]; } } $row->setSourceProperty('field_tags_names', $names); return parent::prepareRow($row); } }

The most important part of this code is:

$nid = $row->getSourceProperty('nid'); // Get the taxonomy tags names. $tags = $this->getFieldValues('node', 'field_tags', $nid); $names = []; foreach ($tags as $tag) { $tid = $tag['tid']; $query = $this->select('taxonomy_term_data', 't'); $query->condition('tid', $tid); $query->addField('t', 'name'); $result = $query->execute()->fetchAssoc(); $names[] = ['name' => $result['name']]; } $row->setSourceProperty('field_tags_names', $names);

 

It does the following things:

  • It reads the nid of the article
  • Gets all the terms' IDs of the field_tags field
  • For each ID, it gets the name of the term and puts it in the `names` array
  • Finally, it sets this value inside the $row using the `setsourceProperty` method.

 

Now our rows will have a property called fields_tags_names with the terms' names, and we can pass this data to the entity_generate plugin.

We need to make a few adjustments in our initial migration file. First and most important, update the  source plugin to use our new source plugin:

source: plugin: my_node …

And update the source in the `field_tags` field to use the new  `field_tags_names` source property.

… field_tags: plugin: sub_process source: field_tags_names ….

 

The final migration file looks like this:

 

id: blog migration_group: Drupal label: Blog source: plugin: my_node node_type: blog destination: plugin: entity:node process: status: status created: created field_tags: plugin: sub_process source: field_tags_names process: target_id: - plugin: entity_generate source: name value_key: name bundle_key: vid bundle: tags entity_type: taxonomy_term ignore_case: true …

And that’s it; if we run the migration, it will create on the fly the terms that do not exist and use them if they do exist.

 

Join groups that will keep you informed

Take the first steps— stay in the know!

Thank you for being awesome!  Use this page to register with your discount. If you want to attend more than one training, fill out the form once per training.

The contextual filter configuration screen.

Sign up to be notified when Agaric gives a migration training:

Building the open web

Vestibulum iaculis consectetur convallis. Donec sit amet congue massa. Quisque nec eros eu dolor posuere fermentum et vel nulla. Donec mollis leo sit amet egestas vulputate. Etiam eget ante ante. Proin dignissim justo vel nibh tincidunt, a porta dui tincidunt. Ut varius, metus ac luctus molestie, turpis magna ultricies lectus, at ornare tellus diam sit amet risus. In hac habitasse platea dictumst. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus neque dui, placerat ac massa nec, rutrum rhoncus ex. Sed ut posuere urna.

As big tech continues to violate our privacy, thwart worker power, collude with militaries and deportation agencies, we need to move to ethical tech tools we can trust.

However, it can be intimidating to make the switch to new, unfamiliar tools.

Micky is leading two workshops to help people make the switch.

“How to Switch to Free Software: Email” 4:45-6:45pm Wednesday, December 4

Micky Metts of Boston’s Agaric Tech Cooperative will help us get out of the fix. The key to regaining security and control of the internet is switching to free software equivalents to proprietary/corporate software for communicating – among many uses.

This first workshop focuses on communications using email and texting software. The moderate inconvenience of switching is worth the privacy of strong encryption and the freedom of a new world of user-controlled communications and organizing. This first workshop in Sala Quetzal focuses on email and texting with encrypted software under user control. Bring your phone.

“How to Switch to Free Software: Browsers Etc” 2-4pm Thursday, December 5

A professional software developer, Micky, will focus on this second workshop, also in Sala Quetzal, on browsing, searching, and virtual meeting software. She will show how free software opens up the world of “platform co-ops” – think of Uber under drivers’ control and AirBnB under homeowners’ control.

Micky will be assisted by at-the-elbow translator/helpers. Bring your laptop and your phone.

""

Upgrade from Drupal 6 or 7 when it is right for you

In the era of modern Drupal, release cycles of major versions have only minor importance

The growing community built around Drupal offers a multitude of options to easily integrate Drupal into your current lifestyle and to branch out in new and different ways. Here are a few ways to migrate your lifestyle to one as a Freelance Drupal Developer and a contributor to the community.

If you have a 9 to 5 job at an office or a specific location, you can choose to view online Drupal tutorials in whatever spare time you have instead of watching a movie. Drupal tutorials can be quite entertaining at times and are especially rewarding because they will change your life for the better.

Sign up for an account on Drupal.org and download the latest version of Drupal. Install Drupal locally on your hard drive and use some of the knowledge you learned in the tutorials. If you get stuck, log onto groups.drupal.org and search for an answer to your issue - chances are good that someone else has had the same issue and the solution will be posted there. As you search through the posts on the forum, be sure to respond to any posts that you may have the solution for. Since you have just gone through the install and setup, there is a good possibility that even as a beginner - you too may be able to help someone else. It's a good practice to do both things on a forum visit:

  1. Ask For Help
  2. Give Some Help

After a few weeks or months viewing tutorial videos and getting a solid idea of the moving parts within Drupal, you can start to create your first real site. I recommend that you involve a friend. Most people have at least one friend that has an idea for a business venture. Ask your friend if you may help them build a site based on their business idea. Enlist the friend to help you by inviting them over for a bowl of popcorn and a few Drupal movies...

Ben spoke most recently on this topic at DrupalCon Seattle and Drupal Camp Twin Cities, both in 2019, about how Drupal as a Service can save our livelihoods and our lives.  Here are some resources related to the talk and topic.

A graphic of the earth engulfed in flames.

The Earth is not dying, it is being killed, and those who are killing it have names and addresses.

Utah Phillips

As far as i can tell, the Internet hasn't sourced that quotation, but no one challenges that it was Phillips— and i thought i heard him say about the same thing on the radio, in a broadcast where he also slammed NPR, boosting community radio and, if needed, the do-it-yourself be-the-media ethos.  Maybe i'm part of a collective delusion, in which case, i'm sure Utah Phillips wouldn't care one way or another so long as we got on with working for the liberation of humanity and preserving life on planet Earth as part of that.

Sources cited

Crowd-sourcing this on Mastodon (itself interestingly compatible with LibreSaaS with instances like social.coop working on governance models, if not yet having the revenue to cover hosting, let alone contribute back to development:

Hello fediverse, what online tools do you know about that are LibreSaaS— you can pay to use them, but the full stack is free/libre open source software so you or others can totally host the entire thing yourself if you want?

I added whichever answers i didn't already have to the LibreSaaS list pad.

Tech Won't Build It

We'll keep looking for ways that cooperation can save us all (and technology can help) so sign up to get (extremely occasional, less than once a year) updates.

(Technically, there is one formatter each for text lists and for entity references, but all the options which In Other Words adds are the same for both.)

We can configure a separator between list items, a final join word, and whether to connect the final items with a comma (or semicolon or any other punctuation we can imagine for our list).

In all its glory in context: