You are here

public function ReportEditor::applyTemplate in Forena Reports 7.5

Same name and namespace in other branches
  1. 8 src/Editor/ReportEditor.php \Drupal\forena\Editor\ReportEditor::applyTemplate()

Apply a template based on the block id.

Parameters

unknown $id:

unknown $class:

unknown $config:

File

src/Editor/ReportEditor.php, line 852
ReportEditor.inc Wrapper XML class for working with DOM object. It provides helper Enter description here ... @author metzlerd

Class

ReportEditor

Namespace

Drupal\forena\Editor

Code

public function applyTemplate($id, $template_class, $config = array()) {
  $path = "body//*[@id='{$id}']";
  $nodes = $this->simplexml
    ->xpath($path);
  if ($nodes) {
    $node = dom_import_simplexml($nodes[0]);
  }
  else {
    drupal_set_message(t('Could not find %s in report', array(
      '%s' => $id,
    )), 'error');
    return;
  }
  $block_name = $node
    ->getAttributeNS($this->xmlns, 'block');
  $class = $node
    ->getAttribute("class");
  $config['block'] = $block_name;
  $data = Frx::BlockEditor($block_name)
    ->data($this->parms);
  $c = Frx::Template($template_class);
  if ($c) {
    $c
      ->initReportNode($node, $this->frxReport);
    if (strpos($class, $template_class) === FALSE) {
      $c
        ->resetTemplate();
    }
    $c
      ->generate($data, $config);
  }
  else {
    drupal_set_message(t('Could not find template %s', array(
      '%s' => $templateClass,
    )), 'error');
  }
}