Drupal-7.12 创建节点类型
Lepaskan: 2016-07-25 09:05:04
asal
1277 orang telah melayarinya
drupal 站点开发
- function examplenode_install() {
- //Updates the database cache of node types
- node_types_rebuild();
-
- $types = node_type_get_types();
-
- // add the body field to the node type
- node_add_body_field($types['job_post']);
-
- // Load the instance definition for our content type's body
- $body_instance = field_info_instance('node', 'body', 'job_post');
-
- // Configure the body field
- $body_instance['type'] = 'text_summary_or_trimmed';
-
- // Save our changes to the body field instance.
- field_update_instance($body_instance);
-
- // Create all the fields we are adding to our content type.
- foreach (_job_post_installed_fields() as $field) {
- field_create_field($field);
- }
-
- // Create all the instances for our fields.
- foreach (_job_post_installed_instances() as $instance) {
- $instance['entity_type'] = 'node';
- $instance['bundle'] = 'job_post';
- field_create_instance($instance);
- }
- }
-
- /**
- * Return a structured array defining the fields created by this content type.
- * For the job post module there is only one additional field – the company name
- * Other fields could be added by defining them in this function as additional elements
- * in the array below
- */
- function _job_post_installed_fields() {
- $t = get_t();
-
- return array(
- 'job_post_company' => array(
- 'field_name' => 'job_post_company',
- 'label' => $t('Company posting the job listing'),
- 'type' => 'text',
- ),
- );
- }
-
- /**
- * Return a structured array defining the field instances associated with this content type.
- */
- function _job_post_installed_instances() {
- $t = get_t();
-
- return array(
- 'job_post_company' => array(
- 'field_name' => 'job_post_company',
- 'type' => 'text',
- 'label' => $t('Company posting the job listing'),
- 'widget' => array(
- 'type' => 'text_textfield',
- ),
- 'display' => array(
- 'example_node_list' => array(
- 'label' => $t('Company posting the job listing'),
- 'type' => 'text',
- ),
- ),
- ),
- );
- }
-
- /**
- * Implements hook_uninstall().
- */
- function examplenode_uninstall() {
- // Gather all the example content that might have been created while this
- // module was enabled.
- $sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
- $result = db_query($sql, array(':type' => 'job_post'));
- $nids = array();
- foreach ($result as $row) {
- $nids[] = $row->nid;
- }
-
- // Delete all the nodes at once
- node_delete_multiple($nids);
-
- // Loop over each of the fields defined by this module and delete
- // all instances of the field, their data, and the field itself.
- foreach (array_keys(_job_post_installed_fields()) as $field) {
- field_delete_field($field);
- }
-
- // Loop over any remaining field instances attached to the job_post
- // content type (such as the body field) and delete them individually.
- $instances = field_info_instances('node', 'job_post');
- foreach ($instances as $instance_name => $instance) {
- field_delete_instance($instance);
- }
-
- // Delete our content type
- node_type_delete('job_post');
-
- // Purge all field infromation
- field_purge_batch(1000);
- }
-
复制代码
|
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31
Topik-topik yang berkaitan
Lagi>