SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
Свои типы Entity:
зачем и как
использовать
Entity
Bundle 1

Entity Type

Field 1

Bundle 2

Field 2

Bundle 3

Field 3
hook_entity_info()
function node_entity_info() {

'bundle keys' => array(

$return = array(

'bundle' => 'type',

'node' => array(

),

'label' => t('Node'),

'bundles' => array(),

'controller class' => 'NodeController',

//...

'base table' => 'node',

),

'revision table' => 'node_revision',

);

'fieldable' => TRUE,

// …

'entity keys' => array(

foreach (node_type_get_names() as $type => $name) {

'id' => 'nid',

$return['node']['bundles'][$type] = array(

'revision' => 'vid',

// ...

'bundle' => 'type',

);

'label' => 'title',

}

'language' => 'language',
),

return $return;
}
Drupal core
●
●
●
●
●
●

Node
Comment
User
Taxonomy Term
Taxonomy Vocabulary
File
Contrib Modules
●
●
●
●
●

Drupal Commerce
Rules
Profile 2
Message
Field Collection

...
Форма для заполнения
Имя

Email

О себе

Послать
Обработка данных
Результат
Требования
● Гибкость
● Расширяемость
● Несколько форм: разные поля,
схожий функционал
● Сжатые сроки

Entity + Bundles + Fields
Почему не ноды?
● Не нужны некоторые
свойства
● Нужны
дополнительные
свойства
● не нужен некоторый
функционал / хуки
● нужен свой
функционал

● Не нужны
комментарии
● Не нужны ревизии
● Не нужна система
доступов
(node_access())
● нужна своя система
доступов
● не нужна страница
/node/[nid]
Entity API
https://drupal.org/project/entity
Views, Rules
Экспорт / Features
Token (Entity Tokens)
Admin UI
entity_metadata_wrapper()
$node = node_load(1);
$wrapper = entity_metadata_wrapper('node', $node);
$wrapper->title->value();
$wrapper->author->name->value();
$wrapper->field_multiple->value();
foreach ($wrapper->field_multiple as $delta =>
$field_wrapper) {
$field_wrapper->value();
}
$wrapper->field_price->value();
$wrapper->field_price->amount_decimal->value()
$wrapper->title->set('another title');
$wrapper->body->value->set('Lorem Ipsum');
Entity без полей
●
●
●
●
●

Views
Rules
Token
Admin UI
entity_metadata_wrapper()
также смотрите
●
●
●
●

Drupal Commerce
Profile 2
Entityforms
Entity Construction Kit (ECK)
Спасибо за
внимание !

Weitere ähnliche Inhalte

Was ist angesagt?

Реализация шаблонов корпоративных приложений в Magento
Реализация шаблонов корпоративных приложений в MagentoРеализация шаблонов корпоративных приложений в Magento
Реализация шаблонов корпоративных приложений в Magento
Magecom Ukraine
 
Все дороги ведут в Checkout
Все дороги ведут в CheckoutВсе дороги ведут в Checkout
Все дороги ведут в Checkout
Magecom Ukraine
 
Индексирование в Magento
Индексирование в MagentoИндексирование в Magento
Индексирование в Magento
Magecom Ukraine
 
AddConf. Дмитрий Сошников - Будущее ECMAScript
AddConf. Дмитрий Сошников  - Будущее ECMAScriptAddConf. Дмитрий Сошников  - Будущее ECMAScript
AddConf. Дмитрий Сошников - Будущее ECMAScript
Dmitry Soshnikov
 
I tmozg js_school_jquery
I tmozg js_school_jqueryI tmozg js_school_jquery
I tmozg js_school_jquery
ITmozg
 
Интуит. Разработка приложений для iOS. Лекция 5. Сложные Views
Интуит. Разработка приложений для iOS. Лекция 5. Сложные ViewsИнтуит. Разработка приложений для iOS. Лекция 5. Сложные Views
Интуит. Разработка приложений для iOS. Лекция 5. Сложные Views
Глеб Тарасов
 
Python
PythonPython
Python
pelid
 
Yii development
Yii developmentYii development
Yii development
MageCloud
 

Was ist angesagt? (20)

Python dict: прошлое, настоящее, будущее
Python dict: прошлое, настоящее, будущееPython dict: прошлое, настоящее, будущее
Python dict: прошлое, настоящее, будущее
 
Реализация шаблонов корпоративных приложений в Magento
Реализация шаблонов корпоративных приложений в MagentoРеализация шаблонов корпоративных приложений в Magento
Реализация шаблонов корпоративных приложений в Magento
 
Лекция #5. Введение в язык программирования Python 3
Лекция #5. Введение в язык программирования Python 3Лекция #5. Введение в язык программирования Python 3
Лекция #5. Введение в язык программирования Python 3
 
Все дороги ведут в Checkout
Все дороги ведут в CheckoutВсе дороги ведут в Checkout
Все дороги ведут в Checkout
 
Индексирование в Magento
Индексирование в MagentoИндексирование в Magento
Индексирование в Magento
 
AddConf. Дмитрий Сошников - Будущее ECMAScript
AddConf. Дмитрий Сошников  - Будущее ECMAScriptAddConf. Дмитрий Сошников  - Будущее ECMAScript
AddConf. Дмитрий Сошников - Будущее ECMAScript
 
Yserver
YserverYserver
Yserver
 
Работа с БД в Drupal 7
Работа с БД в Drupal 7Работа с БД в Drupal 7
Работа с БД в Drupal 7
 
Подробная презентация JavaScript 6 в 1
Подробная презентация JavaScript 6 в 1Подробная презентация JavaScript 6 в 1
Подробная презентация JavaScript 6 в 1
 
Caching on highload Drupal site - Alexander Shumenko
Caching on highload Drupal site - Alexander ShumenkoCaching on highload Drupal site - Alexander Shumenko
Caching on highload Drupal site - Alexander Shumenko
 
I tmozg js_school_jquery
I tmozg js_school_jqueryI tmozg js_school_jquery
I tmozg js_school_jquery
 
Интуит. Разработка приложений для iOS. Лекция 5. Сложные Views
Интуит. Разработка приложений для iOS. Лекция 5. Сложные ViewsИнтуит. Разработка приложений для iOS. Лекция 5. Сложные Views
Интуит. Разработка приложений для iOS. Лекция 5. Сложные Views
 
Python
PythonPython
Python
 
Perl: Symbol table
Perl: Symbol tablePerl: Symbol table
Perl: Symbol table
 
Mojo. The web in a box!
Mojo. The web in a box!Mojo. The web in a box!
Mojo. The web in a box!
 
Сущности в Drupal 7
Сущности в Drupal 7Сущности в Drupal 7
Сущности в Drupal 7
 
Пластилиновый код: как перестать кодить и начать жить
Пластилиновый код: как перестать кодить и начать житьПластилиновый код: как перестать кодить и начать жить
Пластилиновый код: как перестать кодить и начать жить
 
Yii development
Yii developmentYii development
Yii development
 
Enterprise Patterns in Magento
Enterprise Patterns in MagentoEnterprise Patterns in Magento
Enterprise Patterns in Magento
 
Подробная презентация JavaScript 6 в 1
Подробная презентация JavaScript 6 в 1Подробная презентация JavaScript 6 в 1
Подробная презентация JavaScript 6 в 1
 

Mehr von ADCI Solutions

Drupal. History and Future. Sergey Susikov.
Drupal. History and Future. Sergey Susikov.Drupal. History and Future. Sergey Susikov.
Drupal. History and Future. Sergey Susikov.
ADCI Solutions
 
Data Import From the Server of The Central Bank of the Russian Federation: Ho...
Data Import From the Server of The Central Bank of the Russian Federation: Ho...Data Import From the Server of The Central Bank of the Russian Federation: Ho...
Data Import From the Server of The Central Bank of the Russian Federation: Ho...
ADCI Solutions
 
Drupal 8: What's new? Anton Shubkin
Drupal 8: What's new? Anton ShubkinDrupal 8: What's new? Anton Shubkin
Drupal 8: What's new? Anton Shubkin
ADCI Solutions
 
Contextly. Dmitry Tartynov
Contextly. Dmitry TartynovContextly. Dmitry Tartynov
Contextly. Dmitry Tartynov
ADCI Solutions
 
Vagrant. Halturin Artem
Vagrant. Halturin ArtemVagrant. Halturin Artem
Vagrant. Halturin Artem
ADCI Solutions
 
Must-knows and common mistakes in theming. Kate Kalashnikova.
Must-knows and common mistakes in theming. Kate Kalashnikova.Must-knows and common mistakes in theming. Kate Kalashnikova.
Must-knows and common mistakes in theming. Kate Kalashnikova.
ADCI Solutions
 
Drupal 8. Movement towards. Susikov Sergey
Drupal 8. Movement towards. Susikov SergeyDrupal 8. Movement towards. Susikov Sergey
Drupal 8. Movement towards. Susikov Sergey
ADCI Solutions
 
Upgrade with 6 to 7. Denis Komel'kov
Upgrade with 6 to 7. Denis Komel'kovUpgrade with 6 to 7. Denis Komel'kov
Upgrade with 6 to 7. Denis Komel'kov
ADCI Solutions
 
Responsive website building approach. Olga Smolyankina and Kate Kalashnikova
Responsive website building approach. Olga Smolyankina and Kate KalashnikovaResponsive website building approach. Olga Smolyankina and Kate Kalashnikova
Responsive website building approach. Olga Smolyankina and Kate Kalashnikova
ADCI Solutions
 
LESS and even more. Anton Shubkin.
LESS and even more. Anton Shubkin.LESS and even more. Anton Shubkin.
LESS and even more. Anton Shubkin.
ADCI Solutions
 
Selenium. Stas Kuzminov
Selenium. Stas KuzminovSelenium. Stas Kuzminov
Selenium. Stas Kuzminov
ADCI Solutions
 

Mehr von ADCI Solutions (15)

Drupal front-end performance
Drupal front-end performance Drupal front-end performance
Drupal front-end performance
 
Introduction to cron queue
Introduction to cron queueIntroduction to cron queue
Introduction to cron queue
 
Drupal. Advantages and disadvantages. Igor Rodionov.
Drupal. Advantages and disadvantages. Igor Rodionov.Drupal. Advantages and disadvantages. Igor Rodionov.
Drupal. Advantages and disadvantages. Igor Rodionov.
 
Drupal theming must knows. Kate Kalashnikova.
Drupal theming must knows. Kate Kalashnikova.Drupal theming must knows. Kate Kalashnikova.
Drupal theming must knows. Kate Kalashnikova.
 
Drupal. History and Future. Sergey Susikov.
Drupal. History and Future. Sergey Susikov.Drupal. History and Future. Sergey Susikov.
Drupal. History and Future. Sergey Susikov.
 
Data Import From the Server of The Central Bank of the Russian Federation: Ho...
Data Import From the Server of The Central Bank of the Russian Federation: Ho...Data Import From the Server of The Central Bank of the Russian Federation: Ho...
Data Import From the Server of The Central Bank of the Russian Federation: Ho...
 
Drupal 8: What's new? Anton Shubkin
Drupal 8: What's new? Anton ShubkinDrupal 8: What's new? Anton Shubkin
Drupal 8: What's new? Anton Shubkin
 
Contextly. Dmitry Tartynov
Contextly. Dmitry TartynovContextly. Dmitry Tartynov
Contextly. Dmitry Tartynov
 
Vagrant. Halturin Artem
Vagrant. Halturin ArtemVagrant. Halturin Artem
Vagrant. Halturin Artem
 
Must-knows and common mistakes in theming. Kate Kalashnikova.
Must-knows and common mistakes in theming. Kate Kalashnikova.Must-knows and common mistakes in theming. Kate Kalashnikova.
Must-knows and common mistakes in theming. Kate Kalashnikova.
 
Drupal 8. Movement towards. Susikov Sergey
Drupal 8. Movement towards. Susikov SergeyDrupal 8. Movement towards. Susikov Sergey
Drupal 8. Movement towards. Susikov Sergey
 
Upgrade with 6 to 7. Denis Komel'kov
Upgrade with 6 to 7. Denis Komel'kovUpgrade with 6 to 7. Denis Komel'kov
Upgrade with 6 to 7. Denis Komel'kov
 
Responsive website building approach. Olga Smolyankina and Kate Kalashnikova
Responsive website building approach. Olga Smolyankina and Kate KalashnikovaResponsive website building approach. Olga Smolyankina and Kate Kalashnikova
Responsive website building approach. Olga Smolyankina and Kate Kalashnikova
 
LESS and even more. Anton Shubkin.
LESS and even more. Anton Shubkin.LESS and even more. Anton Shubkin.
LESS and even more. Anton Shubkin.
 
Selenium. Stas Kuzminov
Selenium. Stas KuzminovSelenium. Stas Kuzminov
Selenium. Stas Kuzminov
 

Entity. Anton Shubkin and Yaroslav Ponomarev