Skip to content

Instantly share code, notes, and snippets.

@amitaibu
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitaibu/8756853 to your computer and use it in GitHub Desktop.
Save amitaibu/8756853 to your computer and use it in GitHub Desktop.

Build Status

"Site preview" module suite for Drupal 7.x

Zariz is a suite of Drupal modules and methodology, that models content (nodes) creation and editing similar to Git's branches, and allows generating static sites from the Drupal backend. You can read more about it in this blog post, and here.

The counterpart of Zariz which is responsible for the static site creation is generator-zariz.

Live demo

  • Use this simplytest.me link (the "Zariz example" module will be auto enabled)
  • Migrate content via /admin/content/migrate

Creating branch

The OG (Organic groups) group type Branch is equivalent to a Git branch.

// Create a new "master" branch. There can be only a single master on the site.
$live_node = zariz_create_branch('live');

// Branch out fom the live branch.
$dev_node = zariz_create_branch('dev', $live_node);

Merging branches

We can check if there are merge conflicts - meaning that there is already a newer content in the "to branch". Zariz will auto-detect the parent branch.

$conflicts = zariz_get_merge_conflicts($dev_node->nid);

If there are no conflicts, we can merge - meaning that content from the "from branch" will be cloned into the "to branch".

$snapshot = zariz_merge_branch($dev_node->nid);

Working with Snapshots

Snapshots holds information about the content of a branch at a certain time. This is done by simply holding the last entity ID (e.g. node) that existed. The last entity ID can keep changing as long as the snapshot is not locked.

// Get the last snapshot from a branch.
$snapshot = zariz_get_snapshot_from_branch($live_node->nid);

// Check if a snapshot is locked.
$snpashot->isLocked()

// Lock a snpashot.
$snpashot->lock()

Query alter

Zariz can alter a query to the node table, to reflect the content in a certain branch. The altering is opt-in, by settings the zariz query tag. For example:

$query = new EntityFieldQuery();
$result = $query
  ->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'article')
  // Set the Zariz query tag.
  ->addTag('zariz')
  // Set explicitly the Branch ID. If this Metadata is omitted, the
  // OG-context will be used.
  ->addMetaData('zariz', array('branch_id' => $branch_id))
  ->propertyOrderBy('nid')
  ->execute();

The same query tag can be also used in Views. For example in /admin/structure/views/view/branch_content/edit under Query settings => Query Tags notice that the zariz tag was added.

Dependencies

Unless stated otherwise, use latest release version is required.

Commerce integration

"Zariz commerce" module integrates with commerce and allows smart revisioning of commerce products. Optional: In order to be able to "Add to cart" from the reference field, this soon-to-be merged patch is needed.

Typical permissions setup

  • In admin/people/permissions grant authenticated user Branch: Create new content
  • In admin/config/group/permissions/node/branch grant non-member and member roles the following permissions:
  • Merge branch
  • Create Article content
  • Edit any Article content

Example module

Enable zariz_example module and follow its README Here is the Drush command to download and install Zariz Example:

drush dl entityreference_prepopulate replicate node_clone
drush dl og --dev
drush en zariz_example

Developed by Gizra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment