Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Martin Rud 255 posts 986 karma points c-trib
    20 days ago
    Martin Rud
    0

    Saving with DateFolders installed gives 'Cannot save content with an empty name'

    My solution:

    • Umbraco 13.4.0
    • Infocaster.Umbraco.DateFolders 11.0.0

    I have this in appSettings.json:

    "DateFolders": {
    "ItemDateProperty": "date",
    "CreateDayFolders": false,
    "OrderByDescending": true,
    "FolderDocType": "pageNewsFolder",
    "ItemDocTypes": ["pageNewsItem"]
    }
    

    I have property "date" of type Umbraco.DateTime on document type "pageNewsItem".

    When I save a pageNewsItem document, I get:

    An error occurred
    One or more errors occurred. (Cannot save content with an empty name.)
    
    Exception Details
    System.AggregateException, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e: One or more errors occurred. (Cannot save content with an empty name.)
    Stacktrace
    at Umbraco.Cms.Infrastructure.Scoping.Scope.TryFinally(Action[] actions)
       at Umbraco.Cms.Infrastructure.Scoping.Scope.Dispose()
       at Umbraco.Cms.Core.Services.ContentService.SaveAndPublish(IContent content, String[] cultures, Int32 userId)
       at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.PublishInternal(ContentItemSave contentItem, String defaultCulture, String cultureForInvariantErrors, Boolean& wasCancelled, String[]& successfulCultures)
       at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.PostSaveInternal[TVariant](ContentItemSave contentItem, Func`3 saveMethod, Func`2 mapToDisplay)
       at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.PostSave(ContentItemSave contentItem)
       at lambda_method5780(Closure, Object)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
    --- End of stack trace from previous location ---
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
    
  • Simon Napper 109 posts 343 karma points
    20 days ago
    Simon Napper
    0

    Are you sure it works with Umbraco 13? Looks like they've only gone as far as Umbraco 11 and it's not been worked on in 2 years.

    It is open source, perhaps it might be worth downloading it and seeing if you can fix the error? I'm sure they'll be happy if you can!

    https://github.com/Infocaster/Datefolders

  • Martin Rud 255 posts 986 karma points c-trib
    20 days ago
    Martin Rud
    0

    You are probably right. I had a "feeling" that I have it working on another Umbraco 13 project, but I can't find that project so maybe I remember it wrong.

    I'll conside looking at the source code, but right now I don't have the time.

    Is there a way to have all news directly under the same document, but rewriting urls so they become "year and month-ified"?

    I.e. mysite.com/news/2023/10/my-news-article

  • Simon Napper 109 posts 343 karma points
    20 days ago
    Simon Napper
    100

    I'd probably look at using a custom UrlProvider and ContentFinder, this should get you started if you want to try it:

    https://docs.umbraco.com/umbraco-cms/v/13.latest-lts/reference/routing/request-pipeline/outbound-pipeline#custom-url-provider

  • Martin Rud 255 posts 986 karma points c-trib
    20 days ago
    Martin Rud
    0

    That sounds like the solution I asked for now that DateFolders does not work. Therefore I mark it as solution.

    However; I did this instead:

    using Umbraco.Cms.Core.Events;
    using Umbraco.Cms.Core.Notifications;
    
    namespace MartinRud.ContentService;
    public class SavingAutomationAction : INotificationHandler<ContentSavingNotification>
    {
        public void Handle(ContentSavingNotification notification)
        {   
            foreach (var node in notification.SavedEntities)
            {
                if (node.ContentType.Alias == "pageNewsItem" && node.HasProperty("date") && node.HasProperty("umbracoUrlName")) 
                {
                    var cultures = node.AvailableCultures;
                    foreach (var culture in cultures)
                    {
                        if(node.GetValue("date", null) == null) continue;
    
                        var dateValue = node.GetValue<DateTime>("date", null);  // date property is not variable by culture; therefore culture is set to null
                        string umbracoUrlName = dateValue.ToString("yyyy-MM") + "-" + node.Name;
                        node.SetValue("umbracoUrlName", umbracoUrlName, culture);
                    }
                }
            }
        }
    }
    

    It's not creating physical year and month folder nodes and therefore urls are not like: mysite.com/news/2023/10/my-news-article

    but like: mysite.com/news/2023-10-my-news-article

    But it's ok for me for now. 😊

Please Sign in or register to post replies

Write your reply to:

Draft