Skip to content

Instantly share code, notes, and snippets.

View nathanwoulfe's full-sized avatar

Nathan Woulfe nathanwoulfe

View GitHub Profile
@nathanwoulfe
nathanwoulfe / UmbracoCustomIndexer
Created June 24, 2015 04:33
Index Archetype content in Umbraco - a custom search indexer
namespace Your.Namespace {
class CustomIndexer : UmbracoContentIndexer {
protected override Dictionary<string, string> GetDataToIndex(XElement node, string type)
{
Dictionary<string,string> data = base.GetDataToIndex(node, type);
string content = "";
if (data.ContainsKey("archetypeAlias"))
@nathanwoulfe
nathanwoulfe / youtube-tracking.js
Last active August 13, 2017 23:19
An example AngularJs directive using the YouTube iFrame API, pushing events into the GTM datalayer
// functional demo at http://www.usc.edu.au/open-day#sessions
(function() {
'use strict'
function hubVideo() {
var video = {
restrict: 'E',
replace: true,
scope: {
@nathanwoulfe
nathanwoulfe / WhereIsMyMockedUser.cs
Created April 12, 2018 05:50
Where is my mocked user? How do I get him onto my context?
public GroupControllerTests()
{
// do some other setup stuff first
Mock<WebSecurity> webSecurity = new Mock<WebSecurity>(null, null);
// only need a couple of properties, enough to build a string and stuff
var currentUser = Mock.Of<IUser>(u =>
u.IsApproved
&& u.Name == Utility.RandomString()
@nathanwoulfe
nathanwoulfe / nunpublish.js
Created June 5, 2018 10:19
Hide the unpublish button for members of the editor group
/* package.manifest...
*
* {
* "javascript" : ["~/App_Plugins/nunpublish/script.js"]
* }
*/
(function () {
function directive(authResource) {
@nathanwoulfe
nathanwoulfe / events.cs
Created June 7, 2018 03:13
Events from an interface
// interface
public interface IService
{
// other stuff, but nothing related to events
}
// inheriting class
public class Service : IService
{
public static event EventHandler<MyEventArgs> SomethingHappened;
@nathanwoulfe
nathanwoulfe / plugin.min.js
Created June 16, 2018 05:22
Restore anchors in TinyMce
/* this has been heavily edited for brevity */
tinymce.PluginManager.add('link', function (editor) {
/* ... */
function showDialog(linkList) {
/* ... */
var selectedElm = selection.getNode();

In case you missed it, Umbraco 8 dropped almost by surprise in the last week of February.

Along with a massive refactoring of lots of code of which I have absolutely no understanding, v8 introduces something I do understand - Content Apps.

Since you're reading Skrift, I'm hoping you're up to speed with the latest and greatest from Umbraco HQ, and content apps (or the term, at least), aren't an entirely new concept. If you're reading this and thinking 'Content Whats?', duck over to the Umbraco documentation and read up on the shiny new feature.

Content apps are beautifully described in that documentation as 'companion read-only information relating to the current content item in the Umbraco backoffice'.

Note the emphasis on companion and read-only. Content apps are not an interface for updating a node, but for supplying additional information for making our editors' jobs more pleasant.

@nathanwoulfe
nathanwoulfe / MapHttpAttributeRoutes.cs
Created February 4, 2019 09:29
MapHttpAttributeRoutes
// v7 version
using System.Web.Http;
using Umbraco.Core;
namespace MyNamespace
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
@nathanwoulfe
nathanwoulfe / installer.cs
Created February 4, 2019 09:43
Bang some tables into a fresh v8 install. Is this the right way to do it? It smells smelly.
// namespaces and usings omitted for brevity
//
public class WorkflowInstallMigration : Upgrader
{
private readonly MigrationPlan _plan;
private readonly IScopeProvider _scopeProvider;
private readonly IMigrationBuilder _migrationBuilder;
private readonly IKeyValueService _keyValueService;
2019-02-06 19:45:14,333 [P18512/D2/T11] ERROR Umbraco.Web.Editors.ContentController - Unhandled controller exception occurred for request 'http://localhost:62128/umbraco/backoffice/UmbracoApi/Content/PostSave'
System.ArgumentNullException: Value cannot be null.
Parameter name: user
at Umbraco.Core.Security.ContentPermissionsHelper.CheckPermissions(IContent content, IUser user, IUserService userService, IEntityService entityService, Char[] permissionsToCheck)
at Umbraco.Web.Editors.Filters.ContentSaveValidationAttribute.ValidateUserAccess(ContentItemSave contentItem, HttpActionContext actionContext)
at Umbraco.Web.Editors.Filters.ContentSaveValidationAttribute.OnActionExecuting(HttpActionContext actionContext)
at System.Web.Http.Filters.ActionFilterAttribute.OnActionExecutingAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task