eiriksm.dev: Set id of CSV migration row based on line number

Migrate in core is among my favorite parts of Drupal 8 and 9. The framework is super flexible, and it makes migrating content from any source you can dream up pretty straight forward. Today I want to show a trick that I use when I receive a csv (or Excel file) from clients, where they want all of the contents in it migrated to Drupal. One very simple example would be a list of categories.

Typically the file will come with one term on each line. However, migrate would want us to set an ID for all of the terms, which currently none of the rows have. One solution to this is to place an ID on all of the rows manually with some sort of spreadsheet software, and then point our migration to the new column for its IDs. But since that both involves the words “manual” and “spreadsheet software” it immediately makes me want to find another solution. Is there a way we can set the row id programmatically based on the row number instead? Why, yes, it is!

So, here is a trick I use to set the ID from the line number:

The migration configuration looks something like this:

id: my_module_categories_csv
label: My module categories
migration_group: my_module
source:
  # We will use a custom source plugin, so we can set the 
  # ID from there.
  plugin: my_module_categories_csv
  track_changes: TRUE
  header_row_count: 1
  keys:
    - id
  delimiter: ';'
  # ... And the rest of the file 

As stated in the yaml file, we will use a custom source plugin for this. Let’s say we have a custom module called “my_module”. Inside that module folder, we create a file called Categories Csv.php inside the folder src/Plugin/migrate/source/CategoriesCsv.php. And in that file we put something like this:

<?php

namespace Drupalmy_modulePluginMigratesource;

use DrupalmigratePluginMigrationInterface;
use DrupalmigrateRow;
use Drupalmigrate_source_csvPluginmigratesourceCSV;

/**
 * Source plugin for Categories in csv.
 *
 * @MigrateSource(
 *   id = "my_module_categories_csv"
 * )
 */
class CategoriesCsv extends CSV {

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    // Delta is here the row number.
    $delta = $this->file->key();
    $row->setSourceProperty('id', $delta);
    return parent::prepareRow($row);
  }

}
   

In the code above we set the source property of id to the delta (the row number) of the row. Which means you can have a source like this:

Name
Category1
Category2
Category3

Instead of this

id;Name
1;Category1
2;Category2
3;Category3

The best part of this is that when your client changes their mind, you can just update the file instead of editing it before updating it. And with editing, I mean “manually” and with “spreadsheet software”. Yuck.

To finish this post, here is an animated gif called “spreadsheet software yuck”

Vardot: DrupalAudit

DrupalAudit

Firas Ghunaim
Sun, 07/05/2020 – 03:19

Your comprehensive Drupal website auditing tool is here!

Vardot released the beta-version of DrupalAudit to aid Drupal website owners and developers just before the release of Drupal 9 early June 2020.

Frequent performance audits are essential to guarantee that you benchmark your desired KPIs and website efficiency in alignments of the objectives of your digital strategy.

The tool will assess your Drupal website across the following key areas:

  • Performance
  • SEO
  • Accessibility
  • Best Practices

To use DrupalAudit, follow these 3 simple steps:

  1. Enter your Drupal site’s URL and test the performance across all site aspects.
  2. Find out how your Drupal site is performing in the areas you care about.
  3. Automatically generated tips will guide you on what to do next.
Form
Form title
Audit Your Drupal Website Performance

Vardot: 8 Winning Travel and Tourism Marketing Tactics

Gábor Hojtsy: Learn about and shape the future of Drupal at DrupalCon Global

Drupal 9 was just released last month, and in less than two weeks we get together to celebrate it (again), learn, grow and plan together for the future at DrupalCon Global.

I presented my “State of Drupal 9” talk at various events for over a year now, and while the original direction of questions were about how the transition would work, lately it is more about what else can we expect from Drupal 9 and then Drupal 10. This is a testament and proof to the continuous upgrade path we introduced all the way back in 2017. Now that Drupal 9.0 is out, we can continue to fill the gaps and add new exciting capabilities to Drupal core.

DrupalCon Global will have various exciting events and opportunities to learn about and help shape the future of Drupal 9 and even Drupal 10. Tickets are $249 and get you access to all session content, summits and BoF discussions. As usual, contributions do not require a ticket and will happen all week as well, including a dedicated contribution day on Friday. Here is a sampling of all content elements discussing, planning on and even building the future of Drupal.

Sessions about the future of Drupal

First there is the Driesnote of course. Dries will share the result of the Drupal 2020 Product Survey and discuss plans for Drupal 10. There is a followup Q&A session to discuss the keynote and other topics with Dries live.

The Drupal Initiatives Plenary coordinated by yours truly is going to feature various important leaders in our community working on diversity and inclusion, accessibility, events, mentoring, promotion as well as core components like the Claro admin theme and the Olivero frontend theme. This is the best way to get an overview of how Drupal’s teams work, what are their plans and challenges. Even better, the plenary session is followed by a BoF where we can continue the discussion in a more interactive form.

In Drupal Core markup in continuous upgrade path Lauri Eskola will dive into why the deprecation process used for PHP and JavaScript code is not workable for HTML and CSS. This informs the direction of where markup is going in Drupal 9 and 10 onwards.

In the Drupal.org Panel the Drupal Association team discusses how key initiatives are supported on Drupal.org including Composer, Automatic Updates and even Merge Requests for Drupal contribution and plans for the future.

Mike Baynton and David Strauss will discuss Automatic updates in action and in depth showing what is possible now and what are the future plans.

There is not one but two sessions about the new proposed frontend theme. In The Olivero theme: Turning a wild idea into a core initiative Mike Herchel and Putra Bonaccorsi discusses the whole history and future plans while in Designing for chaos: The design process behind Olivero will cover the design specifically.

Moshe Weitzman leads a core conversation to take stock of the current command line tools for Drupal and discuss what a more complete core solution would look like in A robust command line tool for all Drupal sites.

In Let’s Make Drupal Core Less Complicated Ted Bowman will propose ways to simplify Drupal core for existing uses and to achieve an easier learning curve.

Finally Drupal 9: New Initiatives for Drupal offers a chance to discuss new initiatives proposed by Dries in the Driesnote. If you are interested to join in either or discuss the plans, this is your opportunity!

Birds of a Feather discussions about the future of Drupal

Attendees with tickets for DrupalCon Global will be able to participate in live discussions about key topics. BoF submission is open, so this list will possibly grow as time goes.

Ofer Shaal leads a discussion titled Standardize Rector rules as part of Drupal core deprecations to make sure the transition from Drupal 9 to 10 will be even easier than Drupal 8 to 9 is.

Submit your Birds of a Feather discussion now.

Contribute to the future of Drupal

Just like in-person DrupalCons, DrupalCon Global contribution will be free to attend and does not require a ticket. The contribution spaces are especially good to go to if you are interested in the future of Drupal and making a difference.

If you’ve been to a DrupalCon or a DrupalCamp before, a contribution event usually involves one or more rooms with tables that have signage on them for what they are working on. This is not exactly possible online, however, we devised a system to replicate tables as groups at https://contrib2020.getopensocial.net/all-groups which allows you to see what topics will be covered and who the leads are. (Huge props to Rachel Lawson at the Drupal Association for building this out!)

If your topic is not yet there, you should create a group now. Groups indicate what they are working on and what skills they need from contributors. You should join groups you are interested to help and read their information for guidance. Teams will post group events to let you know when certain activities (introduction, review sessions, co-working on specific problems or meetings to discuss issues) will happen. Events will also be used to signify when you are most likely to find people working on the topics. The OpenSocial site is a directory of topics and events, contribution itself will happen on drupal.org with discussion on Drupal Slack for most groups.

There are already groups for Configuration Management 2.0, the Olivero theme, the Bug Smash initiative and Media. Stay tuned for more appearing as the event comes closer.

Agaric Collective: Free Drupal 9 webinars on site building, migrations, and upgrades

On Tuesday, July 7, Agaric will host 3 free online webinars about Drupal 9. We invite the community to join us to learn more about the latest version of our favorite CMS. We will leave time at the end of each presentation for questions from the audience. All webinars will be presented online via Zoom. Fill out the form at the end of the post to reserve your seat. We look forward to seeing you.

Getting started Drupal 9

Time: 10:00 AM – 11:00 AM Eastern Time (EDT)

This webinar will cover basic site building concepts. You will learn what is a node and how they differ from content types. We are going to explain why fields are so useful for structuring your site’s content and the benefits of doing this. We will cover how to use Views to create listing of content. Layout builder, blocks, taxonomies, and the user permissions system will also be explained.

Introduction to Drupal 9 migrations

Time: 11:30 AM – 12:30 AM Eastern Time (EDT)

This webinar will present an overview of the Drupal migrations system. You will learn about how the Migrate API works and what assumptions it makes. We will explain the syntax to write migrations how different source, process, and destinations plugins work. Recommended migration workflows and debugging tips will also be presented. No previous experience with the Migrate API nor PHP is required to attend.

Drupal 9 upgrades: how and when to move your Drupal 7 sites?

Time: 1:00 PM – 2:00 PM Eastern Time (EDT)

This webinar will present different tools and workflows to upgrade your Drupal 7 site to Drupal 9. We will run through what things to consider when planning an upgrade. This will include how to make site architecture changes, modules that do not have D9 counterparts, what to do when there are no automated upgrade paths.

Agaric is also offering full-day trainings for these topics later this month. Dates, prices, and registration options is available at https://agaric.coop/training

Read more and discuss at agaric.coop.

Drudesk: Upgrade your website from Drupal 7 to 8/9 with the Drupal Module Upgrader

Upgrade your website from Drupal 7 to 8/9 with the Drupal Module Upgrader

The idea to upgrade a website from Drupal 7 to Drupal 8/9 is getting new perspectives.

Now that Drupal 9 is there as an official release, it’s clear like never before that Drupal 7 is getting outdated. It’s time to upgrade Drupal 7 sites so they can give their owners a much better value. The Drudesk support team knows how to achieve this through upgrades and updates, as well as speed optimization, bug fixes, redesign, and so on.

Tag1 Consulting: Enabling Declarative Components Everywhere: Drupal + Web Components Out of the Box

Many front-end technologies, especially React, now consider the notion of declarative components to be table stakes. Why haven’t they arrived in environments like the Drupal CMS’s own front end? Many native CMS presentation layers tend to obsolesce quickly and present a scattered or suboptimal developer experience, particularly against the backdrop of today’s rapidly evolving front-end development workflows. But according to Fabian Franz, there is a solution that allows for that pleasant front-end developer experience within Drupal itself without jettisoning Drupal as a rendering layer. The solution is a combination of Web Components support within Drupal and intelligent handling of immutable state in data that allows for Drupal to become a more JavaScript-like rendering layer. Rather than working with endless render trees and an antiquated Ajax framework, and instead of reinventing Drupal’s front-end wheel from scratch, Fabian recommends adopting the best of both worlds by incorporating key aspects of Web Components, the Shadow DOM, and particularly syntactic sugar for declarative components that competes readily not only with wildly popular JavaScript technologies like React and Vue but also matches up to the emerging approaches seen in ecosystems like Laravel. In this Tag1 Team Talks episode, join Fabian Franz (Senior Technical Architect and…

preston
Wed, 07/01/2020 – 05:13