OrchardCore icon indicating copy to clipboard operation
OrchardCore copied to clipboard

Add DisplayAsync() overloads to render when a given feature is enabled

Open hishamco opened this issue 1 year ago • 8 comments

Related to https://github.com/OrchardCMS/OrchardCore/discussions/12014

hishamco avatar Jul 18 '22 14:07 hishamco

The only concern I have is that it makes that DisplayAsync call a little more expensive. Should we be concerned?

Skrypt avatar Jul 18 '22 15:07 Skrypt

BTW this just call when it's required. we might cache the enabled features but I though it's a bad idea, unless we can invalidate the cache when the feature is disabled

hishamco avatar Jul 18 '22 16:07 hishamco

@hishamco Technically this is not useful as all views are tied to module and not a feature

ns8482e avatar Jul 18 '22 17:07 ns8482e

At the beginning I thouth to pass a flag to ensure whether it's a module or feature. Either way the idea here is to ensure the shape isn't throws when the feature is disabled.

We could make the passed value accept module / feature

hishamco avatar Jul 18 '22 19:07 hishamco

Not sure it's a good thing, normally to validate/register things relying on a feature we have the manifest dependencies and the usage of the [Features()] attrubute. Or we have the [RequireFeatures()] to automatically validate things if a given feature(s) is enabled, e.g to execute a startup. Or a mix of both.

jtkech avatar Jul 18 '22 21:07 jtkech

I knew, @jtkech please refer to my PR #12017 to see the use case on action. Please let me know if there's a better way to display the admin culture

hishamco avatar Jul 18 '22 22:07 hishamco

I don't think we have an extension point allowing features to collaborate to this admin zone/section, as we do to shape compose a content item with drivers, but also as we do for admin menus, dashboard widgets and so on.

Hmm, maybe just do an extension helper to know if a given feature is enabled and use it in the admin view, if so I would make an extension on ShellDescriptor that you can inject, so that you just have to lookup in ShellDescriptor.Features so without calling _extensionManager.GetFeatures() as it is done by ShellFeaturesManager, this because you only need the feature names, not full IFeatureInfo.

Maybe just a local extension, or no extension at all, just use in the admin view

@inject ShellDescriptor ShellDescriptor
...
var isEnabled = shellDescriptor.Features.Any(sf => sf.Id == "OC.Localization");

And yes, as @ns8482e said a shape is not tied to an individual feature but to a module, that may have only one feature, itself ;) But yes, a shape may be only used by the components of a given feature.

jtkech avatar Jul 19 '22 06:07 jtkech

@inject ShellDescriptor ShellDescriptor
...
var isEnabled = shellDescriptor.Features.Any(sf => sf.Id == "OC.Localization");

if we can utilize this as extension method to render a shape optionally it will be good

hishamco avatar Jul 19 '22 10:07 hishamco

This pull request has merge conflicts. Please resolve those before requesting a review.

github-actions[bot] avatar Jan 29 '24 13:01 github-actions[bot]