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;
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mmartinov’s picture

Status: Active » Needs review
FileSize
2.86 KB

Here's the patch.

TravisCarden’s picture

Status: Needs review » Needs work

Thank 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!

mmartinov’s picture

Yes, 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?

TravisCarden’s picture

@mmartinov, what if we had a little offline conversation about entities? Contact me.

skek’s picture

Subscribing for the entity feature cause using the variables for this is not really nice.

ergonlogic’s picture

Issue summary: View changes
FileSize
2.86 KB

Updated patch.

ergonlogic’s picture

re. #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.

ergonlogic’s picture

Status: Needs work » Needs review
FileSize
10.51 KB

The 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.

TravisCarden’s picture

Thanks 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.

ergonlogic’s picture

Title: Attach checklists to nodes from content type » Attach checklists to entities as fields

Note that the attached patch for field support should also fix #1966114: Add support for per-user saved progress.

ergonlogic’s picture

FileSize
10.5 KB

Fixed trailing whitespace in patch.

ergonlogic’s picture

After a bit more use, here are a few more things to look at as part of adding support for checklists as fields:

  • Rather than clutter up the ChecklistapiChecklist class, maybe we should add a ChecklistapiChecklistField class that inherits from it, then overrides the necessary bits for fields support. I think this would mostly entail adding getSavedProgress() and setSavedProgress methods that would be called from __construct() and saveProgress() respectively.
  • That, in turn would allow easier cleanup of a couple remaining todos in clearSavedProgress() and hasSavedProgress().
  • We probably need per-checklist-per-entity-type permissions: '[view|edit] the <checklist_title> on <entity_type>', and so a new access function is probably in order.
ergonlogic’s picture

FileSize
12.29 KB

This patch addresses the first item from #12, adding a ChecklistapiChecklistField class that inherits from ChecklistapiChecklist, etc.

Still to do:

  • Clearing saved progress on checklist fields still needs work, as the menu and confirmation form need to be reworked to allow the entity id and field delta to be passed in.
  • Also, the new perms still to be added and checked.
generalredneck’s picture

Just 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.

ergonlogic’s picture

Commit 8a7a128f8 in my sandbox fixes the remaining todos from #13. We end up with lots of permissions, but that's the price of flexibility.

fourmi4x’s picture

Hi, 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!

TravisCarden’s picture

@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.

m.stenta’s picture

I 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!

LaurensV’s picture

I would love to see a module that can attach checklists to entities. @m.stenta: How far are you with your project?

m.stenta’s picture

@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.

TravisCarden’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
andy_w’s picture

I 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.

TravisCarden’s picture

Status: Needs review » Needs work

Thanks, @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.

vuil’s picture

Version: 8.x-1.x-dev » 2.0.x-dev