GithubHelp home page GithubHelp logo

taxonomy_fixtures's Introduction

Taxonomy fixtures

This drupal module provides an "unfeaturized" way of exporting/importing taxonomy terms to/from a json file.

Fixtures?

Yes. As in sample data or initial data.

"Unfeaturized"?

It just doesn't use the features module at all. Using the features module for content is evil.

Tags are content?

Well, kind of. Tags are to be referenced by content. Which means you need them available to be referenced and you may run into the scenario where you:

  • Need to add a couple of tags to a vocabulary
  • Need A way to deploy these to multiple environments without the need to manually create them on a production instance.
  • Need to quickly deploy a set of tags for use in CI Tests or QA Sites.
  • Want to easily create a few tags when a installing a Drupal Profile.

Ok, I'm in. How do I setup to use it?

In order to begin importing and exporting content you need to provide a simple mapping. You do that implementing hook_taxonomy_fixtures_vocabulary() for your module. Let's look at how DKAN begin to use it to bootstrap "Topics":

/**
 * Implements hook_taxonomy_fixtures_vocabulary().
 */
function dkan_default_topics_taxonomy_fixtures_vocabulary() {
  $data_path = drupal_get_path('module', 'dkan_default_topics') . '/data';
  $vocabularies = array();

  $vocabularies['dkan_topics'] = array(
    'export_path' => $data_path,
    'map' =>     array(
      'name' => 'name',
      'field_icon_type' => 'type',
      'field_topic_icon' => 'icon',
      'field_topic_icon_color' => 'icon_color',
      'description' => 'description',
      'weight' => 'weight',
      'uuid' => 'uuid',
    ),
  ); 

  return $vocabularies;
}

This hook returns:

  • A map of drupal fields to JSON fields
  • Where to export the JSON field (and eventually where to import it from)
  • Everything tied together in an associative array which keys are the exported vocabularies machine names

Drupal to JSON Mapping

'map' => array(
  'name' => 'name',
  'field_icon_type' => 'type',
  'field_topic_icon' => 'icon',
  'field_topic_icon_color' => 'icon_color',
  'description' => 'description',
  'weight' => 'weight',
  'uuid' => 'uuid',
),

The array keys are the drupal fields names. Values are the JSON Fields names.

Export/import location

Where do you want the JSON Export to live. In this case a data directory inside the dkan_default_topics module directory (wherever that is)

'export_path' => drupal_get_path('module', 'dkan_default_topics') . '/data',

How do i know if this is setup correctly?

Running the following will output all the subscribed vocabularies:

drush tf list

If your vocabulary is there you are good to go.

Ok, i'm ready. How do i export and import data using this?

There are a drush commands to accomplish all this.

Export Data

In order to export all the subscribed vocabularies you run:

$ drush tf export

If you want to export just the dkan_topics vocabulary:

$ drush tf export dkan_topics

Import Data

To import all the exported vocabularies

$ drush tf import

To import just the dkan_topics vocabulary

$ drush tf import dkan_topics

taxonomy_fixtures's People

Contributors

teosibileau avatar janette avatar topicus avatar acouch avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.