The request comes from ticket #1198388: Checker only works on the core "body" field and on sites without localization. The goal is that besides the node body, content in cck fields would be checked as well.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

spidersilk’s picture

I may be able to help with this. I'm working on a site now for a client who would like this module to check more fields than just the body, so if I have to figure out a way to make it work for them, hopefully I can find a way to apply the work I do for them for other people as well.

Tentatively thinking of having it look for all fields of the "Long text" (or Long text with summary) type and check all of them, since that would at least include any fields with a considerable amount of text, regardless of their names. But we'll see what I can get to work...

I'm also working on finding a way to have it check image fields as well as images in the body, so again, if I can get that to work I'll happily contribute my code.

spidersilk’s picture

So, I just got this working! To a limited extent, anyway...

My modified version looks through all the node's fields, checks to see if they're of the "long text" or "long text and summary" type, and if they are, it adds their content to the $body variable (even if the node doesn't actually have any fields called "body"), and then analyzes the whole thing.

It even looks for field collections (created with the Field Collection module), and when it finds one, goes through as many instances as it has, checking each one for long text fields. (I added this mainly because the client project I'm working on right now uses that.)

It no longer returns false if there's no body field - only if there are no long text fields at all.

It seems to work well, but it's not the most elegant solution - ideally it would be nice to be able to choose which fields to check within the SEO Compliance Checker settings for each content type, and maybe have the results for each one reported separately. But hey, at least it's checking more fields than just the body now!

I am determined, this weekend, to finally learn how to make patches with Git, and make one for this modification. Also, I'll be tackling the issue of alt text for image fields later this evening and tomorrow, and will hopefully have a patch for that too before the end of the weekend.

spidersilk’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
11.17 KB

OK, here's a (rather large) patch that addresses this issue and a few others. List of changes:

  • Keyword density rule now searches all long-text fields, not just the body (including long-text fields within field collections, if the Field Collection module is installed). Note that it does not (yet) present separate results for each field, or allow you to pick and choose which fields are checked - it just combines all the long-text fields and treats them all as part of the body.
  • So does the image alt attribute rule.
  • The image alt attribute rule also now checks image fields, not just images inserted in text fields.
  • Two new helper functions were added to seo_checker.module, which are used in the new versions of the above two rules, but could also be useful for people creating their own rules. One goes through the #form_values array and collects all the fields into a new array - and can optionally be narrowed to collect only fields of a particular type (i.e., just images, just long-text fields, etc.). The other concatenates all long-text fields that are found into one long string.
  • I also fixed a number of typos I spotted in help text, descriptions, etc., because I'm kind of compulsive about that sort of thing. :)

This patch definitely needs testing before it can be committed - I tested it on two sites, but there are many different configurations and module combinations it has not been tested with, so please feel free to try it out and provide feedback.

Also - this is only the second patch I've created, and I'm still getting used to Git, so hopefully I haven't made any major errors on that front. I guess we'll see...