나는 이것이 매우 어려울 것이라고 생각했지만, 꽤 쉽다는 것이 밝혀졌습니다.
설치시 노드 테이블에 열을 추가하고 hook_schema_alter()Drupal이 새 열에 대해 알도록 구현 하고 노드를 저장하기 전에 값을 제공하는 논리를 추가 하는 사용자 정의 모듈 만 작성하면 됩니다.
트릭을 수행하는 작은 모듈이 있습니다.
파일 : node_table_alter.info
name = Node Table Alter
core = 7.x
파일 : node_table_alter.install
function node_table_alter_install() {
// Add the new field to the node table
$field = array(
'description' => 'Stores the user id of the last user to alter the node',
'type' => 'int',
'unsigned' => TRUE
);
db_add_field('node', 'changed_by', $field);
}
파일 : node_table_alter.module
function node_table_alter_schema_alter(&$schema) {
// Add the new field to the schema cache
$schema['node']['fields']['changed_by'] = array(
'description' => 'Stores the user id of the last user to alter the node',
'type' => 'int',
'unsigned' => TRUE
);
}
function node_table_alter_node_presave($node) {
// Populate the changed_by column with current user's id
$node->changed_by = $GLOBALS['user']->uid;
}
설치 제거시 필드를 다시 제거하는 논리를 추가하고 changed_by열의 테이블에 색인을 추가 할 수 db_add_index()있지만 (참조 ) 시작하기에 좋은 장소가됩니다.
이 방법의 장점은 노드에 새 속성을 효과적으로 추가했다는 것입니다. 노드의 다른 표준 속성 인 것처럼 node_load(), EntityFieldQuerys 등 을 사용할 수 있습니다 .
신이 Drupal에게 그렇게 확장 될 수 있도록 축복 해주세요!