Closed (fixed)
Project:
farmOS
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
5 Sep 2015 at 02:17 UTC
Updated:
12 Jul 2017 at 14:39 UTC
Jump to comment: Most recent
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:
Comments
Comment #2
m.stentaGeneralizing this because it goes beyond just assets (logs, taxonomies, area types, etc).
Comment #3
m.stentaMoving this to the farmOS project queue.
Comment #4
m.stentaGeneralizing this further, and updating the title and description...
Comment #5
m.stentaComment #6
m.stentaComment #8
m.stentaOk! 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! :-)