Extending and Reusing Qtags

As each Qtag corresponds to a PHP class, each Qtag can use OO inheritance principles to extend another Qtag.

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

 * Creates a link to add a node inside another node (as a subfolder) if the current User has the rights to do so.
 */class Add extends Link {
  public $link_class = array('add-link');
  protected $html_body = '⊕';
   * @return string
   *   The rendered Qtag.
  public function render() {
    // If no target is specified, use the current Node as a target.
    $nodeobj = \Quanta\Common\NodeFactory::loadOrCurrent($this->env, $this->getTarget());
    // Check if the user has the permission to add a node.
    if (\Quanta\Common\NodeAccess::check($this->env, \Quanta\Common\Node::NODE_ACTION_ADD, array('node' => $nodeobj))) {
      if (empty($this->attributes['tooltip'])) {
        // Default title for a "Add" Link, used for the tooltip. Can be overridden.
        $add_title_default = t('Add to !title...', array('!title' => \Quanta\Common\Api::filter_xss($nodeobj->getTitle())));
        $this->attributes['tooltip'] = !empty($this->attributes['tooltip']) ? \Quanta\Common\Api::filter_xss($this->attributes['tooltip']) : $add_title_default;
      return parent::render();

As you can see, the Add class is extending the existing Link Class, and on top of it additionally:
  • performs an access check to make sure the user has the permissions to add a new node inside the current one
  • creates a default text for the link: ⊕
  • adds a default tooltip
  • adds default classes (that will then be used by javascript to launch the "Node add" Shadow panel).

TIP: Reflecting use of OO Php approach, each Qtag can extend another Qtag, potentially reaching high levels of complexity and elaboration

The only limit to the power your Qtags can reach is... your fantasy!