【问题标题】:Best approach to limit users to a single node of a given content type in Drupal将用户限制在 Drupal 中给定内容类型的单个节点的最佳方法
【发布时间】:2010-05-03 05:57:21
【问题描述】:

我需要将用户限制为给定内容类型的单个节点。所以一个用户只能创建一个TypeX节点。我想出了两种方法。哪个更好用...

1) 编辑node/add/typex菜单项,查看数据库,查看用户是否已经创建了TypeX的节点,以及是否有权限创建。

2) 当用户创建 TypeX 节点时,将其分配给无权创建该类型节点的不同角色。

在方法 1 中,我必须在每个页面加载时进行额外的数据库调用,以查看他们是否应该能够看到“创建 TypeX”(节点/添加/类型 x)。但在方法 2 中,我必须保持两个独立的角色。

您会使用哪种方法?

【问题讨论】:

    标签: drupal drupal-6 roles limit


    【解决方案1】:

    http://drupal.org/project/node_limit

    UPDATE:这个更好,一周前更新,第一个一年不更新

    http://drupal.org/project/node_limitnumber

    【讨论】:

    • i menan 方法 1) 如果您有需要硬核优化的千兆站点,可能会更好
    • 哇,我以为我已经彻底查看了 contrib 模块......你猜不是。感谢您的链接。如果有人适合我,我会接受答案
    • 最终发现一位开发人员已经让角色切换方法起作用了,所以我们不会搞砸它。但我很欣赏这些链接,并且将来可能会发现需要这些模块之一
    【解决方案2】:

    如果您愿意,可以研究OnlyOne 模块(沙盒)的代码,以了解实现此目的的简单方法。

    Only One 模块允许为每种语言创建 Only One 节点 在此配置的选定内容类型中。

    /**
     * Implements hook_form_alter().
     * @param $form
     * @param $form_state
     * @param $form_id
     */
    function onlyone_form_alter(&$form, &$form_state, $form_id) {
      $onlyone_content_types = variable_get('onlyone_node_types');
      //getting the name of the node type
      $node_type = substr($form_id, 0, -10);
    
      //Verifying if the new node should by onlyone
      if (isset($onlyone_content_types) && in_array($node_type, $onlyone_content_types, TRUE)) {
        $node = $form_state['node'];
        //if we are trying to create a new node
        if (!isset($node->nid) || isset($node->is_new)) {
          $query = new EntityFieldQuery();
          $query->entityCondition('entity_type', 'node')
            ->entityCondition('bundle', $node_type);
    
          if (drupal_multilingual()) {
            global $language;
            $query->propertyCondition('language', $language->language);
          }
    
          $result = $query->execute();
          //if we have one node, then redirect to the edit page
          if (isset($result['node'])) {
            $nid = array_keys($result['node'])[0];
            drupal_goto('node/' . $nid . '/edit');
          }
        }
      }
    }
    

    披露:我是模块OnlyOne的维护者。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      • 2014-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多