private void DeployHideContentTypeLinks(object modelHost, ContentType contentType, HideContentTypeFieldLinksDefinition hideFieldLinksModel)
        {
            var context = contentType.Context;

            context.Load(contentType, c => c.FieldLinks);
            context.ExecuteQueryWithTrace();

            var fieldLinks = contentType.FieldLinks.ToList();

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = contentType,
                ObjectType = typeof(ContentType),
                ObjectDefinition = hideFieldLinksModel,
                ModelHost = modelHost
            });

            // re-order
            foreach (var srcFieldLink in hideFieldLinksModel.Fields)
            {
                FieldLink currentFieldLink = null;

                if (!string.IsNullOrEmpty(srcFieldLink.InternalName))
                    currentFieldLink = fieldLinks.FirstOrDefault(c => c.Name == srcFieldLink.InternalName);

                if (currentFieldLink == null && srcFieldLink.Id.HasValue)
                    currentFieldLink = fieldLinks.FirstOrDefault(c => c.Id == srcFieldLink.Id.Value);

                if (currentFieldLink != null)
                {
                    currentFieldLink.Required = false;
                    currentFieldLink.Hidden = true;
                }
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = contentType,
                ObjectType = typeof(ContentType),
                ObjectDefinition = hideFieldLinksModel,
                ModelHost = modelHost
            });
        }
 public static ModelNode AddHideContentTypeFieldLinks(this ModelNode model, HideContentTypeFieldLinksDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNode(definition, action);
 }
 public static ModelNode AddHideContentTypeFieldLinks(this ModelNode model, HideContentTypeFieldLinksDefinition definition)
 {
     return AddHideContentTypeFieldLinks(model, definition, null);
 }