Drupal

Evolving Web: Migrating Content Translated with "Entity Translation" from Drupal 7 to Drupal 8

Planet Drupal - 17 June 2017 - 8:39am

Since the release of Drupal 8 with a standardized way of managing translations, many sites running Drupal 7 are making a switch to Drupal 8. In Drupal 7 there are two ways to translate content:

  1. Using the content_translation module. The D7 core way of translating content, where every translation is a separate node.
  2. Using the entity_translation module. Maintains one node with a unique nid, while translations take place at the field level.

In this article we will discuss how to migrate content translations created with the entity_translation module from Drupal 7 to Drupal 8. You can find our tutorial about migrating translations that use Content Translation here.

This article would not have been possible without the help of my colleague Dave. Merci Dave!

The problem

We have a Drupal 7 database containing article nodes, which might have translations in English, Spanish and French. Some of these nodes are language-neutral, i.e. non-translatable. Our target is to migrate the D7 nodes into a D8 website, preserving the translations.

Before we start
  • Since this is an advanced migration topic, it is assumed you already know the basics of migration. If you are new to migrations in Drupal 8, I recommend that you read about migrating basic data to Drupal 8 first.
  • This article assumes that you have read our previous article on how to migrate content translations from Drupal 7 to Drupal 8 or have the relevant knowledge.
  • To execute the migrations in this example, you can download the drupal migration i18n example repository from GitHub. The module should work without any trouble for a standard Drupal 8 install. See quick-start for more information.
  • To see the example migrations in action, you need:
    • A Drupal 8 site.
    • The relevant D7 database, since we are migrating data from a Drupal 6 site.
    • Drush will be required to execute migration commands.
The module

To write the migrations, we create a module - in our case, it has been named migrate_example_i18n. Just like migrating content translations from D7 to D8, we create 2 YML files to define:

  • The example_creature_base migration will migrate all base data or non-translations.
    • The source/translations parameter is omitted or set to false.
    • The destination/translations parameter is omitted or set to false.
  • The example_creature_i18n migration will migrate all translations.
    • The process/nid is configured to use the migration plugin to lookup the node in the base language.
    • The source/translations parameter is set to true.
    • The destination/translations parameter is to true.
    • The migration_dependencies parameter declares example_creature_base as a dependency.

We group the two migrations using the example_creature migration group to keep things clean and organized. Then we can execute both migrations with drush migrate-import --group=example_creature --update.

How to migrate Entity Translations?

Entity translations! Drupal 7 content translations are supported since Drupal 8.3. At the point of writing this, there is no standard method for migrating entity translations to Drupal 8. In this example, we will migrate D7 nodes translated with the entity_translation module, however, the procedure should be similar for other entity types as well. Before we start, here are some notes about what's so different about entity translations:

  • All translations have the same entity_id. So, for a translated node, the entity_translation module will result in only one entry in the node table.
  • Translation information, certain metadata and revision information for entities is stored in the entity_translation table.

So if an English node with ID 19 has translations in Spanish and French, the entity_translations table has the following records:

An extract from the entity_translation table. entity_type entity_id revision_id language source uid status translate created changed node 19 1 en   1 1 0 1485800973 1487198982 node 19 1 es en 1 1 0 1485802336 1487199003 node 19 1 fr en 1 1 0 1487185898 1487198969

The above data structure is significantly different from the content translation structure. In fact, Drupal 8 handles translations much like the entity translation module! Hence, to handle entity-translations, we must take the entity_translation table into consideration, which the core d7_node source plugin does not do at the time of writing this article. Hence, we override the d7_node source with a custom source plugin named d7_node_entity_translation.

class D7NodeEntityTranslation

This is where we jump into code! We override certain methods of d7_node source to add support for the entity_translation table.

class D7NodeEntityTranslation extends D7Node { // Determines if the node-type being translated supports entity_translation. protected function isEntityTranslatable() {} // Depending on the "source/translations" parameter, this method alters // the migration query to return only translations or non-translations. protected function handleTranslations(SelectInterface $query) {} // This method has been overridden to ensure that every node's fields are // are loaded in the correct language. public function prepareRow(Row $row) {} // This method is called by the prepareRow() method to load field values // for source nodes. We override this method to add support for $language. protected function getFieldValues($entity_type, $field, $entity_id, $revision_id = NULL, $language = NULL) {} // Since all source nodes have the same "nid", we need to use a // combination of "nid:language" to distinguish each source translation. public function getIds() {} }

Here's a quick look at the changes we need to make:

  • function getIds() tells the migrate API to use one or more source properties which should be used to uniquely identify source records. When working with entity translations, all translations have the same entity_id, but they have a different language. We override this method to tell Drupal to consider both the entity_id and the language properties to uniquely identify source records. So, the source records are uniquely identified something like 19:en, 19:es, 19:fr instead of using just 19.
  • function handleTranslations() is the method which adds support for the translations parameter we use in the source plugin. The translations parameter tells Drupal whether to migrate entities in their base language or to migrate translations. We override this method to:
    • See if the node type being migrated supports entity translations.
    • If the node type supports entity translations, then we INNER JOIN entity_translation and read translation data and some entity metadata, like date of creation, date of updation, etc from that table.
  • function prepareRow() as the name suggests, prepares a row of source data before it is passed to the process plugins. At this stage, field data is also attached to the source data. However, it does not load field data in the language specified in the source row. To overcome this problem, we override the getFieldValues() method and make sure it loads the field data in the same language as specified in the source row.

That's it! You should now be able to run the migration with drush migrate-import --group=example_creature --update. The output should look something like this:

$ drush mi --group=example_creature --update Processed 9 items (9 created, 0 updated, 0 failed, 0 ignored) - done with 'example_creature_base' Processed 9 items (9 created, 0 updated, 0 failed, 0 ignored) - done with 'example_creature_i18n'

Note: Keep an eye out for Drupal core updates. If the drupal_migrate module adds support for entity translations, migrating entity translations might become much easier.

Next Steps + more awesome articles by Evolving Web
Categories: Drupal

Image Approval

New Drupal Modules - 17 June 2017 - 5:25am
Synopsis

Image approval module allows the moderator to view the recently uploaded images by the users for their account.The moderator can either approve or disapprove the images based on the site policy.The approved image will be published in the user's account across the site.

Categories: Drupal

Colorbox Zoom

New Drupal Modules - 16 June 2017 - 11:00pm

Zoom in on an image that has been loaded through Colorbox. This is great if you have a high resolution image that'd you'd like to show more detail.

Demo & more info:
This integrates Jack Moore's jQuery Zoom plugin with Drupal Colorbox.
http://www.jacklmoore.com/zoom/

Zoom is triggered on hover by default and can be changed to grab, click, or toggle - zooming over the part of the image where the mouse is at. Override options in the module's js/options.js file.

Categories: Drupal

Authcache Recacher

New Drupal Modules - 16 June 2017 - 2:07pm
Categories: Drupal

Entity Compare

New Drupal Modules - 16 June 2017 - 2:02pm
Categories: Drupal

Drupal core announcements: Sprint with the migrate team at DrupalCamp Montreal

Planet Drupal - 16 June 2017 - 11:42am
Start:  2017-06-15 (All day) - 2017-06-18 (All day) America/Toronto Event type:  Sprint

Several key contributors to the Migrate Initiative will be at the sprint at DrupalCamp Montreal on Sunday (and to some degree on earlier days as well). Join contributors Adam G-H (phenaproxima), Maxime Turcotte (maxocub) and Dave Vasilevsky (vasi) in person. Initiative coordinator Mike Ryan (mikeryan) is also planning to join remotely on Sunday.

Among the most important Migrate critical issues on the table that are planned to be worked on is auditing for potential ID conflicts before upgrading from older versions. This is the most thorny outstanding issue for the initiative. Use cases and feedback in general is welcome. Further migrate issues are categorized and tracked in the Migrate triage spreadsheet (update regularly). These include handling import of private files, adding back support for incremental migrations, redirecting for obsolete content translations when they are merged in the migration, etc. All of those need helping hands and this is a great time to get experienced with help from the most well versed people in the field.

If you cannot join the sprint this time, your involvement is more than welcome anytime. The migrate team has weekly meetings on every Thursday at alternating meeting times. See https://www.drupal.org/node/2735059#meet for the upcoming meetings.

Categories: Drupal

Ben's SEO Blog: Why Amazon.com Just Bought Whole Foods and What That Means for Drupal

Planet Drupal - 16 June 2017 - 9:21am

Two of the biggest retailers in the world are getting together. This morning, Amazon.com, the juggernaut that continues to put massive pressure on brick-and-mortar retailers, announced that it is buying Whole Foods, the popular, high-end organic foods grocer.

Both companies are major stakeholders in the Drupal ecosystem: Amazon made an investment in Acquia in 2014, and much of Acquia’s hosting infrastructure relies on Amazon Web Services. Whole Foods, for its part, has used Drupal for its web presence for at least five years—if not much longer—and holds Acquia as a key partner. Acquia Drupal is a significant part of the Whole Foods DevOps story. (I can just imagine that email from the Whole Foods Accounts Payables department to Acquia: “Send the bill to Amazon.”)

From a presentation at an Acquia event:

So why would Amazon jump out and make this purchase? The answer is complex and multi-faceted.

For Amazon, it's all about the data.

First, Amazon is, at its core, a data company. They use shopping history and patterns to sell us things we need before we even know that we need them. With all the newly acquired data from Whole Foods upper-end clientele, Amazon can make more efficient stock decisions in both the retail and physical stores. In February, Whole Foods Chief Executive John Mackey said that they would retain the services of Dunnhumby, a customer data and insights company, to inform merchandising and services (in other words, help us stock our shelves and get our prices down). I can’t help but think that Amazon could do even better.

Distribution

Second, this acquisition gives Amazon access to a grocery distribution network that enhances their own. It creates more markets for home grocery delivery. Nomura Instinet analyst Anthony DiClemente recently said that the grocery industry remains one of the largest and most under-penetrated markets for Amazon. Well, that just changed.

How convenient could Whole Foods home delivery be? As Dries has demonstrated in recent keynotes (blog post: http://buytaert.net/cross-channel-user-experiences-with-drupal), I can envision a future where I ask my Echo Dot for some free-range chickpeas and organic shampoo and a Whole Foods van shows up at my door an hour or two later with my products (and as of today, with a sizable charge on my debit card).

The Whole Foods brand - a trip down memory lane

Third, it gives Amazon a very strong brand that is associated with organic groceries and high-end shopping experience.

I’m from Austin, and I’ve been shopping at Whole Foods since there was a single store in the early 80s. My family lived in nearby Temple so once a month we’d drive to Austin so Mom could shop at Whole Foods while us kids ran around the nearby Book Stop (Look it up. It was ahead of its time.), and eat at a fancy restaurant called Chilis.

So, maybe my brand recognition and a lifelong love of the grocery chain is stronger than most. There's no denying that it looms large over the health-food industry and is super-popular with upper-middle class soccer moms and those avocado-on-toast loving millennials we hear so much about (joke). How will Amazon leverage that loyalty? Could we see Amazon Fresh become “Whole Foods from Amazon”?

It's Go time.

The fourth and perhaps most compelling upside for the acquisition lies with Amazon Go, a recent experiment with automated retail stores.

Go is a frictionless shopping and checkout experience for physical stores. According to their website, you just “browse and shop like you would at any other store. Then you’re on the way: no lines, no checkout.”

Convenient.

It's currently only open to Amazon employees in a single Seattle store but the idea is as simple as the implementation is complicated: use advanced scanners and trackers to automate checkout. But what does this do to labor cost? In their commercial, the lone store employee is making sandwiches. That's hyperbole, but it makes that point: this is what Amazon wants. Any labor that doesn’t directly enhance the customer experience is suspect and should be eliminated as soon as possible.

Yesterday, outgoing CEO of GE Jeff Immelt scoffed that robots were not going to take over factory jobs in the next five years. Perhaps, but in retail, it has already begun. Many retailers from grocery stores to Home Depot offer self-checkout. If Amazon leads the way to friction-free checkout in supermarkets, retailers that do not follow in their footsteps will find that they’re the next Borders, CompUSA, or Radio Shack.

The Go technology isn't ready for real world use yet but let's say it's at most 36 months away from being ready for prime time. That means that in relatively short order, Amazon can dramatically reduce one of the biggest expenses Whole Foods carries today: labor. They'll still have the cheese guy and the bread lady—those personal interactions are why people shop at a high-end grocer after all. Still, no more jockeying for the shortest checkout lines. It's hugely convenient, and it will happen.

With Go, Amazon can now tackle Whole Foods’ biggest issue for most people: price. As much as I love it, my family doesn’t do our grocery shopping at Whole Foods. I have a great experience, but I need a second job just to pay the bill. In fact, I walk around with my iPhone out looking up pricing and even placing one-click orders on Amazon. Now, if I could get that Whole Foods experience at Amazon prices? Sign me up.

Amazon will continue to do what they do best: leverage technology to remove inefficiencies in established industries, give customers the best possible experience along the way, and provide a shortcut to the things I want to do. This combination is their killer app.

The Drupal Opportunity

The opportunity for Drupal companies could be limited or could be huge. It seems unlikely that Amazon will continue to use Drupal to power their Whole Foods infrastructure in the long run. In the short run, however, Whole Foods will continue to operate as an independent, wholly-owned subsidiary—just with a lot more coverage and support from the most technically-savvy retail company around.

Outside of the immediate timeframe, it could open opportunities to build closer ties to Amazon through the use of headless Drupal for backend data storage, retrieval, and integration. As much as retailers suffer from Amazon’s dominance, manufacturers benefit from frictionless distribution and additional sales channels that will be created. That gives us, the Drupal community, more opportunities to do what we do best with Drupal 8 and beyond. We can continue toward building voice interactions that tie into Amazon’s Alexa infrastructure in unique ways; Tech stacks that better integrate e-commerce platforms into Amazon’s listings and sales engine; and possibly even recruiting opportunities for top Drupal talent that may be winding down their tenure with Whole Foods.

And that’s not even to mention the retailers that want to compete with Amazon head-on. They need what Drupal has: vision, community, and a platform for building world-class, sustainable, and expandable solutions. They need technology that allows them to meet and beat the Amazon at their own game. They need a shortcut to success, and that’s Drupal 8.

Opportunities for Drupal from a mega merger of Drupal community companies.Planet Drupal, amazon.com, whole foods, drupal news
Categories: Drupal

interceptjs

New Drupal Modules - 16 June 2017 - 8:54am

interceptjs is a jQuery plugin that allows site owners to control calls to action (CTA) that occur for anonymous users. Could be used to offer user experience surveys, for donation calls to action and more. This module hopes to implement a nice GUI to the library itself.

Categories: Drupal

Promet Source: Drupal Texas Camp Presentation: Harnessing Human Connection to Achieve Marketing Success

Planet Drupal - 16 June 2017 - 7:16am
This blog post is transcribed from the session "More Social, Less Media: Harnessing the power of Human Connection to Achieve Marketing Success" presented by Molly Nelson at Drupal Texas Camp in Austin, TX - June 2017 More Social, Less Media
Categories: Drupal

Profile score

New Drupal Modules - 16 June 2017 - 5:01am
Categories: Drupal

Cached Computed Field

New Drupal Modules - 16 June 2017 - 2:20am

A field that allows to cache computationally expensive computed data in field storage.

Use this field for computed data that is expensive to generate, for example data that is computed using NP-hard algorithms or data that comes from third party sources.

Categories: Drupal

Heading field

New Drupal Modules - 16 June 2017 - 1:10am

The heading module adds a new field type containing a text field and a heading
size. The field will be formatted as a HTML heading (h1 - h6).

This field type is created in the first place to be used within paragraphs.

Installation
  1. Download and extract this module to the modules/contrib directory or download using composer.
  2. Enable the module.
Usage

Create a content type or paragraph type and add the Text > Heading field to it.

Categories: Drupal

Init Test

New Drupal Modules - 15 June 2017 - 11:41pm

This is dummy description.

Categories: Drupal

La Drupalera (en): La Drupalera brings you the most refreshing Drupal events of the summer

Planet Drupal - 15 June 2017 - 11:39pm

 

We know that you don’t want to lose news of Drupal. For that reason, and although it has officially started beach season, here you have the most interesting events of this summer.

June 15
Categories: Drupal

Client Side File Cryptography

New Drupal Modules - 15 June 2017 - 11:41am
Categories: Drupal

OhTheHugeManatee: Better PHP === Better Drupalists: The PHP Track at Drupalcon Vienna

Planet Drupal - 15 June 2017 - 8:19am

One of the best parts of Drupal 8 is our shift to enterprise PHP coding structures. With tools like composer and Symfony’s structures like Events and Dependency Injection, Drupalists are learning to be great PHP developers, and vice-versa. Today, the fastest route to becoming a rock star Drupalist is through PHP.

I’m one of the PHP track chairs for Drupalcon Vienna, and this year our focus is better PHP === better Drupalists. How can better PHP make your life as a Drupal developer easier?

Do you like PHP 7? We want to hear about the technicalities of types, throwing all the things, and your favorite operators (mine is null coalesce, but full respect for you spaceship operator fans).

Have you seen the light of functional programming? Tell us why we should love higher orders with lambda functions and closures. Let’s hear the finer points of first class functions.

Do your tests bring all the bugs to the yard? We want to talk about it. Every method is a promise, and your tests make sure you keep your promises. We want sessions about test driven development in a drupal context, choosing the right test framework and scope, and how your real-world tests are saving you real-world time.

Have you written a composer library wrapper module yet? Submit a session about how composer is saving you lines of code.

Is your development environment fine-tuned for drupal excellence? Tell us how, and why.

We have only two weeks left until session submissions close! Get your session in now and help us make Drupal code something to be proud of.

Categories: Drupal

Valuebound: How to manage page layout using Display Suit module in Drupal 8

Planet Drupal - 15 June 2017 - 8:12am

The Contributed module Display suite (“DS”) allows you to take control on How do you want to render them using interface. admin has ability to arrange nodes, comment,user data, views etc. provides drag and drop after as we do for managing field section.

If you want to build a drupal custom page and really don't have any drupal technical knowledge or coding skill or, you don’t want to write custom templates, and  for smaller stuff then you can go ahead with this Display Suite module. Is really helpful when it comes to replacing the default view of an entity to user defined view using application interface. It’s straightforward…

Categories: Drupal

Texas Creative: 3 Tips for Client Friendly Paragraphs in Drupal 8

Planet Drupal - 15 June 2017 - 7:30am

Drupal’s Paragraphs module is a big part of what makes it easy for our clients to manage their site content. These three tips are how we make the user experience even better.

Read More
Categories: Drupal

Promet Source: The Secret to a Great Web Design RFP

Planet Drupal - 15 June 2017 - 7:03am
A recent prospect responded to my inquiry about the project budget with this:  "We can't release budget information as we need all vendors to bid their best price. If they know the budget they just bid right up to it."  
Categories: Drupal

Entity Reference Revisions Context

New Drupal Modules - 15 June 2017 - 6:35am

This field formatter adds contextual data attributes to entity reference revisions, useful specifically for determining how an element is positioned within a page and when theming a set of entities in the context of a list.

Categories: Drupal

Pages

Subscribe to As If Productions aggregator - Drupal