Monday, June 23, 2014

Entities (Major difference between Drupal 6 and Drupal 7)

Entities

Maybe you've heard of "entities" in Drupal 7, wondered what they were, and wanted to learn the underlying concepts. Leveraging the Entity API lets you create more lightweight and flexible solutions.
The Drupal community often compares site building through configuration to a favorite childhood toy: LEGO bricks. We can build Entity types, which can make Bundles, to which we can add Fieldsand then create Entities. This article explains the relationships between Entity types > Bundles > Fields > Entities. This was one of the most important changes of Drupal 7, and brought components from some well-loved contributed modules -- such as CCK -- into the core system.
The illustration below shows some examples of Entity types included with Drupal 7, with some example entities:
entity types and some entities
Let’s take a closer look at these concepts. It’s sort of a chicken-and-egg thing, one doesn’t exist without the other.

Entity types

In earlier versions of Drupal, the field system was only used on content types. Now, thanks to the Entity API, we can add fields to other things, like comments. Fieldable entities make Drupal eminently flexible. An entity type is a useful abstraction to group together fields. Let’s consider some examples of entity types:
  • Nodes (content)
  • Comments
  • Taxonomy terms
  • User profiles
You can also build new kinds of entity types where the options above don't suit your needs. For more information, read further about using the hook_entity_info and extension by Entity API:entity_crud_hook_entity_info.

Bundles

Bundles are an implementation of an entity type to which fields can be attached. You can consider bundles as subtypes of an entity type. With content nodes (an entity type), for example, you can generate bundles (subtypes) like articles, blog posts, or products. Not all entity types have bundles, however. For example, users do not have separate bundles (subtypes). For the entity types that do allow bundles, you can create as many bundles (subtypes) as you want. Then, using the Field system, you can add different fields to each bundle. Examples include a file download field on Basic Pages and a subtitle field on Articles.

Fields

A field is a reusable piece of content. In technical terms, each field is a primitive data type, with custom validators and widgets for editing and formatters for display. You can read further for a developer's guide to using the Drupal 7 Fields API.
What's important to know as it relates to Entities is that Fields can be added to any of the bundles (or entity types) to help organize their data. Say, for example, you create a content type with an unstructured text field and use HTML to structure parts of it, like a summary section, or prices. That would make it more difficult, then, to control how these were displayed, or to make connections between different types of related content. This is where using fields is essential.

Entity

An entity would be one instance of a particular entity type such as a comment, taxonomy term or user profile or a bundle such as a blog post, article or product.
You can use entity_load to load any entity. Note, however, that the core does not provide a save or delete function, but thanks to Entity API module the missing pieces are added (entity_create(), entity_save(), entity_delete(), entity_view() and entity_access()).

Putting this in Object-Oriented Design/Programming terms...

If you come from an OOD/P background and are trying to better understand what these key D7 concepts are, the following suggested mapping might help (albeit not strictly true from a purist’s perspective) :-
  • An entity type is a base class
  • bundle is an extended class
  • field is a class memberpropertyvariable or field instance (depending on your naming preference)
  • An entity is an object or instance of a base or extended class
All these four OOD/P concepts are special in that they are serialisable (stored - e.g. to a database or file). Serialisation takes place via the Entity API.

So what’s the big deal?

If you’re familiar with Drupal 6 and new to Drupal 7, this will sound like great news. In Drupal 6 and before, users and comments didn't have the same power that nodes (content) had. They couldn't have translations, fields, versioning, and so on. It also meant that systems such as Views, which relied on controlling the selection and listing of fields didn’t work as well with comments and users. Some experimentation was done with modules that turned comments or users into nodes. However, this meant that all the additional information in the node object was added to comments.
Instead, the community created this abstraction based on what was common between these different models of entity types. In this way, the Entity API allows for more lightweight and flexible solutions. There are many entity-aware modules, and more being developed with Drupal 7, which make it easier to relate content together, and gain a more flexible architecture.

Entity API module

The project Entity API extends the entity API of Drupal core in order to provide a unified way to deal with entities and their properties. Additionally, it provides an entity CRUD controller, which helps in simplifying the creation of new entity types.
Learn more about using the Entity API in your projects.


22 comments:

  1. I had been searching the many blogs to get the actual information about difference between the Drupal 6 and Drupal 7 version.But this blog only well briefly explaining that process.
    Web Design Company | Web Design Companies

    ReplyDelete
  2. Day by day technologies has been improving in all kind of industries and platforms it will bring us to next level. Drupal is free open source CMS with SEO friendly platform.


    Website Design Agency Bangalore | Web Development Company Bangalore

    ReplyDelete
  3. These differences are digestible, I think a Drupal Solution Provider will understand all the differences only in a week.

    ReplyDelete
  4. I saw composing styles which have been new and new and numerous that exhausted me. Restless to decide how these change after eventually ;)

    Wordpress Developers in Bangalore | Wordpress Development Bangalore

    ReplyDelete
  5. Your post has everything that is obtained complete and really useful. It's a beautiful presentation about Major difference between Drupal 6 and Drupal 7. This post is very good. Thank you for presenting a very good post.
    cms web development company

    ReplyDelete
  6. Nice Posting! because there are a lot of informative postings so, thanks a lot for sharing the information. Ecommerce website Designing in Mumbai || Ecommerce Solution || Ecommerce Solution in Mumbai

    ReplyDelete
  7. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me. Dynamic Website Designing || Dynamic website Designing in Mumbai || Ecommerce website Designing

    ReplyDelete
  8. Thanks for nice post. It is complicated to me now, but in typical, the efficiency and significance is annoying. Very much thanks again and best of luck! Thanks for sharing. Website Maintenance in Mumbai || Website Development || Website Development in Mumbai

    ReplyDelete
  9. Excellent post, I agree with you 100%! I’m always scouring the Internet for new information and learning whatever I can, and in doing so I sometimes leave comments on blogs. Web Designing || Web Designing in Mumbai || Website Maintenance

    ReplyDelete
  10. It was very useful for me. Keep sharing such ideas in the future as well. This was actually what I was looking for, and I am glad to came here! Thanks for sharing the such information with us. CMS Website Design || CMS Website Developer || CMS website development company

    ReplyDelete
  11. Thanks for sharing about Drupal 6 and Drupal 7. Drupal has its own favour and it is much recommended for enterprise projects. With expertise in Drupal, our development team can furnish a powerful CMS to manage complex tasks.

    ReplyDelete
  12. Glad to read your post...Thanks for sharing such a nice information, its beneficial for me. I have you bookmarked to check out new stuff you post. Keep sharing.
    Website Development Companies Bangalore | Website Designing Company Bangalore

    ReplyDelete
  13. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.
    Signature:
    download baixar facebook movel, Facebook movel, baixar facebook. Facebook chat, baixar whatsapp, fazer o download baixar whatsapp gratis para Android, iPhone. Últimas Facebook

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. good to read about drupal and thanks for sharing drupal information to me. will keen to see your next post

    WEB DESIGN COMPANY BANGALORE

    ReplyDelete
  16. Thank you for sharing valuable information. Nice post. I enjoyed reading this post.
    Signature:
    Versión en facebook descargar a los países hablan Español: entrar a facebook , facebook en español para and facebook entrar direto

    ReplyDelete
  17. I understand what you bring it very meaningful and useful, thanks.
    Signature:
    The place to play all unblockedgames online. Here you can find every blocked games such as: unblocked games , unblocked games happy , unblocked games 77 ,

    ReplyDelete
  18. I have a search the what is the Drupal Cms and its version in many more blogs and website but i have a getting the right information for your blog...thank for sharing the great information..
    Web Development Company Bangalore | Web Design Company Bangalore

    ReplyDelete
  19. Excellent post!! Very informative and helpful blog.Thanks for sharing such great valuable tips and worth to read.
    Web Development Company|Logo Design Company

    ReplyDelete
  20. Great post. I found very useful info from this post. Thank you very much.
    ipad app development company | web development melbourne

    ReplyDelete
  21. This comment has been removed by a blog administrator.

    ReplyDelete

only show translated menu items into current language (Drupal 8)

function MY_THEME_preprocess_menu(&$variables) {   if ($variables['menu_name'] == 'brancott-header-menu') {    $langu...