OrchardCore
OrchardCore copied to clipboard
Add DisplayAsync() overloads to render when a given feature is enabled
Related to https://github.com/OrchardCMS/OrchardCore/discussions/12014
The only concern I have is that it makes that DisplayAsync call a little more expensive. Should we be concerned?
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 Technically this is not useful as all views are tied to module and not a feature
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
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.
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
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.
@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
This pull request has merge conflicts. Please resolve those before requesting a review.