You are here

public function ReportEditor::scrapeBlockConfig in Forena Reports 8

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

Scrape Data block configuration This tries to introspect the frx:block configuration based on the child nodes in the report by calling the getConfig method on the block.

Parameters

string $id: Extract configuration from a template.

Return value

TemplateBase

File

src/Editor/ReportEditor.php, line 841
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 scrapeBlockConfig($id, &$config) {
  $template_class = "FrxMergeDocument";
  $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");
  $templates = $this
    ->templateOptions();
  $config['id'] = $id;
  foreach ($templates as $tclass => $desc) {
    if (strpos($class, $tclass) !== FALSE) {
      $template_class = $tclass;
      break;
    }
  }
  if ($template_class) {

    //@TODO:  Figure out how to generate templates

    /** @var TemplateBase $c */
    $c = FrxAPI::Template($template_class);
    $config['class'] = $template_class;
    if ($c && method_exists($c, 'scrapeConfig')) {
      $c
        ->initReportNode($node, $this->frxReport);
      $config = array_merge($config, $c
        ->scrapeConfig());
    }
  }
  return $template_class;
}