Experimental project

This is a sandbox project, which contains experimental code for developer use only.

Issue: Widget or Theme needs sample data for kickstart. There is no automatic, easy and standard way to package Sample Data with all of its assets(i.e. images, videos,etc) part of single artifact deliverable for easy install in Drupal.

Solution: Use Features module along with Sample Data module for sample data exports/imports in an automotive manner without another dependency

The common practice to package widgets and themes at DesignsSquare.com delivered to client is by separating the deliverable into 3 parts - code, Structures&Configurations and Sample Data for KickStart all part of one deliverable via Features. The Sample Data part contains sample nodes, menu instances and assets referenced from content, fields and variables.

To automate the packaging process for Sample Data part of the deliverable, we have created Sample Data module. The Sample Data module does the following:

      1. Export/Imports nodes with Alias path
      2. Export/Imports menus bases on Alias path
      3. Handle the assets – images, videos, etc for sample data. Specifically:
        A) assets referenced from sample content or other modules located in default public directory(i.e. sites/default/file)
        B) assets referenced by fields(both core type or custom type)
        C) assets referenced by variables
        4. Overrides for context and StormArm variables

      Note: assets referenced by custom fields and variables need to use file_managed functionality to work

      1. Export/Imports nodes with Alias path

      In order to have alias path, you will have to install and enable alias path module - https://www.drupal.org/project/pathauto. Once the sample data have alias path, then export it from features(admin/structure/features). The Sample Data module will hook into the export and store alias path for each node later to restore at the time of import

      2. Export/Imports Menus based on Alias path

      Once you have the pathauto module enabled, each node will have the alias path used by Sample Data to export and import Menus. Go to Features(admin/structure/features) and look for section "MENU ALIAS" with options to select menues you like to import/export. It will store the menus in the export and then import to the new instance based on alias path. Since it uses alias path, each menu has to have unique links(alias path) to work

      3A) Assets referenced from sample content or other modules

      Your sample content may be referencing assets. It is also possible that other modules like "imce" for editor is storing assets. The Sample Data module lets you export those assets. Go to Features(admin/structure/features) and look for section "Content Assets". In this section, it will display all assets(files and directories) from the public directory. Select the ones you like to export and it will store them for later import in the new instance. If you select directory, then it will store the whole tree of the assets

      3B) Assets Referenced by Fields

      Your sample data(nodes) may have fields of type 'file' that is going to reference assets. The Sample Data module will automatically store those assets when you are exporting the sample data(nodes). It will automatically transfer the assets at the time of import in the new instance. The Sample Data module does the same for custom fields referencing assets and not only the Drupal default such as 'file'. There is one requirement. The 'file_managed' functionality needs to be handling the asset in order for the import/export to work

      3C) Assets Referenced By Variables

      You may have chosen to store asset references in form of FID in the Drupal variable. The Sample Data module will export/import this assets as long as the name of the variable is stored part of the entry in the file_usage table for field(column) - 'type':

              //we also add variable name as the 'type' parameter, so we can export via Sample Data module
              file_usage_add($file, 'module_name', 'VARIABLE_NAME', '1');
              // Save.

      As you see, the variable name is saved part of the usage entry. This is done, so Sample Data module exports the asset

      Once the variable is holding reference to the asset and the variable name is stored part of entry in the file_usage table, then in section 'VARIABLE ASSETS' in the Features page(admin/structure/features) there is listed available references for you to select to export/import those assets.

      4. Overrides for context and StormArm variables

      The "CONTEXT OVERRIDE" provides a solution to the fact that features doesn't let you export something that is already part of another feature. This is an issue if you say have a widget with context that needs to be overridden by site specific context. So by select the context from "CONTEXT OVERRIDE", it will store those context to import in the new instance

      The "STRONGARM OVERRIDE", besides the ability of overriding another conflicting feature, it also provides a solution to be able export home page, error 404, 403 that is impossible otherwise because it uses the hard coded path(node/id) specific to each Drupal instance. The Sample Data utilizes alias path to import/export home page, error 404 and 403 pages

      To summarize, the Sample Data module is one full solution for exporting/importing Sample data for Kickstart data. It exports/imports nodes and menus using alias path. It handles all the assets referenced by content, fields or variables. It also provides ability to override contexts as well as export/import home page, error 404, 403 pages. It does all for you, so you can forget about sample data & assets and focus on more important aspects like building widgets,themes and other cool things


      I am unable to export Content(nodes) via futures

      Ensure you have the correct versions for features (7.x-2.0 or above), feature_uuid (7.x-1.0-alpha4...the dev version on July 2014) and uuid (7.x-1.0-alpha5...dev version on July, 2014). Afterwards, enable the content to be exported at admin/config/content/uuid_features

      More Resources

      Import/Export Sample Data and Assets for Kickstart All Via Features
      Handling Artifacts For Custom Module

      The specified file public://artifact-name.jpg could not be copied, because the destination directory is not properly configured

      Ensure the export feature module has write access and re-create the feature.

      Project information