Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

NopDocReferenceTagHelper.cs

using Microsoft.AspNetCore.Razor.TagHelpers;
using Nop.Core.Domain.Common;

namespace Nop.Web.Framework.TagHelpers.Admin;

/// 
/// "nop-doc-reference" tag helper
/// 
[HtmlTargetElement("nop-doc-reference", Attributes = STRING_RESOURCE_ATTRIBUTE_NAME, TagStructure = TagStructure.WithoutEndTag)]
public partial class NopDocReferenceTagHelper : TagHelper
{
    #region Constants

    protected const string STRING_RESOURCE_ATTRIBUTE_NAME = "asp-string-resource";
    protected const string ADD_WRAPPER_ATTRIBUTE_NAME = "asp-add-wrapper";

    #endregion

    #region Fields

    protected readonly AdminAreaSettings _adminAreaSettings;

    #endregion

    #region Ctor

    public NopDocReferenceTagHelper(AdminAreaSettings adminAreaSettings)
    {
        _adminAreaSettings = adminAreaSettings;
    }

    #endregion

    #region Methods

    /// 
    /// Asynchronously executes the tag helper with the given context and output
    /// 
    /// Contains information associated with the current HTML tag
    /// A stateful HTML element used to generate an HTML tag
    /// A task that represents the asynchronous operation
    public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
    {
        ArgumentNullException.ThrowIfNull(context);

        ArgumentNullException.ThrowIfNull(output);

        //clear the output
        output.SuppressOutput();

        if (_adminAreaSettings.ShowDocumentationReferenceLinks)
        {
            //add wrapper
            if (AddWrapper)
            {
                output.TagName = "div";
                output.TagMode = TagMode.StartTagAndEndTag;
                output.Attributes.SetAttribute("class", "documentation-reference");
            }

            var hintHtml = $"{StringResource}";
            output.Content.AppendHtml(hintHtml);
        }

        return Task.CompletedTask;
    }

    #endregion

    #region Properties

    /// 
    /// String resource value
    /// 
    [HtmlAttributeName(STRING_RESOURCE_ATTRIBUTE_NAME)]
    public string StringResource { get; set; }

    /// 
    /// Indicates whether the wrapper tag should be added
    /// 
    [HtmlAttributeName(ADD_WRAPPER_ATTRIBUTE_NAME)]
    public bool AddWrapper { get; set; } = true;

    #endregion
}