Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork331
Contextual API#904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:3.x
Are you sure you want to change the base?
Contextual API#904
Uh oh!
There was an error while loading.Please reload this page.
Conversation
paul121 commentedDec 21, 2024
Otherwise, today I was mostly playing with how the context block renders the messages into a Some simple ideas for follow up:
|
…asset/log views tab pages
mstenta commentedFeb 25, 2025
Rebased onto 3.x. Let's see if anything needs to be updated for the new PHPStan level, coding standards, etc. |
mstenta left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Overall this looks good and makes sense@paul121! This will be a great addition!
I reviewed the commits to understand the overall architectural decisions, but I haven't tested or reviewed final UI yet. I'll plan to do that once everything else is ironed out.
We should add some automated tests. I'm thinking some kernel tests for the actual context plugin discovery logic, and a functional test for the block.
It would also be nice to include some documentation for module developers. Any developers building plan types that useplan_record entities instead of theplan andlog fields will need to write a plugin. Or maybe we can add a generic plugin forplan_record use-cases? 🤔
Lastly, I wonder if we should consider splitting the "core" bits offarm_ui_context out to afarm_context module, so that it could potentially still be used on a headless farmOS instance. I know this PR doesn't currently expose contextual information to the API (I see you mentioned that in your comments above though), but that could be useful in the future, and isn't "UI".
| dependencies: | ||
| -farm:farm_ui_action | ||
| -farm:farm_ui_breadcrumb | ||
| -farm:farm_ui_context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We'll need an update hook to enable this on existing sites.
| * {@inheritdoc} | ||
| */ | ||
| publicfunctiongetRuntimeContexts(array$unqualified_context_ids) { | ||
| $result = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks like a lot of this is copied from core, yea? Maybe it would be worth including a comment here to that effect, so future devs can refer back to the core code if updates are necessary etc (in plan and log contexts too).
| /** | ||
| * Provides a farm context block. | ||
| * | ||
| * @Block( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This needs to be changed from an annotation to an attribute.
| @@ -0,0 +1,23 @@ | |||
| langcode:en | |||
| status:true | |||
| dependencies: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Needs an enforced dependency so that it gets removed whenfarm_ui_context is uninstalled.
| theme: | ||
| -gin | ||
| id:farm_context | ||
| theme:gin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We'll need to figure out how to do this without an explicit dependency on Gin. We maintain the ability for downstream users to develop/use their own theme by encapsulating all Gin-specific stuff infarm_ui_theme.
Perhapsfarm_ui_theme could install this block, and depend onfarm_ui_context? 🤔
Then it would be the responsibility of downstream users with custom themes to add the block themselves, but at least all the other functionality of contexts would exist.
| // @todo Fix so that an asset context message displays on views tabs. | ||
| // This is needed so that the asset route parameter can pick up the route. | ||
| // General issue: https://www.drupal.org/project/drupal/issues/2528166 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'd like to understand this a bit more. It doesn't look like the core issue is getting much action recently, but I only skimmed it.
I see this commit is marked asTEMP: ... - what is the path forward here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Hmm yeah, afraid I don't remember if this change was enough to display the contextual info load on the "logs" tab for any given asset, or if this change also needs the core path... My hunch is that this change is enough but the comment is confusing.. but I should test.
I think this comment is a good summary of the issue:https://www.drupal.org/project/drupal/issues/2528166#comment-14855963 but yea, doesn't look like that will merge anytime soon because it could cause some breaking change (existing code that expects theasset parameter to only be an ID will fail if this is changed to start returning an entity object)
Tho there is also a larger question if we even want the asset's contextual information available on these pages? I see how this could be an issue if the contextual info UI takes up excessive space on the page but I hope that we can make the contextual information UI minimal enough so that there is little to no reason to ever not include on any "asset page"... otherwise we might as well isolate contextual information to a dedicated page and try to show it in other places... but IMO the ability to bubble up contextual info into more places/pages is the driving factor of this PR 😅
Anyways - adding this additionalasset route parameter to thisview.farm_log.page_asset route definition makes it possible for theContextProvider/AssetRouteContext class to provide the asset into the route's context on these pages without having to know the specific details about thisview.farm_log.page_asset route specifically. This is all important because the route context is used by theFarmContextBlock itself. When rendering an instance of theFarmContextBlock on a given entity page, assetl/log/etc, it means this context will be mapped directly from the route context.BUT the block's context can also be set manually, allowing for the ability to potentially render one or moreFarmContextBlock on demand for one or more entities in a given context (eg: maybe when interacting with the asset timeline?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks I think I understand a bit better now.
Tho there is also a larger question if we even want the asset's contextual information available on these pages?
Personally, I think the MVP only requires showing the contextual information on/asset/%. If it simplifies this PR to just do that as a first step, and then make next step decisions in follow-ups, I would be OK with that.
| // Query for plans the asset might be a part of. | ||
| $plans = \Drupal::entityTypeManager()->getStorage('plan')->loadByProperties([ | ||
| 'asset' =>$asset->id(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This is probably fine as-is, but we should confirm that this doesn't break on plans that do NOT include the defaultasset orlog reference fields. It's possible for downstream plan types to omit those if they want to take their own approach (or useplan_record entities).
(I thought thecrop andgrazing plan modules both did that, but it seems that they are still inheriting theasset andlog fields. That's a separate issue... those should be removed since they are not used by those plan types. I'll make note to follow up on that separately...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ah interesting. As long as there is one plan bundle that has aplan.asset field I do not think this would cause an issue - but yes, if there were no plan bundles that had thisplan.asset field, I can see how this might break. IIRCloadByProperties builds a simple entity API query behind the scenes which I do seem to remember failing when specified fields do not exist...
mstenta commentedFeb 25, 2025
This feels like a good feature to include in 4.0.0. I'm going to flag it with that milestone for now, but if we want to get it merged into 3.x I'm fine with that too. It isn't a breaking change, but I'm starting to feel like we're approaching an unofficial feature freeze on the 3.x branch (we've already decided to move#849 to the 4.0.0 milestone). |

Seehttps://gitlab.com/OpenTEAMAg/feedback/support_requests/-/issues/208
I've just dusted off my previous2.x-context branch and rebased on latest 3.x. Opening a draft PR so this doesn't get lost going forward.
I want to review some of the implementation details, but here is the current status and quick notes:
FarmContextplugin that isContextAwareto detect Asset, Log, Plan, etc entity types. Facilitate byFarmContextManagerservice.detailselement. An instance of this block is configured to render in thehelpregion (below task links and status messages).It's been almost 2 years but all of the above was still working with minimal changes :D It definitely needs a through review and could possible use new Drupal core APIs/PHP language features (attributes vs annotation, etc) BUT I think I do still feel good about this general architecture. It feels quite robust and can be adapted to our needs, but should evaluate this again as well.