Reusing qtags

Being a qtag nothing else than a php method, each qtag can reference another qtag.

As an example, let's see how the ADD qtag (normally used to add a node inside another node) is implemented.

/**
 * Implementation of qtag ADD.
 *
 * Creates an "add node" button.
 *
 * @param Environment $env
 *   The Environment.
 *
 * @param string $target
 *   The qtag's target.
 *
 * @param array $attributes
 *   The qtag's attributes.
 *
 * @return string
 *   The rendered qtag.
 */function qtag_ADD($env, $target, &$attributes) {
  $nodeobj = empty($target) ? NodeFactory::current($env) : NodeFactory::load($env, $target);
  $target = $nodeobj->getName();
  $link = '';
  // Check if the user has the permission to add a node.
  if (NodeAccess::check($env, NODE_ACTION_ADD, array('node' => $nodeobj))) {
    $attributes['link_class'] = isset($attributes['add_class']) ? $attributes['add_class'] : '';
    $attributes['link_class'] .= ' add-link ';
    $attributes['tooltip'] = isset($attributes['tooltip']) ? filter_xss($attributes['tooltip']) : 'Add to ' . filter_xss($nodeobj->getTitle()) . '...';
    $attributes['language'] = isset($attributes['language']) ? $attributes['language'] : Localization::getLanguage($env);
    $attributes['title'] = isset($attributes['title']) ? filter_xss($attributes['title']) : '⊕';


    $link = qtag_LINK($env, $target, $attributes);
  }
  return $link;
}

As you can see, the function simply uses the existing qtag_LINK, but performs an access check to make sure the user can actually add a new node, and adds a tooltip and wrapping classes that will then be used by javascript to launch the Node add Shadow.

This simple demonstration shows you how a qtag can be used to extend another qtag. The only limit is... your fantasy!