public function defineFromTemplate(WorkflowDefinition $definition, $templateName)
    {
        $template = null;
        /* @var $template WorkflowTemplate */

        if (!is_array($this->templates)) {
            return;
        }

        $template = $this->getNamedTemplate($templateName);

        if (!$template) {
            return;
        }

        $template->createRelations($definition);

        // Set the version and do the write at the end so that we don't trigger an infinite loop!!
        if (!$definition->Description) {
            $definition->Description = $template->getDescription();
        }
        $definition->TemplateVersion = $template->getVersion();
        $definition->RemindDays = $template->getRemindDays();
        $definition->Sort = $template->getSort();
        $definition->write();
        return $definition;
    }