private void DeployHideContentTypeLinks(object modelHost, ContentType contentType, RemoveContentTypeFieldLinksDefinition 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.DeleteObject();
                }
            }

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