You are here

public function Flowchart::getGraph in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Util/Flowchart/Flowchart.php \Drupal\business_rules\Util\Flowchart\Flowchart::getGraph()

Show the Business Rule workflow for one item.

Parameters

\Drupal\Core\Entity\EntityInterface $item: The item.

Return value

array The render array.

File

src/Util/Flowchart/Flowchart.php, line 48

Class

Flowchart
Class Flowchart.

Namespace

Drupal\business_rules\Util\Flowchart

Code

public function getGraph(EntityInterface $item) {

  // Variables and non saved items does not have graph.
  // If item has no children, there is no sense in show the flowchart as well.
  if ($item instanceof Variable || $item
    ->isNew() || !$this
    ->itemHasChildren($item)) {
    $form['graph_definition'] = [
      '#type' => 'textarea',
      '#attributes' => [
        'id' => 'graph_definition',
        'style' => [
          'display:none',
        ],
      ],
    ];
    return $form;
  }
  $this
    ->mountMatrix($item);
  $graph_definition = [];
  $graph_definition[] = '<mxGraphModel dx="1426" dy="847" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" background="#ffffff"><root><mxCell id="0"/><mxCell id="1" parent="0"/>';

  // Prepare the graph.
  $graph_definition = array_merge($graph_definition, $this
    ->processMatrix());
  $graph_definition[] = '</root></mxGraphModel>';
  $form['graph_definition'] = [
    '#type' => 'textarea',
    '#value' => implode('', $graph_definition),
    '#attributes' => [
      'id' => 'graph_definition',
      'style' => [
        'display:none',
      ],
    ],
    '#rows' => 0,
    '#cols' => 0,
  ];
  $form['mxGraph'] = [
    '#type' => 'markup',
    '#prefix' => '<div id="business_rules_workflow_graph">',
    '#suffix' => '</div>',
  ];
  return $form;
}