Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Designing Better UX For Left-Handed People

      July 25, 2025

      This week in AI dev tools: Gemini 2.5 Flash-Lite, GitLab Duo Agent Platform beta, and more (July 25, 2025)

      July 25, 2025

      Tenable updates Vulnerability Priority Rating scoring method to flag fewer vulnerabilities as critical

      July 24, 2025

      Google adds updated workspace templates in Firebase Studio that leverage new Agent mode

      July 24, 2025

      Trump’s AI plan says a lot about open source – but here’s what it leaves out

      July 25, 2025

      Google’s new Search mode puts classic results back on top – how to access it

      July 25, 2025

      These AR swim goggles I tested have all the relevant metrics (and no subscription)

      July 25, 2025

      Google’s new AI tool Opal turns prompts into apps, no coding required

      July 25, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Laravel Scoped Route Binding for Nested Resource Management

      July 25, 2025
      Recent

      Laravel Scoped Route Binding for Nested Resource Management

      July 25, 2025

      Add Reactions Functionality to Your App With Laravel Reactions

      July 25, 2025

      saasykit/laravel-open-graphy

      July 25, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Sam Altman won’t trust ChatGPT with his “medical fate” unless a doctor is involved — “Maybe I’m a dinosaur here”

      July 25, 2025
      Recent

      Sam Altman won’t trust ChatGPT with his “medical fate” unless a doctor is involved — “Maybe I’m a dinosaur here”

      July 25, 2025

      “It deleted our production database without permission”: Bill Gates called it — coding is too complex to replace software engineers with AI

      July 25, 2025

      Top 6 new features and changes coming to Windows 11 in August 2025 — from AI agents to redesigned BSOD screens

      July 25, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Multisite Maximum Item Validation for Content Area or Link Collection in Optimizely CMS-12.

    Multisite Maximum Item Validation for Content Area or Link Collection in Optimizely CMS-12.

    July 23, 2025

    This blog post will discuss MultiSite validation for either ContentArea or LinkItemCollection, which are both capable of storing multiple items. Although we can use the custom MaxItem attribute to validate the ContentArea or LinkItemCollection, the problem arises when the same property is used for multiple sites with different validation limits.

    In a recent project, we were tasked with migrating multiple websites into a single platform using Optimizely. These sites shared common ContentTypes wherever applicable, though their behavior varied slightly depending on the site.

    One of the main challenges involved a ContentType used as the StartPage with the same properties across different sites. While the structure remained the same, the validation rules for its properties differed based on the specific site requirements. A common issue was enforcing a maximum item validation limit on a property like a ContentArea, where each site had a different limit—for example, Site A allowed a maximum of 3 items, while Sites B and C allowed 4 and 5 items, respectively.

    To solve this multisite validation scenario, we implemented a custom validation attribute that dynamically validated the maximum item limit based on the current site context.

    Below are the steps we followed to achieve this.

    • Make a MaxItemsBySitesAttribute custom validation attribute class and add an AttributeUsage attribute with AllowMultiple = true.
    • Then inherit from ValidationAttribute as a base class. This class is used to provide server-side validation rules on content properties for Block, Page, or Media content types.
        [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
        public class MaxItemsBySitesAttribute : ValidationAttribute
        {
            private readonly string[] _siteName;
            private int _max;
    
            public MaxItemsBySitesAttribute(int max, params string[] siteName)
            {
                _max = max;
                _siteName = siteName;
            }
            protected override ValidationResult IsValid(object value, ValidationContext validationContext)
            {
                var siteSpecificLimit = GetSiteSpecificMaxLimitByFieldName(validationContext.MemberName, validationContext?.ObjectType?.BaseType);
                string errorMsg = $"{validationContext.DisplayName}, exceeds the maximum limit of {siteSpecificLimit} items for site {SiteDefinition.Current.Name}";
    
                if (value is ContentArea contentArea)
                {
                    if (contentArea.Count > siteSpecificLimit)
                    {
                        return new ValidationResult(errorMsg);
                    }
                }
                else if (value is LinkItemCollection linkItems)
                {
                    if (linkItems.Count > siteSpecificLimit)
                    {
                        return new ValidationResult(errorMsg);
                    }
                }
    
                return ValidationResult.Success;
            }
    
            private int GetSiteSpecificMaxLimitByFieldName(string fieldName, Type type)
            {
                var propertyInfo = type.GetProperty(fieldName);
                if (propertyInfo != null)
                {
                    var attributes = propertyInfo.GetCustomAttributes<MaxItemsBySitesAttribute>()?.ToList();
                    var siteMaxLimit = attributes.FirstOrDefault(x => x._siteName != null && 
                                                                 x._siteName.Any(site => site == SiteDefinition.Current.Name));
    
                    return siteMaxLimit == null ? 0 : siteMaxLimit._max;
                }
                return 0;
            }
        }
      • The function GetSiteSpecificMaxLimitByFieldName() in the above code played an important role in this class to retrieve decorated attribute(s) [MaxItemsBySites(2, “AlloyBlog”)] and [MaxItemsBySites(3, “AlloyDemo”, “AlloyEvents”)] with specified item limit counts and site names.
    • Then, decorate the [MaxItemsBySites] custom attribute(s) on the ContentArea or LinkItemCollection property by adding the maximum item limit and site(s) name as given below.
    public class StartPage : SitePageData
    {
        [Display(
            GroupName = SystemTabNames.Content,
            Order = 320)]
        [CultureSpecific]
        [MaxItemsBySites(2, "AlloyBlog")]
        [MaxItemsBySites(3, "AlloyDemo", "AlloyEvents")]
        public virtual ContentArea MainContentArea { get; set; }
    }
    • The attribute will receive a trigger and verify the maximum item limit and site name against the site that is currently running and display an error message below if validation matches.

    Site Specific Maxitem Validation Error

     

    By implementing site-specific maximum item validation in your Optimizely CMS multisite, content authors can ensure content consistency, enhance user experience, and maintain precise control over content areas and link collections across diverse properties in different sites.

    In case you want other validation by site-specific, you can use the same approach by changing the code accordingly.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleDesigning Human‑Centered GenAI Workflows for Business Process Automation
    Next Article Honeypot Fields in Sitecore Forms

    Related Posts

    Development

    Laravel Scoped Route Binding for Nested Resource Management

    July 25, 2025
    Development

    Add Reactions Functionality to Your App With Laravel Reactions

    July 25, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    CVE-2025-47754 – V-SFT EditData Out-of-Bounds Read Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    2025’s highest-rated Xbox game on Metacritic is coming to Game Pass in a matter of days — but you’ve never heard of it

    News & Updates

    CVE-2025-42959 – Apache HMAC Reuse Replay Attack

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-49483 – Falcon Linux, Kestrel, and Lapwing Linux ASR180x, ASR190x TR069 Resource Leak Exposure

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    This Linux distro routes all your traffic through the Tor network – and it’s my new favorite for privacy

    June 23, 2025

    I could easily see myself defaulting to Securonis when I need serious security. Source: Latest…

    CVE-2025-6102 – Wifi-soft UniBox Controller Os Command Injection Vulnerability

    June 16, 2025

    FBI and Europol Disrupt Lumma Stealer Malware Network Linked to 10 Million Infections

    May 22, 2025

    CVE-2025-48881 – Valtimo Object Management Configuration Information Disclosure

    May 30, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.