Oct 04 2017
Oct 04

In our modules we can include default configuration to ship content types, views, vocabularies on install. If we try to reinstall the module, we'll get an error. Let's take a look at why and how we can solve it.

Unable to install … already exist in active configuration

During uninstall the configuration is not removed because it has no connection to the module itself and thus we get the error because Drupal modules may not replace active configuration. The reason for that is to prevent configuration losses.

We can move all the configuration to config/optional rather than config/install which basically means that configuration that does not exists will be installed and the existing one will be ignored. If we do this we can reinstall the module.

So, if we want the configuration to remain active we've already solved the problem, but if we don't want that, we want the module to remove all configuration and contents its provided we'll need to look at another solution.

Let's take a look at the Article content type that is created when using the Standard distribution on installing Drupal.

node.type.article.yml

langcode: en  
status: true  
dependencies: {  }  
name: Article  
type: article  
description: 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.'  
help: ''  
new_revision: true  
preview_mode: 1  
display_submitted: true  

field.field.node.article.body.yml

langcode: en  
status: true  
dependencies:  
  config:
    - field.storage.node.body
    - node.type.article
  module:
    - text
id: node.article.body  
field_name: body  
entity_type: node  
bundle: article  
label: Body  
description: ''  
required: false  
translatable: true  
default_value: {  }  
default_value_callback: ''  
settings:  
  display_summary: true
field_type: text_with_summary  

If we delete the content type, we can find out that the field instance body on the content type has been removed. First we actually see that the configuration will be removed when confirming the deletion of the content type, but also by looking in the database in the config table where active configuration is stored. It's gone.

The reason it's deleted is because it has an dependency on the node.type.article.yml configuration as we can see:

dependencies:  
  config:
    - field.storage.node.body
    - node.type.article
  module:
    - text

So what we need to do to make sure the content type we create when installing or module, that it's configuration uses our module as an dependency. So let's take a look at how we can do that:

Let's imagine we have a custom_event module that creates a event content type.

node.type.event.yml

langcode: en  
status: true  
dependencies:  
  enforced:
    module:
      - custom_event
third_party_settings: {}  
name: Event  
type: event  
description: 'Event'  
help: ''  
new_revision: true  
preview_mode: 1  
display_submitted: false  

The dependencies-part is the interesting one:

dependencies:  
    enforced:
        module:
            - custom_event

We have defined a custom_event module, in that module we have some exported configuration files in the config/install folder. We update the node.type.event.yml configuration file to have our module as an dependency. Now when we uninstall the module, the content type will be removed.

We also have to do this for our views, taxonomy, and field storages, or pretty much any configuration entity we provide configuration for. We don't have to worry about field instances, as we saw above those are dependent on the content type itself, but field storages on the other hand does not depend on a content type because you can reuse fields on multiple of those.

So, just add the module as an dependency and you're good to go, here's an example on a field storage field_image

field.storage.node.field_image.yml

langcode: en  
status: true  
dependencies:  
  enforced:
    module:
      - custom_event
  module:
    - file
    - image
    - node
id: node.field_image  
field_name: field_image  
entity_type: node  
type: image  
settings:  
  uri_scheme: public
  default_image:
    uuid: null
    alt: ''
    title: ''
    width: null
    height: null
  target_type: file
  display_field: false
  display_default: false
module: image  
locked: false  
cardinality: 1  
translatable: true  
indexes:  
  target_id:
    - target_id
persist_with_no_fields: false  
custom_storage: false  

Please enable JavaScript to view the comments powered by Disqus.

Dec 13 2016
Dec 13

It’s been a bit more than a year since Drupal 8 was released. There are more than 15 000 open issues open (and 70 000 closed (!), just to give you some context) in the Drupal core issue queue. Here’s a few of those issues I’m keeping an extra eye on.

Changing password hashing library.

Replace custom password hashing library with PHP 5.5 password_hash()

This issue has been active since 4 years back and is still actively going. The idea is to replace the current password library which is a forked version of phpass to use the built-in password_hash functionality that was introduced in PHP 5.5.
cweagans who created the issue lifts up three main problems with the current solution:

  • It has to be maintained by Drupal
  • It has 0% interoperability
  • It lacks forward-upgrading mechanism

and I agree with all of them. Drupal itself is a huge code base and has a lot of things to keep updated and further developed. Password hashing algorithms are hard and definitely takes an enormous amount of time to get it right. So, instead why not use something that’s built in to PHP and is secure.

The interoperability concern also makes sense. Because it is built in, it’s secure by design (by the way I’m not really saying the current solution is insecure) and are used in different systems and projects outside of Drupal. This also allows us to easier migrate something to Drupal without having to worry about rehashing passwords when doing so.

The final concern is about forward-upgrading. So currently bcrypt hashing algorithm is the to-go strategy for password hashing. If there comes a better algorithm in the future or you change the cost of the algorithm. The verify will still pass, but you can in a few lines make sure the password gets rehashed for enhanced security.

Menu subtrees in menu blocks show all subitems regardless of the active menu item

This issue is about 1 year old and is something I’ve experienced and had to deal with in a few of my latest projects.

So the problem is that if you have a menu which looks like this:

- Home
- Products
 - Product category 1
   - Product 1
   - Product 2
 - Product category 2
   - Product 3
   - Product 4

If we set the Menu block to level 3 and visits Product category 1 we are expected to see:

   - Product 1
   - Product 2

However currently it renders like:

- Product 1
- Product 2

- Product 3
- Product 4

To solve this temporarily, we’ve used the Menu block module along with an patch provided by an patch: https://www.drupal.org/node/2811337 (which is now closed due to duplicating this core issue).

Issue: https://www.drupal.org/node/2831274

I am most excited about this one. The idea is to bring the Media entity module into core. You should take a look at the module, but also the Drupal 8 Media guide.

But to give you an quick idea on what it is all about, it’s basically an initiative to add proper Media handling in Drupal. There are a lot of submodules that can be put together to give you a really powerful system for handling media. Such as entity browsers, image cropping, etc.

Currently we just use the plain simple file handling provided by Drupal today along with the IMCE module to reuse already uploaded files. It works fine, but I believe this initiative will give us something much more flexible and robust. Something we should expect from a CMS such as Drupal. I by mentioned this at work earlier this week and was told by a colleague this hopes to get into Drupal 8.4 so we’ll just have to idle by and see.

I’m also interested to learn how the upgrade path from using the module as contrib into core will look like. But also too see if there’s a good way to migrate existing media contents into this Media system.

Language support in Paragraphs

This one isn’t part of the Drupal core but as we use Paragraphs in most of our projects I’d also like to mention this issue:

Support translatable paragraph entity reference revision field

So currently Paragraphs does not have translation support and this way a Oh shit moment for us when creating a multilingual site. Luckily for us, this issue been active for a while and there are patches which works, as in it runs just fine in production.

Paragraphs is an awesome module for flexible content layout so getting this issue done is a deal-breaker for us. And again, these guys are making great progress and I wouldn’t be surprised if it was completed in a not so far future.

Dec 11 2016
Dec 11

Last week a friend called me and asked for help to put together some furnitures for his newly bought apartment. Together we tried to follow the user manual and as the time passed the more frustration we felt. Perhaps our clients feel the same way as we did when they use our systems? Somethings that feels clear to us (the builders) can seem like a impossibility for the consumer, the client.

With this analogy in mind I realised how important writing good documentation is. I also started thinking on how we can improve existing documentation and how to write it better for the future.

There are two kind of documentations I believe should be written, one for the consumers (the clients) and one for the developers.

Documentation for the consumers.

So, how can we best teach a client? For one we can have a user manual, introducing the system and the things clients will work with on a daily basis. Answering simple things like login, writing content, but also how the system works and should best be used. We use Drupal (a CMS) at work and they have a user manual that we translated and use as a base to introduce to the clients the basics of the CMS.

However many of the systems that are being developed are different than the core install and might be slightly different. Therefor if the CMS manual does not match that product, it should be adjusted to be so.

  • How is the system used best?
  • What are the limitations?
  • Workflows typical for the solution

Many of these questions has already been partly (or fully) discussed during sprint plans and discussions with the client on what you actually are producing. Putting them down in text, will help later on.

One of my colleagues also does video tutorials that are much appreciated from the clients. These videos are made in a local environment of the system that’s later shipped to production. Producing these videos as new features is shipped and how they are used is something I believe can be really useful. Videos also has the pro’s of the consumer being able to see how a workflow works from start to finish and jumping back and forth. In text it’s a bit more work and harder to do so.

We also like to invite clients to come over for a couple of hours to be introduced to the system face to face and being able to answer questions they might have right of the bat. These are often appreciated and I believe this might be one of the best ways to learn the client how to work with the system. This might not always be available to do, but if so, consider doing a Stream through something like Google Hangout or Skype. Recording these and making it available afterwards so we can look back is also an good idea.

Documentation for the developers.

Every once and then we have to go back on these medieval systems that was written years ago. Most often it’s a bug or even a new feature that has to be addressed. These legacy applications often tends to contain bad decisions and smelly code that is really hard to maintain. Perhaps the employee who first created is no longer with us and those who were around doesn’t have a clue on what’s going on it. These things are scary to work with, things break easily and there are no tests to verify that the changes you did broke something else in the system. Documentation for developers are also important and stuff that makes sense now will most certainly not in one year or more later on.

What about refactoring the code? Well refactoring and improving existing code is not always an option. We wish, but there may not be an budget or interesting in doing so.

To prevent these things we introduced Tech leads at work that makes sure documentation exists and is available to answer questions about the system when needed. The questions vary, but we’ve set up a pretty decent template:

  • Project details
    • CMS/Framework used?
    • Language, language version?
    • Web host?
    • Teach leads?
  • Introduction, small introduction on what the project is and what it does.
  • Startup, how do you install and get the project up and running on a local machine
  • Things to really know about this system
  • System structure
  • Production environment and backup routines
  • Things to verify works after an update (unless we have tests)
  • Sprint descriptions (what we did and were done in latest sprints)

I believe one of the most important thing is the Things to really know about this system. That is really helpful, especially if the system does something like pushing tweets, sending emails or something else that you have to be aware of. We kinda try avoiding these things and making sure development environment is safe to work in, but in legacy or projects that we’ve taken over it’s not always for granted.

Nov 28 2012
Nov 28

This video looks at the basics of working with MySQL from the command line. We get into the mysql environment and look at databases, tables and fields. We cover creating and deleting databases, creating a user, and querying within a particular database.

Nov 28 2012
Nov 28

This video shows you how to create your own custom shortcuts for various commands. We'll look at some common aliases and see how to add them to our command line environment. This is super handy for commands that you type in all the time and don't want to go through the tedium of typing the whole thing out every time. For example, we show how to automatically go to a particular directory with just one word (e.g. type "clients" and go to the /Users/add1sun/lullabot/clients directory immediately).

Jul 18 2012
Jul 18
Lullabot logo

Lullabot has trained thousands of Drupal developers & guided the development of some of the largest Drupal websites.

May 09 2012
May 09

In this presentation we get an overview of what the Drupal Ladder project is, along with some background on where it came from and why. We also look at the main pieces of the project, with the ladder and sprints. This is meant to be a "lightning talk" length introduction to the project and can be used at local meetups to kick things off.

May 09 2012
May 09

In this presentation we get an overview of what the Drupal Ladder project is, along with some background on where it came from and why. We also look at the main pieces of the project, with the ladder and sprints. This is meant to be a "lightning talk" length introduction to the project and can be used at local meetups to kick things off.

Apr 01 2012
joe
Apr 01

In this video Joe Shindelar goes over some important information about giving hugs. He walks through the various facets of hugs, giving some demonstrations throughout on:

  • Defining a hug
  • Types of hugs
  • Cautions
  • Technique

As Joe admonishes in the video, don't forget to practice your hugging after watching the video. Practice makes perfect!

Feb 01 2012
Feb 01

In this video we set up a LAMP stack web server for local development on an Ubuntu desktop (version 11.10). We will walk through installing and using tasksel to get the web server installed, then we'll add phpmyadmin to the mix. Once we have the server up and running, we'll look at where the web root is and how to add websites. Finally we wrap up with a quick look at how to start, stop, and restart our server when needed.

Jan 24 2012
Jan 24

This video shows you how to download and do the initial setup of MAMP, which is Apache, MySQL and PHP for Macintosh. It shows some basic configuration tweaks to change the port from 8888 to the default of 80 so that you can just visit the localhost in the browser and get your Drupal installation to appear. It also provides a general orientation to MAMP, and some other initial configuration setting changes.

Jan 24 2012
Jan 24

This video walks through the process of downloading and doing the initial configuration of WampServer, which is Apache, MySQL and PHP for Windows. It shows how to turn it on and off, as well as how to get files to show up from the localhost server.

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web