/** * Tries to find a template for the given resource by inspecting the current view * and the domain object's workflow state. * * That is, an "InputView" with an resource of workflow step "inactive" results in * a template of ".../Inactive_Input" that can then be set via "setTemplate()". * * Returns the first found template that matches the view's name and has a file extension * of '.haml', '.twig' or '.php'. * * @param ProjectionInterface $resource domain object with State/Step * * @return string|false template path/name to use; false if no matching template file was found */ protected function getCustomTemplate(ProjectionInterface $resource) { $view_class = new ReflectionClass($this); $view_class_dir = dirname($view_class->getFilename()); $state = $resource->getWorkflowState(); $class_file_name = basename($view_class->getFilename()); $class_name = str_replace('View.class.php', '', $class_file_name); $template_name = sprintf('%s_%s', ucfirst($state), $class_name); $template_extensions = array('.haml', '.twig', '.php'); $custom_template = false; foreach ($template_extensions as $template_extension) { $template_file = $template_name . $template_extension; $template_path = $view_class_dir . DIRECTORY_SEPARATOR . $template_file; if (is_readable($template_path)) { $custom_template = $view_class_dir . DIRECTORY_SEPARATOR . $template_name; break; } } return $custom_template; }
public function __construct($state_machine_name, ProjectionInterface $resource) { $this->resource = $resource; $this->execution_context = new ExecutionContext($state_machine_name, $resource->getWorkflowState(), array_merge($resource->getWorkflowParameters(), ['current_state' => $resource->getWorkflowState()])); }