Skip to content
This repository was archived by the owner on Sep 16, 2025. It is now read-only.

[FR] add component reference type support #101

@pgsfredda

Description

@pgsfredda

Hi.

No slug is generated for components.

I have analyzed the 'setting-service.js' file. I developed a possible fix that is working for me (see below).

With that fix, to produce the slug for the fields in a component, you have to set the plugin settings file field contentTypes using the value of the collectionName field used in the component configuration file.

Strapi: 4.11.4
Strapi Plugin Slugify: 2.3.3
MySQL: 8.0.30 (MySQL Community Server - GPL)

Here is a possible fix to generate a slug for components by changing the build method:

build(settings) {

	const buildModel = (contentType, uid, nameAttr,displayName) => {
		const model = settings.contentTypes[contentType[nameAttr]];
		if (!model) {
			return;
		}

		// ensure provided fields are present on the model
		const hasField = isValidModelField(contentType, model.field);
		if (!hasField) {
			strapi.log.warn(
				`[slugify] skipping ${contentType.info[displayName]} registration, invalid field provided.`
			);
			return;
		}

		let references = _.isArray(model.references) ? model.references : [model.references];
		const hasReferences = references.every((referenceField) =>
			isValidModelField(contentType, referenceField)
		);

		if (!hasReferences) {
			strapi.log.warn(
				`[slugify] skipping ${contentType.info[displayName]} registration, invalid reference field provided.`
			);
			return;
		}

		const data = {
			uid,
			...model,
			contentType,
			references,
		};
		settings.modelsByUID[uid] = data;
		settings.modelsByName[contentType[nameAttr]] = data;
	};

	// build models
	settings.modelsByUID = {};
	settings.modelsByName = {};
	
	_.each(strapi.contentTypes, (contentType, uid) => buildModel(contentType, uid, 'modelName', 'singularName'));
	_.each(strapi.components, (contentType, uid) => buildModel(contentType, uid, 'collectionName', 'displayName'));

	_.omit(settings, ['contentTypes']);

	return settings;
}
      

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions