Problem/Motivation

An user requested a way to see the nodes that reference a particular bean.

Proposed resolution

Provide a page (admin/content/blocks/bean-usage) that lists all beans (blockreferences) as well as what entities use them.

Remaining tasks

reviews needed

User interface changes

new URL path: admin/content/blocks/bean-usage

API changes

added new file bean.admin.inc in the includes folder for page display. (includes/bean.admin.inc)

Comments

Guito339’s picture

StatusFileSize
new6.67 KB

Please find patch attached.

Guito339’s picture

StatusFileSize
new6.67 KB
fmitchell’s picture

Assigned: Guito339 » fmitchell
Status: Patch (to be ported) » Needs review

Assigning to me to review.

indytechcook’s picture

Status: Needs review » Needs work

This is a neat idea but I think I'd rather see this at admin/reports/bean-usage that way it corresponds with other usage type reports.

fmitchell’s picture

Agreed.

It'd also be nice if when viewing a bean, we utilized the functions generating the report to show a list of linked nodes that reference it. I believe this was also part of the original intention of the request.

Gui, can you add those two changes?

1.) Put the callback under reports
2.) Provide an additional list of linked nodes on the bean view to show where it is being used as a blockreference so a user could jump to that node right away.

Guito339’s picture

StatusFileSize
new7 KB

I changed the link to admin/reports/bean/usage just in case we come up with something else to add under bean reports. I also added a permission for view bean usage as a user should not need to have 'administer beans' to view the usage report.

Guito339’s picture

StatusFileSize
new9.05 KB

Here is another patch with a 'Usage' tab on the bean view to see where the bean in being used with drill down links.

mrfelton’s picture

Can we get a screenshot?

skwashd’s picture

I had a quick look over this code and it seems to assume that everyone using BEAN will be using blockreference.module. The hook_menu implementation and other places that implement blockreference specific functionality need to be wrapped in if (module_exists('blockreference')) { ... } blocks to avoid introducing a hard dependency for the module.

Guito339’s picture

screenshots attached as per usage on Department of Energy.

Guito339’s picture

StatusFileSize
new9.08 KB

I wrapped the hook_menu_items content in an if (module_exists('blockreference)) { ... } in the latest patch (bean_usage_view-1649312-6164156.patch). This way the usage tab and report links will not display unless the blockreference module is installed and enabled.

fmitchell’s picture

The patch from #11 didn't apply cleanly to me. It looks like it might have been diff'd from an older version of bean.

The attached patch has been diff'd from the latest 7.x-1.x-dev.

I've put the usage into a separate module so we can easily add context and block admin usage later. This also makes it easier to add the blockreferences dependency.

I also pulled some (not all) of the queries out.

A couple of things for Guito339 to add just to /admin/reports/bean/usage callback, please:

  1. Paginate the bean usage results as some sites (like Energy.gov) have thousands of beans
  2. Make table headers sortable
  3. Pull in bean title as column between bean type and entity reference
  4. Provide filter for bean types

It may be easier to make the report a view as this will accomplish all of the above, but you'll then have to refactor your code to be a views handler. If it's a default view, this would also allow users to add other fields as they see fit. It's up to you.

fmitchell’s picture

StatusFileSize
new9.61 KB

Forgot patch

Guito339’s picture

Assigned: fmitchell » Guito339
StatusFileSize
new15.05 KB

The latest attachment off of 7.x-1.x has the sortable table headers, pagination, a form to set the number of results per page on the bean usage view and the added Bean title in between the label and entity id.

I am working on the filter next.

Guito339’s picture

Status: Needs work » Needs review
StatusFileSize
new15.35 KB

Attached is the next patch that includes all the table sorting, pagination, settings form and now the bean filter form. Please take a look and let me know if there is anything else that you'd like to see improved.

I did as much QA as I could, but having been working on this for a little over a week I might have missed something, so please QA as much as you can as well.

Guito339’s picture

StatusFileSize
new19.08 KB

Sorry guys! Patched from the wrong folder. Attached is the correct patch.

Guito339’s picture

StatusFileSize
new19.45 KB

Found a small issue with the usage view for the individual bean. fmitchell also found an issue when adding a new bean, where the bean wasn't showing up. I found an issue in the query and fixed it. All should be well now. Patch attached. Please review

fmitchell’s picture

I applied the patch on a vanilla install. Received a few errors:

Notice: Trying to get property of non-object in bean_usage_output() (line 102 of ../bean/bean_usage/bean_usage.module).
Notice: Trying to get property of non-object in bean_usage_output() (line 103 of ../bean/bean_usage/bean_usage.module).
Notice: Undefined index: filter in bean_usage_output() (line 110 of ../bean/bean_usage/bean_usage.module).
Notice: Undefined index: sort in bean_usage_output() (line 155 of ../bean/bean_usage/bean_usage.module).
Notice: Undefined index: filter in bean_usage_filters() (line 41 of ../bean/bean_usage/includes/bean_usage.forms.inc).
Strict warning: Only variables should be passed by reference in bean_usage_output() (line 299 of ../bean/bean_usage/bean_usage.module).

Once these are cleaned up, should be fine.

Guito339’s picture

StatusFileSize
new19.51 KB

I added the code to a vanilla install and fixed the notices and warnings.
Patch attached, please test and verify.

fmitchell’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.