Status:
Pending resolution of #3474212: Create a new architecture for checklists as config entities, with tasks fulfilled by conditions.
Original report
I would like to propose a patch which will allow me to "attach" a checklist to all nodes of certain content type by implementing the following two hooks:
/**
* Implements hook_node_view().
*/
function onboarding_node_view($node, $view_mode, $langcode) {
if ($node->type === 'new_employee' && $view_mode === 'full') {
$form = drupal_get_form('onboarding_checklist_form', $node->nid);
$form['title'] = array(
'#markup' => '<h2>' . $form['#checklist']->title . '</h2>'
);
$node->content['onboarding_checklist'] = $form;
}
}
/**
* Form callback for Onboarding checklist.
*/
function onboarding_checklist_form($form, &$form_state, $nid) {
module_load_include('inc', 'checklistapi', 'checklistapi.pages');
$delta = '_node_' . $nid;
$form = checklistapi_checklist_form($form, $form_state, 'onboarding', $delta);
unset($form['actions']['clear'], $form['compact_mode_link']);
return $form;
}
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | checklistapi-checklist_fields-2056411-13.patch | 12.29 KB | ergonlogic |
| #6 | add_checklist_delta-2056411-6.patch | 2.86 KB | ergonlogic |
| #1 | add_checklist_delta-2056411-1.patch | 2.86 KB | mmartinov |
Comments
Comment #1
mmartinov commentedHere's the patch.
Comment #2
traviscarden commentedThank you, @mmartinov; that's a clever patch. My concern here is that checklist progress is currently stored in Drupal persistent variables, and since those all get loaded into memory on every bootstrap in Drupal 7, that could quickly become a performance problem for sites of any scale. I like the idea, though—it's actually been on my own wishlist for a bit. I think that how I'd like to accomplish it is to make Checklists entities that can be attached to content types as fields. That will be a big job, though, and won't come through soon. In the meantime, if you understand the implications of your patch and you know it won't be a problem in your use case, you could probably go ahead and use it yourself. If you have any experience with entities and fields and would like to help out there, I would welcome that, too. Best wishes!
Comment #3
mmartinov commentedYes, I do understand the implications of using the variables system. Just needed a fast solution for a business problem and came up with that. Going to use it until the entities thing is done. And yes, I would like to help with that. How do you think we could start?
Comment #4
traviscarden commented@mmartinov, what if we had a little offline conversation about entities? Contact me.
Comment #5
skek commentedSubscribing for the entity feature cause using the variables for this is not really nice.
Comment #6
ergonlogicUpdated patch.
Comment #7
ergonlogicre. #2, what would be the benefit of defining Checklist entities? It seems like a simpler solution would be to just define a Checklist field type. This would get us db-backed storage when attached to entities, but we could leave the existing implementation for global checklists. It seems like it'd at least be a step in the right direction, and make converting to entities later easier.
Comment #8
ergonlogicThe attached patch implements checklists as fields. The site-wide checklists remain unchanged, so it shouldn't break any APIs. It provides a simple select widget, to choose from among the defined checklists, and the formatter simply displays the checklist form.
Comment #9
traviscarden commentedThanks for the patch, @ergonlogic! I'm excited to look at it, but I'm indisposed this week. I'll give it a look as soon I'm able.
Comment #10
ergonlogicNote that the attached patch for field support should also fix #1966114: Add support for per-user saved progress.
Comment #11
ergonlogicFixed trailing whitespace in patch.
Comment #12
ergonlogicAfter a bit more use, here are a few more things to look at as part of adding support for checklists as fields:
Comment #13
ergonlogicThis patch addresses the first item from #12, adding a ChecklistapiChecklistField class that inherits from ChecklistapiChecklist, etc.
Still to do:
Comment #14
generalredneckJust an observation. If a Checklist Item was an entity (not specifically the list itself) then you could do some really cool stuff with views by querying on items that have been cleared or not on certain days and what not.
Comment #15
ergonlogicCommit 8a7a128f8 in my sandbox fixes the remaining todos from #13. We end up with lots of permissions, but that's the price of flexibility.
Comment #16
fourmi4x commentedHi, I was wondering, has this in some way been ported to drupal 8, or is it planned?
Would there still be performance issues in trying to doing it?
Thanks!
Comment #17
traviscarden commented@fourmi4x: This patch has not been ported to Drupal 8 unless someone has done so on the side. I would still like to pursue making checklists into fields, but I wouldn't take the approach in this patch. I don't personally expect to have the time to work on it in the foreseeable future, though.
Comment #18
m.stentaI am interested in doing something along the lines of what @generalredneck describes in comment #14 above, using the Log module (http://drupal.org/project/log) for the individual checklist item entities. I created a new issue to explore that idea in more detail: #2876152: Integrate with Log module - input and ideas would be welcome!
Comment #19
LaurensV commentedI would love to see a module that can attach checklists to entities. @m.stenta: How far are you with your project?
Comment #20
m.stenta@LaurensV: I'm working towards a tight project deadline right now, and checklist integration may or may not end up being part of it. If it is, then I will likely be creating entities from checklists, rather than the other way around. Specifically, this will be my approach: #2876152: Integrate with Log module
If that doesn't happen during this project, I may still pursue it in the future, but I'm not sure when.
Comment #21
traviscarden commentedComment #22
andy_w commentedI know this is an old thread, but I needed some similar functionality to attach a checklist to an entity and ended up doing something using entity references and borrowing heavily from the UI of checklist api, but for a different use case.
https://www.drupal.org/project/checklist_entity_reference
Not sure if there would be any way to make checklist api do this sort of thing, if so I don't want to duplicate effort.
Comment #23
traviscarden commentedThanks, @andy_w. You're not duplicating effort. There's no way to do what you're accomplishing with Checklist API itself today.
Also, marking this "Needs work", since the latest patch would need to be ported to Drupal 8 before it could be reviewed.
Comment #24
vuilComment #25
traviscarden commentedClosing this in favor of #3474212: Create a new architecture for checklists as config entities, with tasks fulfilled by conditions.
Comment #26
traviscarden commentedActually, the fieldable use case may actually be out of scope for that issue. Let's call it a dependency instead.