Metal Toad: Programmatically Importing Drupal 8 Field Configurations

Planet Drupal - 13. März 2018 - 4:33
Programmatically Importing Drupal 8 Field Configurations Marcus Bernal Tue, 03/13/2018 - 02:33

Sometimes during development, a chicken and egg situation happens when business logic intersects with Drupal's mechanisms. For instance, a custom module, client_business_logic, is built to handle some unique, abstract bit of logic which depends on a taxonomy vocabulary that has fields added to it.

Dries Buytaert: How to use Drupal 8's off-canvas dialog in your modules

Planet Drupal - 13. März 2018 - 2:42

The goal of this tutorial is to show how to use Drupal 8.5's new off-canvas dialog in your own Drupal modules.

The term "off-canvas" refers to the ability for a dialog to slide in from the side of the page, in addition to resizing the page so that no part of it is obstructed by the dialog. You can see the off-canvas dialog in action in this animated GIF:

This new Drupal 8.5 feature allows us to improve the content authoring and site building experience by turning Drupal outside-in. We can use the off-canvas dialog to enable the content creator or site builder to seamlessly edit content or configuration in-place, and see any changes take effect immediately. There is no need to navigate to the administrative backend to make edits. As you'll see in this tutorial, it's easy to use the off-canvas dialog in your own Drupal modules.

I use a custom album module on for managing my photo albums and for embedding images in my posts. With Drupal 8.5, I can now take advantage of the new off-canvas dialog to edit the title, alt-attribute and captions of my photos. As you can see in the animated GIF above, every photo gets an "Edit"-link. Clicking the "Edit"-link opens up the off-canvas dialog. This allows me to edit a photo in context, without having to go to an another page to make changes.

So how did I do that?

Step 1: Create your form, the Drupal way

Every image on has its own unique path:

I can edit my images at:

For example, gives you the image of the Niagara Falls. If you have the right permissions you could edit the image at (you don't ????). Because you don't have the right permissions, I'll show you a screenshot of the edit form instead:

I created those paths (or routes), using Drupal's routing system, and I created the form using Drupal's regular Drupal form API. I'm not going to explain how to create a Drupal form in this post, but you can read more about this at the routing system documentation and the form API. Here is the code for creating the form:

<?php namespace Drupal\album; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\album\Image; use Drupal\Core\Url; class ImageEditForm extends FormBase { public function getFormId() { return 'album_edit_image'; } public function buildForm(array $form, FormStateInterface $form_state, $dir = NULL, $img = NULL) { $image = Image::loadImage("$dir/$img"); $form['path'] = [ '#type' => 'hidden', '#value' => $image->getUrlPath(), // Unique ID of the image ]; $form['title'] = [ '#type' => 'textfield', '#title' => t('Title'), '#default_value' => $image->getTitle(), ]; $form['alt'] = [ '#type' => 'textfield', '#title' => t('Alt'), '#default_value' => $image->getAlt(), ]; $form['caption'] = [ '#type' => 'textarea', '#title' => t('Caption'), '#default_value' => $image->getCaption(), ]; $form['submit'] = [ '#type' => 'submit', '#value' => t('Save image'), ]; return $form; } public function submitForm(array &$form, FormStateInterface $form_state) { $values = $form_state->getValues(); $image = Image::loadImage($values['path']); if ($image) { $image->setTitle($values['title']); $image->setAlt($values['alt']); $image->setCaption($values['caption']); $image->save(); } $form_state->setRedirectUrl(Url::fromUserInput('/album/'. $image->getUrlPath())); } } ?> Step 2: Add an edit link to my images

First, I want to overlay an "Edit"-button over my image:

If you were to look at the HTML code, the image link uses the following tag:


Clicking the link doesn't open the off-canvas dialog yet. The class="edit-button" is used to style the button with CSS and to overlay it on top of the image.

Step 3: Opening the off-canvas dialog

Next, we have to tell Drupal to open the form in the off-canvas dialog when the "Edit"-link is clicked. To open the form in the off-canvas dialog, simply extend that tag to:


Some extra HTML in the tag is all it took; it took my regular Drupal form, showed it in the off-canvas dialog, and even styled it! As I wrote above, it is easy to use the off-canvas dialog in your own modules. Hopefully you'll be inspired to take advantage of this new functionality.

There are several things being added though, so let's break it down. First we add the a class called use-ajax.

  • use-ajax is the class that is necessary for any link including dialogs that use Drupal's Ajax API.

We also added some data-dialog-* attributes:

You can create a link like the example above using a Drupal render array; it will open a form page in the off-canvas dialog and redirect the submitted form back to the current page:

$elements['link'] = [ '#title' => 'Edit image', '#type' => 'link', '#url' => Url::fromRoute('album_image', ['album' => $album, 'image' => $image], ['query' => \Drupal::service('redirect.destination')->getAsArray()])->toString();, '#attributes' => [ 'class' => ['use-ajax'], 'data-dialog-type' => 'dialog', 'data-dialog-renderer' => 'off_canvas', 'data-dialog-options' => Json::encode(['width' => 400]), '#attached' => [ 'library' => [ 'core/drupal.dialog.ajax', ], ], ];

Because the dialog functionality might not be needed on every page, Drupal won't load it unless needed. We use the #attached element to tell Drupal that we want the JavaScript dialog system to be loaded for this page. It's a bit more work, but it keeps Drupal efficient.

Improving the developer experience

Applying the off-canvas dialog to my blog and writing this tutorial uncovered several opportunities to improve the developer experience. It seems unnecessary to set class' => ['use-ajax'] when data-dialog-type is set. Why do I need to specify both a data-dialog-type and a data-dialog-renderer? And why can't Drupal automatically attach core/drupal.dialog.ajax when data-dialog-type is set?

In discussing these challenges with Ted Bowman, one of the developers of the off-canvas dialog, he created an issue on to work on off-canvas developer experience improvements. Hopefully in a future version of Drupal, you will be able to create an off-canvas dialog link as simply as:

$link = Link::createFromRoute('Edit image', 'album_image', ['album' => $album, 'image' => $image])->openInOffCanvasDialog(); $elements['link'] = $link->toRenderable();

Special thanks to Ted Bowman and Samuel Mortenson for their feedback to this blog post.

MidCamp - Midwest Drupal Camp: ICYMI: Next year at O'MidCamp!

Planet Drupal - 12. März 2018 - 23:41
ICYMI: Next year at O'MidCamp! Next Year is O'MidCamp

Mark your calendars, next year MidCamp is St. Patrick's day weekend, March 14–17, 2019. Join us for the fun and add "saw the river dyed green" to "learned all the things".

MidCamp - Midwest Drupal Camp: MidCamp 2018 is a wrap

Planet Drupal - 12. März 2018 - 23:39
MidCamp 2018 is a wrap

MidCamp 2018 is in the books, and we couldn't have done it without all of you. Thanks to our trainers, trainees, volunteers, organizers, sprinters, venue hosts, sponsors, speakers, and of course, attendees for making this year's camp a success.

Videos are up

By the time you read this, we'll have 100% of the session's recordings from camp up on our YouTube Channel. Find all the sessions you missed, share your own session around, and spread the word. While you're there, check out our list of other camps who also have a huge video library to learn from.

Tell us what you thought

If you didn't fill it out during camp, please fill out our quick survey. We really value your feedback on any part of your camp experience, and our organizer team works hard to take as much of it as possible into account for next year.

Nextide Blog: Maestro D8 Concepts Part 4: Interactive Task Edit Options

Planet Drupal - 12. März 2018 - 21:34

This is part 4 of the Maestro for Drupal 8 blog series, defining and documenting the various aspects of the Maestro workflow engine.  Please see Part 1 for information on Maestro's Templates and Tasks, Part 2 for the Maestro's workflow engine internals and Part 3 for information on how Maestro handles logical loopback scenarios.

Nextide Blog: Drupal Ember Basic App Refinements

Planet Drupal - 12. März 2018 - 21:34

This is part 3 of our series on developing a Decoupled Drupal Client Application with Ember. If you haven't yet read the previous articles, it would be best to review Part1 first. In this article, we are going to clean up the code to remove the hard coded URL for the host, move the login form to a separate page and add a basic header and styling.

We currently have defined the host URL in both the adapter (app/adapters/application.js) for the Ember Data REST calls as well as the AJAX Service that we use for the authentication (app/services/ajax.js). This is clearly not a good idea but helped us focus on the initial goal and our simple working app.

Nextide Blog: Untapped areas for Business Improvements

Planet Drupal - 12. März 2018 - 21:34

Many organization still struggle with the strain of manual processes that touch critical areas of the business. And these manual processes could be costlier that you think. It’s not just profit that may be slipping away but employee moral, innovation, competitiveness and so much more.

By automating routine tasks you can increase workflow efficiency, which in turn can free up staff for higher value work, driving down costs and boosting revenue. And it may be easier to achieve productivity gains simpler, faster, and with less risk that you may assume.

Most companies with manual work processes have been refining them for years, yet they may still not be efficient because they are not automated. So the question to ask is, “can I automate my current processes?”.

Nextide Blog: Maestro D8 Concepts Part 3: Logical Loopbacks & Regeneration

Planet Drupal - 12. März 2018 - 21:34

This is part 3 of the Maestro for Drupal 8 blog series, defining and documenting the various aspects of the Maestro workflow engine.  Please see Part 1 for information on Maestro's Templates and Tasks, and Part 2 for the Maestro's workflow engine internals.  This post will help workflow administrators understand why Maestro for Drupal 8's validation engine warns about the potential for loopback conditions known as "Regeneration".

Nextide Blog: Maestro D8 Concepts Part 2: The Workflow Engine's Internals

Planet Drupal - 12. März 2018 - 21:34

The Maestro Engine is the mechanism responsible for executing a workflow template by assigning tasks to actors, executing tasks for the engine and providing all of the other logic and glue functionality to run a workflow.  The maestro module is the core module in the Maestro ecosystem and is the module that houses the template, variable, assignment, queue and process schema.  The maestro module also provides the Maestro API for which developers can interact with the engine to do things such as setting/getting process variables, start processes, move the queue along among many other things.

As noted in the preamble for our Maestro D8 Concepts Part 1: Templates and Tasks post, there is jargon used within Maestro to define certain aspects of the engine and data.  The major terms are as follows:

Nextide Blog: Decoupled Drupal and Ember - Authentication

Planet Drupal - 12. März 2018 - 21:34

This is part 2 of our series on developing a Decoupled Drupal Client Application with Ember. If you haven't yet read Part 1, it would be best to review Part1 first, as this article continues on with adding authentication and login form to our application. Shortly, we will explore how to create a new article but for that we will need to have authentication working so that we can pass in our credentials when posting our new article.

Nextide Blog: Maestro D8 Concepts Part 1: Templates and Tasks

Planet Drupal - 12. März 2018 - 21:34

Templates and tasks make up the basic building blocks of a Maestro workflow.  Maestro requires a workflow template to be created by an administrator.  When called upon to do so, Maestro will put the template into "production" and will follow the logic in the template until completion.  The definitions of in-production and template are important as they are the defining points for important jargon in Maestro.  Simply put, templates are the workflow patterns that define logic, flow and variables.  Processes are templates that are being executed which then have process variables and assigned tasks in a queue.

Once created, a workflow template allows the Maestro engine to follow a predefined set of steps in order to automate your business process.  When put into production, the template's tasks are executed by the Maestro engine or end users in your system.  This blog post defines what templates and tasks are, and some of the terms associated with them.


Nextide Blog: Decoupled Drupal and Ember

Planet Drupal - 12. März 2018 - 21:34

This is the first in a series of articles that will document lessons learned while exploring using Ember as a decoupled client with Drupal.

You will need to have Ember CLI installed and a local Drupal 8 (local development assumed). This initial series of articles is based on Ember 2.14 and Drupal 8.3.5 but my initial development was over 6 months ago with earlier versions of both Ember so this should work if you have an earlier ember 2.11 or so installed.

You should read this excellent series of articles written by Preston So of Acquia on using Ember with Drupal that provides a great background and introduction to Ember and Drupal.

Nextide Blog: Maestro Overview Video

Planet Drupal - 12. März 2018 - 21:34

We've put together a Maestro overview video introducing you to Maestro for Drupal 8.  Maestro is a workflow engine that allows you to create and automate a sequence of tasks representing any business process. Our business workflow engine has existed in various forms since 2003 and through many years of refinements, it was released for Drupal 7 in 2010. 

If it can be flow-charted, then it can be automated

Now, with the significant updates for Drupal 8, maestro was has been rewritten to take advantage of the Drupal 8 core improvements and module development best practices. Maestro now provides a tighter integration with native views and entity support.

Maestro is a solution to automate business workflow which typically include the movement of documents or forms for editing and review/approval. A business process that would require conditional tests - ie: IF this Then that.

Nextide Blog: Maestro Workflow Engine for Drupal 8 - An Introduction

Planet Drupal - 12. März 2018 - 21:34

The Maestro Workflow Engine for Drupal 8 is now available as a Beta download!  It has been many months of development to move Maestro out of the D7 environment to a more D8 integrated structure and we think the changes made will benefit both the end user and developer.  This post is the first of many on Maestro for D8, which will give an overview of the module and provide a starting point for those regardless of previous Maestro experience.

Jeff Geerling's Blog: Getting Started with Lando - testing a fresh Drupal 8 Umami site

Planet Drupal - 12. März 2018 - 21:20

Testing out the new Umami demo profile in Drupal 8.6.x.

I wanted to post a quick guide here for the benefit of anyone else just wanting to test out how Lando works or how it integrates with a Drupal project, since the official documentation kind of jumps you around different places and doesn't have any instructions for "Help! I don't already have a working Drupal codebase!":

Analoge Smartwatch: Fossil Q Machine im Test

heise online Newsticker - 12. März 2018 - 21:00
Die aktuelle Generation von Fossils Hybrid-Smartwatch hat kein Display und informiert mit Zeigern über Nachrichten und deren Absender, Anrufe und mehr. Das gelungene Design und die vielen Funktionen sind überzeugend gut.

Programmiersprachen: Swift teilt sich mit Objective-C die Chartplatzierung

heise online Newsticker - 12. März 2018 - 20:00
Laut Untersuchung von RedMonk ist die keine vier Jahre alte Apple-Sprache auf GitHub und Stack Overflow nun in der Top Ten – und hat ihren Vorgänger erreicht.

Sony Xperia XA2 Ultra im Test – groß und mit Dual-Selfie-Kamera

heise online Newsticker - 12. März 2018 - 19:00
Das Sony Xperia XA2 Ultra ist ein Großbild-Smartphone: Auf seinem 6-Zoll-Bildschirm zeigt es Inhalte an. Selfies schießt es mit einer Dual-Kamera. Was das Gerät zu einem Preis von 449 Euro sonst noch drauf hat, verrät der Test von TechStage.

Carsharing mit Brennstoffzellenautos: BeeZero stellt Betrieb ein

heise online Newsticker - 12. März 2018 - 18:30
In Deutschland einmalig: ein Carsharing-Anbieter, der nur Brennstoffzellenautos in seiner Flotte hat. Anscheinend ließ sich das Modell nicht wirtschaftlich betreiben.

Opera, VLC, WinRAR, 7-Zip, Skype: Türkischer Provider ersetzt Downloads durch Spyware

heise online Newsticker - 12. März 2018 - 18:00
Dank Deep Packet Inspection kann die Türk Telekom gezielt Downloadanfragen manipulieren und Internetnutzern Malware unterschieben. In Ägypten wird die Technik dagegen genutzt, damit Internetsurfer heimlich Kryptogeld minen.