【问题标题】:Override defaults page option in apostropheCMS覆盖撇号CMS中的默认页面选项
【发布时间】:2018-01-02 23:35:32
【问题描述】:

我想让“已发布”选项默认设置为“假”,而不是“真”。

我试图在撇号自定义页面中使用它:

但它不起作用! 你能帮忙吗?

谢谢

编辑:完整的 index.js 也许我的默认选项在其他地方被覆盖了?

var _ = require('lodash');

module.exports = {

  extend: 'apostrophe-doc-type-manager',

  beforeConstruct: function(self, options) {

options.name = options.name || self.__meta.name.replace(/\-pages$/, '-page');

if (options.permissionsFields === undefined) {
  // By default, pages have nuanced permissions
  options.permissionsFields = true;
}

options.addFields = [
  {
    type: 'boolean',
    name: 'published',
    label: 'Published',
    def:false
  },
    {
      type: 'slug',
      name: 'slug',
      label: 'Slug',
      required: true,
      // with this flag, a leading / is enforced, and slashes
      // elsewhere are allowed etc.
      page: true
    },
    {
      type: 'select',
      name: 'type',
      label: 'Type',
      required: true,
      choices: _.map(options.apos.pages.typeChoices, function(type) {
        return {
          value: type.name,
          label: type.label
        };
      })
    },
    {
      type: 'boolean',
      name: 'orphan',
      label: 'Hide in Navigation'
    }
].concat(options.addFields || []);

options.arrangeFields = [
  {
    name: 'basics',
    label: 'Basics',
    fields: [ 'meta-description', 'title', 'slug', 'type','alaune', 'color', 'published', 'tags', 'orphan' ]
  }
].concat(options.arrangeFields || []);

},

construct: function(self, options) {
require('./lib/dispatch.js')(self, options);
require('./lib/api.js')(self, options);
}
};

哈哈,我喜欢这个网站,但是如果没有更多的 cmets,我就无法发布我的代码!好吧,我的问题很容易解释。

所以 .. 我要感谢 apostrophe-cms 团队所做的出色工作^^ 以及 Tom 的耐心支持!

【问题讨论】:

  • 应该可以。你把它放在beforeConstruct 吗?请发布更完整的代码。谢谢!
  • 你好汤姆,谢谢你的回复可以在另一个文件上覆盖这个默认选项吗?

标签: apostrophe-cms


【解决方案1】:

事实证明,新页面的发布状态是从其父页面继承的。这是在apostrophe-pagesnewChild 方法中实现的。

老实说,这是一个非常有用的规则,因此您可能只想创建顶级页面,手动将它们设置为不发布,然后利用二级页面的规则等。

或者,暂时取消发布您的主页,即使是顶级页面也不会发布(显然在发布后您不想再这样做了)。

但是如果这些场景都不能真正满足您的需求,您可以通过“超级模式”扩展newChild 方法来做您想做的事情:

// in lib/modules/apostrophe-pages/index.js of your own project.
// DO NOT modify it in node_modules, that is NEVER NECESSARY

module.exports = {
  construct: function(self, options) {
    var superNewChild = self.newChild;
    self.newChild = function(parentPage) {
      var child = superNewChild(parentPage);
      child.published = false;
      return child;
    };
  }
};

我们会考虑一个拉取请求来为apostrophe-pages 模块实现一个类似unpublishNewChildPages 的标志。那么上面的代码可能是newChild的原始实现的一部分。

仅供参考,您共享的代码似乎是整个模块的过于完整的副本,如果您只是想覆盖一件事,则不需要将整个模块复制到项目级别(而且您不应该,它让您对我们以后所做的任何更改负责)。您的核心 Apostrophe 模块的项目级版本会自动继承原始版本,因此您可以覆盖个别内容而不必担心原始代码 - 它仍然会运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-22
    相关资源
    最近更新 更多