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

Make all template field info fields available. #28

Merged
merged 1 commit into from
Oct 6, 2019

Conversation

jbreuer
Copy link
Contributor

@jbreuer jbreuer commented Aug 27, 2019

When adding custom fields to the template field those can't be accessed in the current version. This PR makes those fields available.

For example I've added a 'Do not auto generate' and 'Do not edit in Experience Editor' field:

generate1

So per template field you can manage this:

generate2

With this info available I made some changes to the GlassMapper.csx file:

public static readonly System.Guid DoNotAutoGenerateId = new System.Guid("{CA075FD6-5BDD-44E6-881F-74AE42568C44}");
public static readonly System.Guid DoNotEditInExperienceEditorId = new System.Guid("{97A75B68-9E59-4F97-84F7-AD9CC4D081B3}");

public string RenderInterfaceFields(TemplateCodeGenerationMetadata template)
{
    var localCode = new System.Text.StringBuilder();

    foreach (var field in template.OwnFields)
    {
        var autoGenerate = !field.AllFields.ContainsKey(DoNotAutoGenerateId) || field.AllFields[DoNotAutoGenerateId] != "1";
        var isEditable = !field.AllFields.ContainsKey(DoNotEditInExperienceEditorId) || field.AllFields[DoNotEditInExperienceEditorId] != "1";

        if (autoGenerate)
        {
        localCode.AppendLine($@"
        /// <summary>{field.HelpText}</summary>
        [SitecoreField(FieldId = {template.Namespace}.Constants.{template.CodeName}.Fields.{field.CodeName}IdString)]
        [ExperienceEditor(IsEditable = {isEditable.ToString().ToLower()})]
        public virtual {GetFieldType(field)} {field.CodeName} {{ get; set; }}");
        }
    }

    return localCode.ToString();
}

So by making custom field info also accessible you become much more flexible in creating your own custom GlassMapper.csx.

There are some more examples, but I will blog about those soon.

@blipson89 blipson89 changed the base branch from master to dev August 29, 2019 01:27
blipson89 added a commit that referenced this pull request Aug 29, 2019
@blipson89
Copy link
Owner

@jbreuer I created a new branch called 28-AllFields and merged dev into it. I made a couple minor changes there as well.

Basically, while reviewing your code, I noticed something that was already in Leprechaun that I wanted to clean up. I cleaned that up and then updated your code to match.

I tested it on my end and it works. Would you like to pull down that branch (28-AllFields) and confirm before I merge it in?


As a side note, I will be referencing this pull request whenever I need to show any of my devs an example of how to properly write a description in a pull request 😁

@jbreuer
Copy link
Contributor Author

jbreuer commented Aug 29, 2019

Hi @blipson89,

I've tested the 28-AllFields branch and everything works. I've checked the changes you've made and those are all good improvements!

Hopefully this can be released soon.

Regards, Jeroen Breuer

@jbreuer
Copy link
Contributor Author

jbreuer commented Sep 2, 2019

Is this PR going to be closed since you did all the work in the 28-AllFields branch? Is there anything I can help with?

@jbreuer
Copy link
Contributor Author

jbreuer commented Sep 16, 2019

Hi @blipson89,
Do you have a status update about the 28-AllFields branch?
Regards, Jeroen Breuer

@blipson89 blipson89 merged commit 0cc50bc into blipson89:dev Oct 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants