Drupal 8 Configuration Management Issues


Everyone seems very excited with new configuration management tools provided by drupal 8. It just packages all (or single) site settings and you can import it to your other environments. But there are few glitches those can give developers hard time. And I am one of those developer. Here are few issues, I noticed while working with other developers and using configuration management.

1. Unable to install the standard module since it does not exist.

First of all, I had no idea what’s going on here. Later I figured out that, one of the developer installed fresh drupal  with standard profile and later changed the site hash to match the old installation. Now as configuration is looking for standard extension which does not exist on our site and configuration import fails with message ‘unable to install the standard….’. There are two ways to fix this issue:

  1. Make backup of you configuration files. Copy to your imported configuration files to your config folder and edit ‘core.extension.yml’. Remove the line standard: xxxx under module. Now, you can sync the config.
  2. Edit settings.php file, and paste:
$settings['install_profile']  = 'standard';

I would recommend to try first method and second if first does not work.

2. Configuration source control issue

When you install drupal, you will get weird directories. If you want to have common folder for configuration sync, you can define the directory where you want to have all config files. I personally prefer to use ‘sites/xxxx/sync’ folder. To use it as sync folder, you need to make add line of setting in settings.php.

$config_directories['active'] = 'sites/xxxx/sync'; //xxxx is your site folder, default in most of the cases

3. Configuration Management vs features

As you have noticed, features module is still there even drupal 8 is armed with configuration management. Features team has their own explanation on why you still need feature. As a rule of thumb, if you want to package certain collection of feature which you can use in other sites easily, you need features module. For example, If you want to use all articles related configurations in different site, you need feature in this case. You can use configuration management too but that will too much work. Using feature you can easily package them and import them in new site. You can learn details of configuration management vs features. https://www.youtube.com/watch?v=a6QLTjSFVhs and http://www.slideshare.net/nuvoleweb/2015-04devdaysmontpellier

 

 

Advertisements

Drupal: Use custom template file for any form


Introduction

Drupal 7 has well known template file concept. Template (.tpl) file is used to display the data and has minimal or no logic at all. I am pretty sure there are many scenarios where you would like to use your own template file. Most of the cases you can easily create template file using well documented instructions. For example, if you want to create template file for content type ‘Article’, you simply create a template file ‘node–article.tpl.php’ and put it inside your theme’s template folder. Drupal will automatically detects that template file and use it instead of default node.tpl.php. Similarly you can see theme suggestion of views just clicking on advanced->theme. But there are certain scenario where there is straight way to create and utilize template file. For example, you may want to customize login screen of your site and want to change layout or add more classes or add new div wrapper. To make use of template file in such scenario, we need to implement certain hooks.

Steps

First you need to add YOURTHEME_theme hook function in you theme->template.php file.

/**
 * theme_theme hook
 * @return type
 */
function MYTHEME_theme() {
    return array(
        'user_login' => array(
            'render element' => 'form',
            'path' => DIRECTORY_PATH_WHERE_YOU_WANT_TEMPLATE_FILE,
            'template' => 'user-login',
            'preprocess functions' => array('MY_FORM_PREPROCESS'),
        ),
    );
}

Now, if you want to update form data or add your own logic, you can use your preprocess function. Moreover, you can define your own custom variables which will be available to use in your template file. In the example below, I am creating new variable ‘myvariable’ which I can use in my template file later.

function MY_FORM_PREPROCESS(&$vars) {
    // Here you can have your own logic and 
    // you can define your own variables 
    // which will be available for you in your tpl file
    $vars['myvariable']='COMPLEX ARRAY';
}

Final step is to create tpl file in the directory you specified earlier. In this example, we have template name ‘user-login’. So, file name will be ‘user-login.tpl.php’. If you forget creating tpl file or misname it, drupal will fall back to use default way.

Further Question

Please leave your comment/question, if you have any concern implementing template file this way.