# Objects type for theme setting

**URL:** https://meta.discourse.org/t/objects-type-for-theme-setting/305009
**Category:** Developer Guides
**Tags:** how-to, theme-guides
**Created:** [April 23, 2024, 6:24am UTC](https://meta.discourse.org/t/objects-type-for-theme-setting/305009 "2024-04-23T06:24:06Z")
**Posts on this page:** 1
**Showing post:** 37

<div class="post-metadata">

### Author: ![singi2016cn](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/singi2016cn/32/532755_2.png) [@singi2016cn](https://meta.discourse.org/u/singi2016cn)
#### Post date: [April 13, 2026, 1:45am UTC](https://meta.discourse.org/t/objects-type-for-theme-setting/305009/37 "2026-04-13T01:45:38Z")

</div>

Yes, I am referring to limiting the maximum number of items in the `objects` array.

Currently, this is not supported out of the box, so I extended the functionality in a custom private theme component. Here is the configuration (for reference only):

Configuration for maximum array count limit:

`themes/quectel-custom-homepage/settings.yml`

```yaml
banner_images:
  type: objects
  default: []
  schema:
    name: "Carousel"
    max: 9 // New extended configuration to limit the maximum number of items in the array
    identifier: image_url
    properties:
      image_url:
        type: upload
        required: true
      link_url:
        type: string
        min: 0
        max: 1023

```

Extended code:

`themes/quectel-custom-homepage/javascripts/discourse/api-initializers/quectel-custom-homepage.gjs`

```glimmer-javascript
import { action } from "@ember/object";
import { apiInitializer } from "discourse/lib/api";
import classPrepend from "discourse/lib/class-prepend";
import { i18n } from "discourse-i18n";

export default apiInitializer(() => {
  // Use classPrepend to extend the SchemaSettingNewEditor component to support the max limit for objects type
  // Load this component only in the admin context
  let SchemaSettingNewEditor;
  try {
    SchemaSettingNewEditor =
      require("discourse/admin/components/schema-setting/editor").default;
  } catch {
    // Non-admin users cannot load this component, skip extension
    return;
  }

  classPrepend(SchemaSettingNewEditor, (Superclass) => {
    return class extends Superclass {
      @action
      addItem() {
        // Check if the max limit is reached
        const maxLimit = this.args.setting.max || this.activeSchema?.max;

        if (maxLimit && this.activeData.length >= maxLimit) {
          this.validationErrorMessage = i18n(
            themePrefix("theme_settings.errors.objects_value_not_valid_max"),
            {
              count: maxLimit,
            }
          );
          return;
        }

        return super.addItem(...arguments);
      }

      @action
      addChildItem(propertyName, parentNodeIndex) {
        const propertySchema = this.activeSchema.properties[propertyName];

        // Check if the max limit is reached
        if (
          propertySchema?.max &&
          this.activeData[parentNodeIndex][propertyName].length >=
            propertySchema.max
        ) {
          this.validationErrorMessage = i18n(
            themePrefix("theme_settings.errors.objects_value_not_valid_max"),
            {
              count: propertySchema.max,
            }
          );
          return;
        }

        return super.addChildItem(...arguments);
      }
    };
  });
});

```

Theme translation configuration:

`themes/quectel-custom-homepage/locales/en.yml`

```yaml
en:
  theme_settings:
    errors:
      objects_value_not_valid_max: "The number cannot exceed %{count}"

```

Actual effect:

 ![image](https://global.discourse-cdn.com/meta/original/4X/c/f/7/cf7d47e0424f6113c9f27cf610c6346309ad5340.png)

1. Error message
2. Unable to add more items

---

_[View the full topic](https://meta.discourse.org/t/objects-type-for-theme-setting/305009)._
