Comments (4)
the following also fails
$map[\raoul2000\workflow\base\StatusIdConverter::VALUE_NULL] = 1;
from yii2-workflow.
Hi,
The problem is that when the Article model instance is created, it's status attribute is NULL and as a status Id Converter is declared, the SimpleWorkflow behavior is going to ask to the converter for a valid status ID to replace this NULL value. I dont know what default map you have used but I assume it doesn't contain any match for NULL.
Assuming you have an Artcile model like this one :
class Article extends \yii\db\ActiveRecord
{
public function behaviors()
{
return [
'workflow' =>[
'class' => \raoul2000\workflow\base\SimpleWorkflowBehavior::className(),
// declare a status converter with ID 'converter'
'statusConverter' => 'converter'
]
];
}
}
What you should do is :
- initialize the Status Id Converter with a minimal map definig a mapping for NULL.
Yii::$app->set('converter',[
'class' => 'raoul2000\workflow\base\StatusIdConverter',
'map' => [StatusIdConverter::VALUE_NULL => StatusIdConverter::VALUE_NULL ]
]);
- Once you have your final conversion map ready, update the Status Id Converter component, and don't forget the NULL match.
// the status ID conversion is invoked here, and status being NULL
// the conversion will look for a NULL matching line in the conversion map
$article = new Article();
$article->getStatusConverter()->setMap([
'article/DRAFT' => 'DRAFT',
'article/PUBLISHED' => 'PUBLISHED',
'article/EXPIRED' => 'EXPIRED',
'article/SCHEDULED' => 'SCHEDULED',
'article/MODERATED' => 'MODERATED',
StatusIdConverter::VALUE_NULL => StatusIdConverter::VALUE_NULL
]);
This is ok if you want to consider that the NULL status is invariant regarding the Status Id Convertion. If that's not the case and if for instance you want to convert NULL status into 'article/new', then, you will have to force the conversion for all models that were created before the map is updated.
To force status ID conversion on a model, you must call the initStatus()
method on this model:
$article->initStatus();
I hope this explanation is clear. If not, don't hesitate to ask ...
One last point : I think you should update yii2-workflow to dev-master until I release 0.0.12 because from the stack trace I see you are not using the lastest version. As for releasing 0.0.12 I will do that soon but I wanted to wait for your feedback first and make more tests on my side ....
from yii2-workflow.
Thanks raoul
I can confirm all is working as expected.
Thank you very much for your support.
from yii2-workflow.
you're welcome :)
from yii2-workflow.
Related Issues (20)
- Different namespace and workflow history? HOT 1
- Question: Is it possible populate a getDefinition method with relations? HOT 5
- Endstate with no transitions throws an error HOT 10
- I have a few question if you would HOT 2
- Change state by timeout HOT 3
- Cannot use 'Object' as class name as it is reserved HOT 3
- ChangeStatusAction.php HOT 1
- Playground example HOT 1
- keep status updated problem (not an issue, just desperate for your help) HOT 3
- Cannot use 'Object' as class name as it is reserved HOT 4
- unsure how to recheck a Workflow rule on value change HOT 1
- How can the getDefinition() define two or more status fields? HOT 1
- Attach two workflow to a model HOT 1
- Two workflow in a model - disable validation between the two statuses HOT 1
- Migrate to yii3 HOT 1
- Model inheritance HOT 1
- Gridview filter dropdown HOT 2
- Event on enter workflow HOT 2
- Validation on dependant model HOT 2
- How to manage multiple workflows for same model? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-workflow.