DrupalTour. Zhytomyr — Entity API in Drupal 7 (Ivan Tibezh, InternetDevels)

Preview:

Citation preview

Entity API in Drupal 7

Tibezh IvanDrupal developer at InternetDevels

Зміст1. Що таке та навіщо Entity2. Create an Entity3. Bundles4. Fields5. Entity6. Entity API7. Metadata wrapper8. Other

Навіщо Entity

● Гнучкість

● Об’єднання даних у одному місці

● Інтеграція з модулями Views, Rules etc.

Що таке Entity

● node

● taxonomy_term

● taxonomy_vocabulary

● comment

● etc...

Create entity

hook_entity_info()● label● controller class● fieldable● bundles● view modes● type.

Bundles

● Різні поняття

● Різні поля

Fields

Entity - Field

Entity functions from core

entity_● get_controller● get_info● label● language● load● load_unchanged● prepare_view● uri

Entityvs.Entity API

Entity API (contrib)

Entity API - це розширення функціональності Entity у Drupal.

● CRUD* controller● default properties

Functions entity_● access● create● delete● delelte_multiple● export● import● load_single● metadata_wrapper● revision_delete● revision_load● save● view● get_property_info

Hooks

● hook_entity_view● hook_entity_insert● hook_entity_update● hook_entity_presave● hook_entity_delete● hook_entity_load

Entity metadata wrapper

Чому entity metadata wrappers?

● читабельність коду

● простий доступ до полів

● мультимовність

● простота у використанні

Приклад

$wrp = entity_metadata_wrapper(‘node’, $nid);$mail = $wrp->author->mail->value();

$wrp->language('uk')->title_field->value();

$wrp->field_text->set(‘test’);$wrp->save();

Питання

Recommended