2017-05-04 2 views
1

Drupal 8에서 프로그래밍 방식으로 뷰를 만들려고합니다. Drupal 7에서 crud 로그 모듈과 비슷한 점이 있습니다. 인터넷에서 참조를 찾을 수도 없습니다. \ XAMPP \ htdocs를 \ 드루팔 인스턴스 \ 모듈 2. YML 정보 파일을 만듭니다 : C -프로그래밍 방식으로 Drupal 8 뷰를 만드는 방법

+0

정말로보기 (Drupal의 용어로보기)를 만들거나 사용자 지정 데이터베이스 쿼리를 만들려고합니까? – MilanG

+0

"프로그램"을 "보기"로 만들려고했습니다. 어제 당신의 답변에 감사드립니다 ... 어제 그것을 만들었습니다. – Rekha

답변

0

나는 내가 following-- 1. 폴더를 생성 한 ---- 프로그래밍 방식으로 뷰를 만드는 데 성공했다 --first_view.info하고 다음 코드를 추가 ---- 이름 : 먼저보기 유형 : 모듈 설명 : 나의 첫 드루팔 8보기 패키지 : 사용자 정의 핵심 : 8.x의 3.이 파일을 설치 만들기 --- first_view.install 그리고 다음 코드를 추가하십시오.

<?php 

/** 
* @file 
* Install, schema, and uninstall functions for the First View module. 
*/ 

use Drupal\field\Entity\FieldStorageConfig; 
use Drupal\taxonomy\Entity\Term; 

/** 
* Implements hook_install(). 
*/ 
function first_view_install() { 

} 

/** 
* Implements hook_uninstall(). 
*/ 
function first_view_uninstall() { 

} 

/** 
* Implements hook_schema(). 
*/ 
function first_view_schema() { 
$schema['first_view_table'] = [ 
    // Example (partial) specification for table "node". 
    'description' => 'The base table for first_view.', 
    'fields' => [ 
     'id' => [ 
     'description' => 'The primary identifier for a node.', 
     'type' => 'serial', 
     'unsigned' => TRUE, 
     'not null' => TRUE, 
     ], 
     'name' => [ 
     'description' => 'The name of Employee.', 
     'type' => 'varchar', 
     'length' => 32, 
     'not null' => TRUE, 
     'default' => '', 
     ], 
     'age' => [ 
     'description' => 'The age of employee.', 
     'type' => 'int', 
     'unsigned' => TRUE, 
     'not null' => TRUE, 
     'default' => 0, 
     ], 
     'is_active' => [ 
     'description' => 'The activity of employee.', 
     'type' => 'int', 
     'not null' => TRUE, 
     'default' => 0, 
     ], 
     'timestamp' => [ 
     'description' => 'The timestamp of employee.', 
     'type' => 'int', 
     'unsigned' => TRUE, 
     'not null' => TRUE, 
     'default' => 0, 
     ], 
     'project_code' => [ 
     'description' => 'The project code of employee.', 
     'type' => 'varchar', 
     'length' => 32, 
     'not null' => TRUE, 
     'default' => 0, 
     ], 
    ], 

    'unique keys' => [ 
     'id' => ['id'], 
    ], 
    // For documentation purposes only; foreign keys are not created in the 
    // database. 

    'primary key' => ['id'], 
    ]; 
    return $schema; 
} 

4.은 --- first_view.views.inc 을 파일을 생성하고 추가 다음 코드를 위의 단계에 따라

<?php 

/** 
* Implements hook_views_data(). 
*/ 
function first_view_views_data() { 




    $data = []; 


    $data['first_view_table'] = []; 
    $data['first_view_table']['table'] = []; 
    $data['first_view_table']['table']['group'] = t('First View table'); 
    $data['first_view_table']['table']['provider'] = 'first_view_module'; 

    $data['first_view_table']['table']['base'] = [ 

    'field' => 'id', 
    'title' => t('First View table'), 
    'help' => t('First View table contains example content and can be related to nodes.'), 
    'weight' => -10, 
    ]; 


    $data['first_view']['table']['join'] = [ 

    'node_field_data' => [ 
     'left_field' => 'id', 
     'field' => 'id', 
     'extra' => [ 
     0 => [ 
      'field' => 'published', 
      'value' => TRUE, 
     ], 
     1 => [ 
      'left_field' => 'age', 
      'value' => 1, 
      'numeric' => TRUE, 
     ], 
     2 => [ 
      'field' => 'published', 
      'left_field' => 'is_active', 
      'operator' => '!=', 
     ], 
     ], 
    ], 
    ]; 


    $data['first_view_table']['table']['join']['node_field_data'] = [ 

    'left_table' => 'foo', 
    'left_field' => 'id', 
    'field' => 'id', 
    'extra' => [ 
     ['left_field' => 'project_code', 'field' => 'project_code'], 
     ['field' => 'age', 'value' => 0, 'numeric' => TRUE, 'operator' => '>'], 
    ], 
    ]; 


    $data['first_view_table']['id'] = [ 
    'title' => t('Example content'), 
    'help' => t('Relate example content to the node content'), 

    'relationship' => [ 
     'base' => 'node_field_data', 
     'base field' => 'id', 
     'id' => 'standard', 
     'label' => t('Example node'), 
    ], 
    ]; 


    $data['first_view_table']['name'] = [ 
    'title' => t('Name'), 
    'help' => t('Just a Name field.'), 
    'field' => [ 
     'id' => 'standard', 
    ], 

    'sort' => [ 
     'id' => 'standard', 
    ], 

    'filter' => [ 
     'id' => 'string', 
    ], 

    'argument' => [ 
     'id' => 'string', 
    ], 
    ]; 


    $data['first_view_table']['project_code'] = [ 
    'title' => t('Project Code'), 
    'help' => t('Just a Project code field.'), 
    'field' => [ 
     'id' => 'standard', 
    ], 

    'sort' => [ 
     'id' => 'standard', 
    ], 

    'filter' => [ 
     'id' => 'string', 
    ], 

    'argument' => [ 
     'id' => 'string', 
    ], 
    ]; 

    $data['first_view_table']['age'] = [ 
    'title' => t('Age'), 
    'help' => t('Just a numeric field.'), 

    'field' => [ 
     'id' => 'numeric', 
    ], 

    'sort' => [ 
     'id' => 'standard', 
    ], 

    'filter' => [ 
     'id' => 'numeric', 
    ], 

    'argument' => [ 
     'id' => 'numeric', 
    ], 
    ]; 


    $data['first_view_table']['is_active'] = [ 
    'title' => t('Is Active'), 
    'help' => t('Just an on/off field.'), 

    'field' => [ 
     'id' => 'boolean', 
    ], 

    'sort' => [ 
     'id' => 'standard', 
    ], 

    'filter' => [ 
     'id' => 'boolean', 
     'label' => t('Published'), 
     'type' => 'yes-no', 
     'use_equal' => TRUE, 
    ], 
    ]; 


    $data['first_view_table']['timestamp'] = [ 
    'title' => t('Timestamp'), 
    'help' => t('Just a timestamp field.'), 

    'field' => [ 
     'id' => 'date', 
    ], 

    'sort' => [ 
     'id' => 'date', 
    ], 

    'filter' => [ 
     'id' => 'date', 
    ], 
    ]; 


    $data['views']['area'] = [ 
    'title' => t('Text area'), 
    'help' => t('Provide markup text for the area.'), 
    'area' => [ 
     'id' => 'text', 
    ], 
    ]; 

    return $data; 
} 

을 그건 ...하는 .... 우리가 설치할 때와 사용 가능 모듈이 데이터베이스에서 생성되는 모듈 ... 뷰의 일부 데이터를보기 위해 채워 넣어야합니다 ... 더미 데이터를 테이블에 추가하는 것을 잊지 마십시오 ..... 그 후에 구조 /보기 --- "보기 추가"를 클릭하십시오 ----보기에 이름을 지정하십시오 --- 그러면 "보기"드롭 다운 상자에서 테이블 이름을 볼 수 있습니다 ---이 경우 테이블 이름은 "First View Table"입니다.이 기사가 도움이 되었기를 바랍니다 ....

관련 문제