Our site uses Workbench Access to create editorial section control. I'd like to theme the site based on the current section, so have written this module for themekey which queries the workbench access id of the current node. I'm wary this approach is slowing site performance considerably.

Have I got the right idea, or is a different approach needed?

function themekey_workbench_themekey_properties() {

$attributes = array();
$attributes['workbench:aid'] = array(
    'description' => t('Workbench: Access ID - The id of the of the taxonomy term used as the access id'),
    'validator' => 'themekey_validator_ctype_digit',
    'page cache' => THEMEKEY_PAGECACHE_SUPPORTED,
  );

$maps = array();

 $maps[] = array(
    'src' => 'node:nid',
    'dst' => 'workbench:aid',
    'callback' => 'themekey_taxonomy_nid2_wban_aid',
  );


return array('attributes' => $attributes, 'maps' => $maps);
}



function themekey_taxonomy_nid2_wban_aid($nid) {
  $aids = array();

  $query = db_select('workbench_access_node', 'wban');
  $query->addField('wban', 'access_id');
  $query->condition('wban.nid', $nid);
  $result = $query->execute();

  if ($result->rowCount()) {
    foreach ($result as $item) {
      $aids[] = $item->access_id;
    }
  }
  
  return count($aids) ? $aids : NULL;
}

Comments

mkalkbrenner’s picture

Version: 7.x-2.3 » 7.x-3.x-dev
Category: support » feature

The code looks good.

The db query uses the primary key. Therefore it should not have a negative impact on the performance.

I will integrate your code in ThemeKey 3.x itself. If it's located in the modules folder you don't have to worry about loading it or to create a separate module. But I will rename the functions.

mkalkbrenner’s picture

Title: Themekey module for Workbench Access » Workbench Access Support
Status: Active » Needs review

Committed to git:
https://drupal.org/commitlog/commit/6392/73facfeacc2db100a4b998d7f0ab182...

Can you test it?

As mentioned above I renamed the functions and the property, because it'S an intergation of "workbench_access" and not "workbench".

richard.french’s picture

Haven't actually used git before. How I checkout the changes? I thought something like
git checkout 73facfeacc2db100a4b998d7f0ab182d674e5a98 http://git.drupal.org/project/themekey.git This produces the following error fatal: Not a git repository (or any of the parent directories): .git Any ideas?

mkalkbrenner’s picture

git clone --branch 7.x-3.x http://git.drupal.org/project/themekey.git

Just have a look at the git instructions:
https://drupal.org/node/267054/git-instructions/7.x-3.x

richard.french’s picture

Thank you, that works. I get this error PHP Fatal error: Call to undefined function field_info_field_map() in /home/dev2/public_html/sites/all/modules/themekey/modules/themekey.node.inc on line 186 When trying to enable the module using Drush.

mkalkbrenner’s picture

It seems like your drupal core is outdated. You need to install at least 7.22:
https://api.drupal.org/api/drupal/modules!field!field.info.inc/function/...

richard.french’s picture

Thank you. Module enabled successfully and new property works. Excellent.

mkalkbrenner’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.