Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Draft
paul121 wants to merge11 commits intofarmOS:3.x
base:3.x
Choose a base branch
Loading
frompaul121:3.x-context
Draft

Contextual API#904

paul121 wants to merge11 commits intofarmOS:3.xfrompaul121:3.x-context

Conversation

@paul121
Copy link
Member

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:

  • A newFarmContext plugin that isContextAware to detect Asset, Log, Plan, etc entity types. Facilitate byFarmContextManager service.
    • Context aware plugins are a somewhat magical part of this. Initially, this allows us to easily get an entity based of the entity set in the route parameters/context + works nicely with Block plugin contexts.
    • But via the manager, this also provides a nice API of sorts to gather contextual information about an entity in other contexts, just set the necessary context and ask away. Could be useful for contextual information via API or other locations in UI
  • Context plugins can provide an array of messages with: a type (info/warning/etc), short text, long text, array of related links and a weight.
  • A new FarmContextBlock plugin that renders contextual info adetails element. An instance of this block is configured to render in thehelp region (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.

@paul121paul121 marked this pull request as draftDecember 21, 2024 00:33
@paul121
Copy link
MemberAuthor

Otherwise, today I was mostly playing with how the context block renders the messages into adetails element, working on how to format lists of short/long messages + links into the details title + summary. Here is a quick preview:

Screenshot from 2024-12-20 16-35-10

Some simple ideas for follow up:

  • Reduce padding/size of details element, see collapsible views filters/changes inUpdate to stable gin 4.0.0 release #903
  • Add some color/icons/list icon styles for different message types (info, warning, etc...)
  • Consider removing/drastically reducing the size of this on entity edit forms?

@paul121paul121 requested a review frommstentaJanuary 14, 2025 17:41
@mstenta
Copy link
Member

Rebased onto 3.x. Let's see if anything needs to be updated for the new PHPStan level, coding standards, etc.

Copy link
Member

@mstentamstenta left a 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
Copy link
Member

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 = [];
Copy link
Member

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(
Copy link
Member

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:
Copy link
Member

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
Copy link
Member

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.

paul121 reacted with thumbs up emoji

// @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
Copy link
Member

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?

Copy link
MemberAuthor

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?)

Copy link
Member

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(),
Copy link
Member

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...)

Copy link
MemberAuthor

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...

@mstentamstenta added this to thev4.0.0 milestoneFeb 25, 2025
@mstenta
Copy link
Member

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).

paul121 reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mstentamstentamstenta requested changes

Assignees

No one assigned

Labels

None yet

Milestone

v4.0.0

Development

Successfully merging this pull request may close these issues.

2 participants

@paul121@mstenta

[8]ページ先頭

©2009-2025 Movatter.jp