Creo un “Sharepoint 2013 – Empty Project”
Deployo la solución como farm solution
Agrego el mapeo de la carpeta
A continuación agrego un Module
Borramos Sample.txt
Agregamos de nuevo el archivo .spcolor dentro de la carpeta Theme
A continuación edito el archivo Elements.xml, agregando lo siguiente
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="Theme" Url="_catalogs/theme/15">
    <File Path="Theme\custom.spcolor" Url="custom.spcolor"
          Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />
  </Module>
</Elements>
Renombramos la feature
Hacemos doble click sobre la fature, y editamos el título y descripción. También cambiamos ell scope a “Site”
Deployamos la solución y vemos que ya está el archivo en el folder C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\GLOBAL\Lists\themes
También vemos que se deployó el archivo spcolor dentro de la carpeta themes/15
Ahora lo que vamos a hacer es que cuando se active la feature, se setee el theme donde se activa la feature
Para ello, agregamos un event receiver a la feature
Agregamos el siguiente código en el método FeatureActivated
public override void FeatureActivated(SPFeatureReceiverProperties properties)
       {
               SPSite siteCollection = (SPSite)properties.Feature.Parent;
               //activo esta feature para el root web del site collection donde se activa esta feature.
               var web = siteCollection.RootWeb;
               if (web == null)
               {
                   return;
               }
               var uri = new Uri(web.Url);
               var url = uri.AbsolutePath;
               if (url.Equals("/"))
               {
                   url = string.Empty;
               }
               var colorPaletteUrl = url + "/_catalogs/theme/15/custom.spcolor";
               var fontSchemeUrl = url + "/_catalogs/theme/15/SharePointPersonality.spfont";
               string backgroundImageUrl = null;
               const bool shareGenerated = true;
               web.ApplyTheme(colorPaletteUrl, fontSchemeUrl, backgroundImageUrl, shareGenerated);                    
       }
Una vez que deployan la solución, y activan la feature, se ve que se activa el custom color deployado
Que pasa si creamos un sub-site dentro del site collection? Debería tambien setear el custom color al subsite. Para ello creamos un event receiver de tipo
Dentro del método WebProvisioned, agregamos lo siguiente
base.WebProvisioned(properties);// esta bien que se ejecute primero
            SPWeb website = properties.Web;
           
            SPSite siteCollection = properties.Web.Site;
            string colorPaletteUrl = SPUrlUtility.CombineUrl(siteCollection.ServerRelativeUrl, "_catalogs/theme/15/custom.spcolor");
            string fontSchemeUrl = SPUrlUtility.CombineUrl(siteCollection.ServerRelativeUrl, "_catalogs/theme/15/SharePointPersonality.spfont");
            string backgroundImageUrl = null;
            const bool shareGenerated = true;          
properties.Web.ApplyTheme(colorPaletteUrl, fontSchemeUrl, backgroundImageUrl, shareGenerated);
Revisamos que se agregue dentro de la feature, el event receiver.
Deployamos de nuevo, y cuand creemos una nuevo sub-site, y la feature esté activada a nivel de site collection, le seteará el custom color al subsite.
En el caso que nos olvidemos de
Referencias:
http://msdn.microsoft.com/en-us/library/office/jj945889(v=office.15).aspx
http://msdn.microsoft.com/en-us/library/office/jj927175(v=office.15).aspx
Deploy via powershell: http://social.technet.microsoft.com/wiki/contents/articles/23510.sharepoint-2013-deploy-and-apply-theme-to-sharepoint-sites-with-powershell.aspx
No hay comentarios:
Publicar un comentario