General methods of drupal8 and drupal7 modules

Source: Internet
Author: User
Tags php file table name drupal multisite

The bate version of drupal8 has come out, and I have nothing to worry about. I found that the directory structure has changed a lot. The theme and module of the website should be in the root directory themes and modules. Also compatible with d7 sites/all/

This is what readme in sites says.

This directory structure contains the settings and configuration files specific
To your site or sites and is an integral part of multisite configurations.

It is now recommended to place your custom and downloaded extensions in
/Modules,/themes, and/profiles directories located in the Drupal root.
Sites/all/subdirectory structure, which was recommended in previous versions
Of Drupal, is still supported.

See core/INSTALL.txt for information about single-site installation or
Multisite configuration.

About modules

Then I read the d8 module directory and the dblog module, and found that this is how watchdog records are inserted into the database.

The name. module file is the most eye-catching, similar to d7.

<? Php
 
/**
* @ File
* System monitoring and logging for administrators.
 *
* The Database Logging module monitors your site and keeps a list of recorded
* Events containing usage and performance data, errors, warnings, and similar
* Operational information.
 *
* @ See watchdog ()
*/
 
Use Drupal \ Core \ Form \ FormStateInterface;
Use Drupal \ Core \ Routing \ RouteMatchInterface;
 
/**
* Implements hook_help ().
*/
Function dblog_help ($ route_name, RouteMatchInterface $ route_match ){
Switch ($ route_name ){
Case 'Help. page. Dblog ':
$ Output = '';
$ Output. = '$ Output. = '<p> '. t ('The Database Logging module logs system events in The Drupal database. for more information, see the online handbook entry for the <a href = "! Dblog "> Database Logging module </a>. ', array ('! Dblog' => 'http: // drupal.org/documentation/modules/dblog'). '</p> ';
$ Output. = '$ Output. = '<dl> ';
$ Output. = '<dt>'. t ('monitoring your site'). '</dt> ';
$ Output. = '<dd>'. t ('The Database Logging module allows you to view an event log on The <a href = "! Dblog "> Recent log messages </a> page. the log is a chronological list of recorded events containing usage data, performance data, errors, warnings and operational information. administrators shoshould check the log on a regular basis to ensure their site is working properly. ', array ('! Dblog' => \ Drupal: url ('dblog. Overview'). '</dd> ';
$ Output. = '<dt>'. t ('destgging site problems ').' </dt> ';
$ Output. = '<dd>'. t ('in case of errors or problems with the site, the <a href = "! Dblog "> Recent log messages </a> page can be useful for debugging, since it shows the sequence of events. the log messages include usage information, warnings, and errors. ', array ('! Dblog' => \ Drupal: url ('dblog. Overview'). '</dd> ';
$ Output. = '</dl> ';
Return $ output;
 
Case 'dblog. Overview ':
Return '<p> '. t (The Database Logging module monitors your website, capturing system events in a log (shown here) to be reviewed by an authorized individual at a later time. this log is a list of recorded events containing usage data, performance data, errors, warnings and operational information. it is vital to check the Recent log messages report on a regular basis, as it is often the only way to tell what is going on. '). '</p> ';
  }
}
 
/**
* Implements hook_menu_links_discovered_alter ().
*/
Function dblog_menu_links_discovered_alter (& $ links ){
If (\ Drupal: moduleHandler ()-> moduleExists ('search ')){
$ Links ['dblog. Search'] = array (
'Title' => 'top search phrases ',
'Route _ name' => 'dblog. Search ',
'Description' => '<a href = "/project/views" class = "alinks-link" title = "module Introduction: Provides a question mark ?? Yes ?? Sexual approach ,?? Station managers can easily ??? ? The F method of a zombie is hot. Can it? Do ?? And? ^? K ,? K using tables, summaries, full text, RSS, etc? Zombie F. "> View </a> most popular search phrases .',
'Parent' => 'system. admin_reports ',
);
  }
 
Return $ links;
}
 
/**
* Implements hook_cron ().
 *
* Controls the size of the log table, paring it to 'dblog _ row_limit 'messages.
*/
Function dblog_cron (){
// Cleanup the watchdog table.
$ Row_limit = \ Drupal: config ('dblog. Settings')-> get ('row _ limit ');
 
// For row limit n, get the wid of the nth row in descending wid order.
// Counting the most recent n rows avoids issues with wid number sequences,
// E.g. auto_increment value> 1 or rows deleted directly from the table.
// The select statement of the data does not change significantly.
If ($ row_limit> 0 ){
$ Min_row = db_select ('watchdog', 'w ')
-> Fields ('W', array ('wid '))
-> OrderBy ('wid', 'desc ')
-> Range ($ row_limit-1, 1)
-> Execute ()-> fetchField ();
 
// Delete all table entries older than the nth row, if nth row was found.
// Delete is not very large
If ($ min_row ){
Db_delete ('watchdog ')
-> Condition ('wid', $ min_row, '<')
-> Execute ();
    }
  }
}
 
/**
* Gathers a list of uniquely defined database log message types.
 *
* @ Return array
* List of uniquely defined database log message types.
*/
Function _ dblog_get_message_types (){
Return db_query ('select DISTINCT (type) FROM {watchdog} order by type ')
-> FetchAllKeyed (0, 0 );
}
 
/**
* Implements hook_form_FORM_ID_alter () for system_logging_settings ().
*/
// The hook assumes that the from write method is the same as the original one.
Function dblog_form_system_logging_settings_alter (& $ form, FormStateInterface $ form_state ){
$ Row_limits = array (100,100 0, 10000,100 000, 1000000 );
$ Form ['dblog _ row_limit '] = array (
'# Type' => 'select ',
'# Title' => t ('database log messages to keep '),
'# Default_value' => \ Drupal: config ('dblog. Settings')-> get ('row _ limit '),
'# Options' => array (0 => t ('all') + array_combine ($ row_limits, $ row_limits ),
'# Description' => t ('the maximum number of messages to keep in The database log. requires a <a href = "@ cron"> cron maintenance task </a>. ', array (' @ cron' => \ Drupal: url ('system. status ')))
);
 
$ Form ['# submit'] [] = 'dblog _ logging_settings_submit ';
}
 
/**
* Form submission handler for system_logging_settings ().
 *
* @ See dblog_form_system_logging_settings_alter ()
*/
/* This is already written by someone else.
* However, I am very interested in the \ Drupal class and remind me of some of the previous yii projects, there should be an aotoload automatic class loading method <span style = "display: none;"> </span> to load third-party class libraries
* \ Drupa should be the/core/lib/drupal. Php file, and then the drupal folder is displayed. I wonder if it will be used for integration with other third-party class libraries.
* For example, fpdf or phpexecl
* Currently, this is purely a speculation. I will discuss it later.
*/
Function dblog_logging_settings_submit ($ form, FormStateInterface $ form_state ){
\ Drupal: config ('dblog. settings')-> set ('row _ limit ', $ form_state-> getValue ('dblog _ row_limit')-> save ();
}

Changed name.info to dblog.info. yml.

The name. install file has not been viewed before. However, if the d7 schema module is used, the generated. install file content should be the same,

Abbreviations

Function dblog_schema (){
$ Schema ['watchdog'] = array (// watchdog table name
'Description' => 'table that contains logs of all system events. ', // Table description
'Fields' => array (
'Wid' => array (// field name
'Type' => 'Serial', // field type
'Not Null' => TRUE, // whether to allow null
'Description' => 'primary Key: Unique watchdog event ID .',//
),
'Uid' => array (
'Type' => 'int ',
'Unsigne' => TRUE,
'Not Null' => TRUE,
'Default' => 0,
'Description' => 'The {users}. uid of the user who triggered the event .',
),
'Type' => array (
'Type' => 'varchar ',
'Length' => 64,
'Not Null' => TRUE,
'Default' => '',
'Description' => 'type of log message, for example "user" or "page not found ."',
),
'Message' => array (
'Type' => 'text ',
'Not Null' => TRUE,
'Size' => 'Big ',
'Description' => 'text of log message to be passed into the t () function .',
),
'Variables '=> array (
'Type' => 'blob ',
'Not Null' => TRUE,
'Size' => 'Big ',
'Description' => 'serialized array of variables that match the message string and that is passed into the t () function .',
),
'Severity '=> array (
'Type' => 'int ',
'Unsigne' => TRUE,
'Not Null' => TRUE,
'Default' => 0,
'Size' => 'tiny ',
'Description' => 'The severity level of The event; ranges from 0 (Emergency) to 7 (Debug )',
),
'Link' => array (
'Type' => 'varchar ',
'Length' => 255,
'Not Null' => FALSE,
'Default' => '',
'Description' => '<a href = "/project/link" class = "alinks-link" title = "module Introduction: similar to File Field and Image Field, link also adds an extended type, that is, the Link field, to the UDF. By using the link field, you can add a link to the node. The link includes the URL, title, and optional target attributes. "> Link </a> to view the result of the event .',
),
'Location' => array (
'Type' => 'text ',
'Not Null' => TRUE,
'Description' => 'URL of the origin of the event .',
),
'Referer' => array (
'Type' => 'text ',
'Not Null' => FALSE,
'Description' => 'URL of referring page .',
),
'Hostname' => array (
'Type' => 'varchar ',
'Length' => 128,
'Not Null' => TRUE,
'Default' => '',
'Description' => 'hostname of the user who triggered the event .',
),
'Timestamp' => array (
'Type' => 'int ',
'Not Null' => TRUE,
'Default' => 0,
'Description' => 'unix timestamp of when event occurred .',
),
),
'Primary key' => array ('wid'), // primary key
'Indexes' => array (// Index
'Type' => array ('type '),
'Uid' => array ('uid '),
'Severity '=> array ('severity '),
),
);
 
Return $ schema;
}

From the above point of view, d8 and d7 can be used in the writing of modules, but you need to find common APIs of d8 during development.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.