Node tools — расширяем возможности hook_node_info() для настройки комментариев, отображения и прочих вещей из кода!

Прислано: Stutzer

пн, 09/01/2012 - 07:54

Давно мучился с проблемой — создаешь с помощью hook_node_info() новый типа контента, но все равно приходится лезть в интерфейс и настраивать в ручную такие параметры, как отображение комментариев, настройки публикации, отображение даты/автора и прочие вещи, которые hook_node_info() не охватывает. Иногда, конечно, хватает времени и терпения прописать все необходимые с помощью variable_set, но это неудобно.

Наконец, терпение лопнуло и пара часов была потрачена на благо человечества, результатом чего стал небольшой модуль nodetools (пока лежит на github)

Все, что он делает, это позволяет в hook_node_info указывать дополнительные свойства создаваемого типа контента.
Его использование выглядит следующим образом:

<?php
function hook_node_info() {
  return array(
    
'customtype' => array(
      
'name' => t('Custom node type'),
      
'base' => 'custom',
      
'has_title' => TRUE,
      
'title_label' => t('Custom node type title'),
      
'has_body' => FALSE,
      
'body_label' => t('Custom node type body'),
      
'locked' => TRUE,

      
/**
       * ----------------
       * Extra properties
       * ----------------
       */

      /**
       *  Submission form settings (core functional)
       *  ------------------------------------------
       *
       *  Preview before submitting
       *    node_preview_{$type}
       *    value <int>:
       *      0 => Disabled
       *      1 => Optional
       *      2 => Required
       */
      
'node-preview' => 0,

      
/**
       *  Publishing options (core functional)
       *  ------------------------------------
       *
       *  Default options
       *    node_options_{$type}
       *    value <array>:
       *      array('status', 'promote', 'sticky', 'revision')
       */
      
'node-options' => array('status'),

      
/**
       *  Display settings
       *  ----------------
       *
       *  Display author and date information
       *    node_submitted_{$type}
       *    value <int>:
       *      0 => Hide author and date information
       *      1 => Display author and date information
       */
      
'node-submitted' => 0,

      
/**
       *  Comment settings
       *  ----------------
       */
      
'comment' => array(
        
/**
         *  Default comment setting for new content
         *    comment_{$type}
         *    values <int>:
         *      0 => hidden
         *      1 => closed
         *      2 => open
         */
        
'status' => 2,

        
/**
         *  Threading
         *    comment_default_mode_{$type}
         *    values <int>:
         *      0 => don't show
         *      1 => show
         */
        
'default-mode' => 1,

        
/**
         *  Allow anonimous to leave commentns
         *       comment_anonymous_{$type}
         *    values <int>:
         *      0 => forbid
         *      1 => allow
         */
        
'anonymous' => 1,

        
/**
         *  Comments per page
         *    comment_default_per_page_{$type}
         *    values <int>:
         *      10, 30, 50, 70, 90, 150, 200, 250, 300
         */
        
'default-per-page' => 50,

        
/**
         *  Show reply form on the same page as comments
         *    comment_form_location_{$type}
         *    values:
         *      0 => hide
         *      1 => show
         */
        
'form-location' => 1,

        
/**
         *  Preview comment
         *    comment_preview_{$type}
         *    values <int>:
         *      0 => disabled
         *      1 => optional
         *      2 => required
         */
        
'preview' => 0,

        
/**
         *  Allow comment title
         *    comment_subject_field_{$type}
         *    values <int>:
         *      0 => disallow
         *      1 => allow
         */
        
'subject-field' => 0,
      ),
    ),
  );
}
?>

Возможно, модуль еще сыроват, хотя у меня уже все работает.
Уверен, многим пригодится :)

P.S. Можете поддержать анонс на хабре

Комментарии


Настройки просмотра комментариев

Выберите нужный метод показа комментариев и нажмите "Применить"
Опубликовано sas@drupal.org в пн, 09/01/2012 - 09:20.

Спасибо друг, за твои труды праведные и за то, что делишься ими с ближнем.


Опубликовано validoll в пн, 09/01/2012 - 11:28.

Такие вещи я делаю с помощью  Features


Опубликовано RxB в пн, 09/01/2012 - 12:19.

"validoll" написал(а):

Такие вещи я делаю с помощью Features

+1