Access Orchard Content Part Buttons (Save and Publish Now)

560 Views Asked by At

I want to disable Orchard Content Part buttons (Save and Publish Now) in the EDITOR template (when Content Item is created) based on some conditions. Can I do that ? How do I access the buttons in the EDITOR view.

1

There are 1 best solutions below

0
On

Here are come examples,

To build a content fully from a Controller example, taken from the Blog Module

public ActionResult Create() {
        if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Not allowed to create blogs")))
            return new HttpUnauthorizedResult();

        BlogPart blog = Services.ContentManager.New<BlogPart>("Blog");
        if (blog == null)
            return HttpNotFound();

        dynamic model = Services.ContentManager.BuildEditor(blog);
        // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
        return View((object)model);
    }

    [HttpPost, ActionName("Create")]
    public ActionResult CreatePOST() {
        if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't create blog")))
            return new HttpUnauthorizedResult();

        var blog = Services.ContentManager.New<BlogPart>("Blog");

        _contentManager.Create(blog, VersionOptions.Draft);
        dynamic model = _contentManager.UpdateEditor(blog, this);

        if (!ModelState.IsValid) {
            _transactionManager.Cancel();
            // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
            return View((object)model);
        }

        _contentManager.Publish(blog.ContentItem);
        return Redirect(Url.BlogForAdmin(blog));
    }

BuidEditor does the work for you.

And you should use a alternative version of this template, but remove the edit link and publish link.

Note, you need a route for you custom create action, and a menu link on the dashboard may come in handy.