You are here

public function ReportEditor::prependBlock in Forena Reports 8

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

Insert a data block before a node.

Parameters

string $block_name: Name of block to prepend

string $template_class: Class of template to use.

string $id: ID of element to prepend on.

Return value

ReportEditor

File

src/Editor/ReportEditor.php, line 977
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 prependBlock($block_name, $template_class = 'FrxTable', $config = array(), $id) {
  $block_name = str_replace('.', '/', $block_name);
  $path = "body//*[@id='{$id}']";
  $nodes = $this->simplexml
    ->xpath($path);
  if ($nodes) {
    $target = dom_import_simplexml($nodes[0]);
  }
  else {
    drupal_set_message(t('Could not find %s in report', array(
      '%s' => $id,
    )), 'error');
    return NULL;
  }
  $node = $this->dom
    ->createElement('div');
  $pnode = $target->parentNode;
  $pnode
    ->insertBefore($node, $target);
  $config['block'] = $block_name;
  $b = FrxAPI::BlockEditor($block_name, $this->frxReport->block_edit_mode);
  $data = $b
    ->data($this->parms);
  $this
    ->addParameters($b
    ->tokens());
  $this->frxReport
    ->setReport($this->dom, $this->xpq);
  $c = FrxAPI::Template($template_class);
  if ($c) {
    $c
      ->initReportNode($node, $this->frxReport);
    $c
      ->generate($data, $config);
  }
  else {
    drupal_set_message(t('Could not find template %s', array(
      '%s' => $template_class,
    )), 'error');
  }
  return $this;
}