Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] add component reference type support #101

Open
pgsfredda opened this issue Jul 12, 2023 · 2 comments
Open

[FR] add component reference type support #101

pgsfredda opened this issue Jul 12, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@pgsfredda
Copy link

pgsfredda commented Jul 12, 2023

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;
}
      
@pgsfredda pgsfredda changed the title No slug generated for components and for the 'relation' fields No slug generated for components and for the 'relation' fields (a possible fix) Jul 12, 2023
@pgsfredda pgsfredda changed the title No slug generated for components and for the 'relation' fields (a possible fix) No slug generated for components (a possible fix) Jul 12, 2023
@ComfortablyCoding
Copy link
Contributor

ComfortablyCoding commented Aug 10, 2023

Thanks for the request and suggestion. For now this plugin only supports fields define don the model directly.

I will at some point add relational and component support. At the moment their is no eta for that.

I am thinking instead to change how the settings work. For reference fields it will allow for a string or object. In object mode you can specify the path and type (field,relation,component) that the reference field is.

@ComfortablyCoding ComfortablyCoding added the enhancement New feature or request label Aug 10, 2023
@ComfortablyCoding ComfortablyCoding changed the title No slug generated for components (a possible fix) [FR] add component reference type support Aug 22, 2023
@RayHughes
Copy link

RayHughes commented Aug 24, 2023

Also requesting support for object reference. Example: We have categories like cat cat2 and we would like to be able to auto generate cat/article cat2/article2

Each category has a field on it called slug path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants