Hướng dẫn xóa Content Types và Fields trong Drupal

Hướng dẫn xóa Content Types và Fields trong Drupal

Here are two of the most common questions we get from Drupal newcomers:Hướng dẫn xóa Content Types và Fields trong Drupal

  • "What happens if I delete a content type?" 
  • "What happens if I delete a field?"

Because the answers are not easy to find, these kinds of questions can be confusing.

Here's a clear explanation of what happens when you delete a content type or field.

Deleting a Content Type

Hướng dẫn xóa Content Types và Fields trong Drupal

There are three questions to consider when deleting a content type:

  1. What happens to the content?
  2. What happens to the fields associated with the content type just deleted?
  3. What happens to the modules that interact with deleted content type?

1. What happens to the content?

Hướng dẫn xóa Content Types và Fields trong Drupal

The short answer to this question is, the nodes remain in the database. You can see the nodes listed in the Find Content admin page.

However, just because you can see them listed, does not mean you can open them. In fact, you can't; you get an error if you try.

2. What happens to the fields in the deleted content type?

Hướng dẫn xóa Content Types và Fields trong Drupal

The test content type that was just deleted had a test field (a field unique to the test content type) and the image field that comes with the Article content type. As you can see from the screen shot above, the image field is still there but the test field is not.

3. What happens to the modules that interact with the deleted content type?

There are contributed modules that add features to content types such as AddToAny and Webform to name two. In order to add the features provided by the module to the content type, quite often you check a box on the module's configuration page. The module then stores that decision as a configuration setting in the database.

What happens if you delete a content type without telling the module that is no longer needs to do something to that content type? In order to answer this question, I'd have to test quite a few modules to see if the developers of those modules took steps in their code to accommodate a content type suddenly going away. I offer you this however, if you have a content type you want to delete and you have modules on your site that add features to content types, consider disconnecting the content type from these other modules before you delete it.

Deleting a Field

In order to delete a field, you must go the content type where the field resides and delete it, unless of course you are deleting a content type. We saw earlier what happens to fields when we delete a content type. The fields shared across multiple content types remained but the fields unique to the deleted content type were also deleted. This same logic applies when you simply want to delete a field.

If the field you delete is unique to a content type, then the field is gone from the database (that includes it's data). If you delete a shared field from, the field is removed from that content type along with the data unique to the contenty type.

If you find that you need to keep the data associated with the field but you need a different type of field for the data, you need to plan ahead.

  1. Create the new field.
  2. Devise a way to migrate the data from the old field to the new field.
  3. Delete the old field.

Summary

Before you delete anything in Drupal, ask yourself how the "thing" you are about to delete is related to other things on the site. Is the content type related to existing nodes? Does the content have features managed by other modules? Has the field been used? If yes, will you need to save the data stored with the field?

Think things through before you delete.

Via Ostraining.com

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Giới thiệu module Organic Groups trong Drupal 6

Giới thiệu module Organic Groups trong Drupal 6

OG allows users to create and manage their own groups. Other members can then join those groups and share content either privately or publicly.

Bàn về FACEBOOK với học sinh, giới trẻ hiện nay

Bàn về FACEBOOK với học sinh, giới trẻ 2015 hiện nay

Không phải ngẫu nhiên facebook trở thành mạng xã hội có sức hút hấp dẫn nhất trên thế giới. Facebook

Bước 3: Widening Your Net of team Drupal

Bước 3: Widening Your Net of team Drupal

Eric Gaffen, Global Manager, Talent Acquisition at Acquia, is constantly getting requests for new hires from the leadership at Acquia. His previous company grew from 1600 to 3000 in six years, and from that experience, Eric knows larger companies have a very standardized approach to job descriptions which match compensation and evaluation. Things are quite different here. 

Công ty diệt chuột T&C

 

Diet con trung