I am finding that whenever I add a new group of features, I am adding the same glue-code over and over, so this issue will be used to review and consolidate those pieces where possible.

Common hooks necessary when adding new asset and log types in farmOS:

  • hook_farm_access_perms() - Defines default access permissions available to farmOS roles.
  • hook_farm_admin_actions() - Creates the action link buttons at the top of listing pages (ie: "Add a planting").
  • hook_farm_asset_breadcrumb() - Defines the breadcrumb path for assets.
  • hook_farm_asset_view_views() - Adds Views to asset pages.
  • hook_farm_taxonomy_breadcrumb() - Defines the breadcrumb path for taxonomy terms.
  • hook_farm_taxonomy_term_view_views() - Adds Views to taxonomy pages.
  • hook_farm_area_links() - Adds links to the area details popup.
  • hook_views_post_render() - Currently used to add cluster maps to asset listing pages.

Comments

m.stenta created an issue. See original summary.

m.stenta’s picture

Issue summary: View changes

Generalizing this because it goes beyond just assets (logs, taxonomies, area types, etc).

m.stenta’s picture

Project: Farm Asset » farmOS

Moving this to the farmOS project queue.

m.stenta’s picture

Title: Unified hook for defining asset types » Consolidate common asset and log type code
Issue summary: View changes

Generalizing this further, and updating the title and description...

m.stenta’s picture

Issue summary: View changes
m.stenta’s picture

Issue summary: View changes

  • m.stenta committed 9426172 on 7.x-1.x
    Issue #2563527: Consolidate common asset and log type code
    
m.stenta’s picture

Status: Active » Fixed

Ok! I've done a bunch of consolidation. I've moved most of the logic that was spread out across multiple hooks in multiple modules into a new Farm UI module. The primary things that Farm UI manages now are:

* Breadcrumbs
* Action links
* Views added to asset and term pages
* Area details links
* Entity reference argument to limit asset type options
* Rendering of asset cluster maps

The Farm UI module provides two hooks that other modules can use to leverage it:

* hook_farm_ui_entities() - Allows modules to describe the entities that they provide and their relationships to one another, which is used to automatically provide UI elements like breadcrumbs, action links, and Views.
* hook_farm_ui_entity_views() - Allows modules to add Views to asset and term pages. This replaces the old hooks: hook_farm_asset_view_views() and hook_farm_taxonomy_term_view_views()

I also consolidated a lot of the implementations of hook_farm_access_perms() into other modules in a general way so that it doesn't need to be implemented manually for each entity type.

The following hooks have been removed entirely:

* hook_farm_access_perms()
* hook_farm_admin_actions()
* hook_farm_asset_breadcrumb()
* hook_farm_asset_view_views()
* hook_farm_taxonomy_breadcrumb()
* hook_farm_taxonomy_term_view_views()
* hook_farm_area_links()
* hook_views_post_render()

Further, I dissolved the Farm Admin module into four other more specific modules: Farm People (which provides the People View), Farm Menu (which provides the "farm" menu), Farm Dashboard (provides the main dashboard page at /farm), and Farm Help (provides the /farm/help path and hook for modules to add to it).

So no, when a new module is created that provides entity types, the only hook it really needs to provide is hook_farm_ui_entities().

If it provides custom permissions, it also needs to implement hook_farm_access_perms(). If it provides custom Views that are not just standard entity listing Views for assets or logs, then it should also implement hook_farm_ui_entity_views() to add them to asset or term pages.

These changes reduced the codebase by over 1000 lines. But moreso, it streamlines and simplifies the code necessary to implement new features in farmOS. Great! :-)

Status: Fixed » Closed (fixed)

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