Entidades e OOP no Drupal
Até o drupal 6, nodes eram considerados a abstração básica
Fields
Versão
Tradução
Listas
Por que não tudo como nodes?
A nova abstração básica do drupal
Empacotamento de fields/funcionalidades por bundles
O drupal core já nos da algumas entities
Node = Entity Type
Uso de entity_load
Uso de entity_extract_id
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', 1)
->fieldCondition('field_news_types', 'value', 'spotlight', '=')
->fieldCondition('field_photo', 'fid', 'NULL', '!=')
->fieldOrderBy('field_photo', 'fid', 'DESC')
->range(0, 10)
->addMetaData('account', user_load(1)); // Run the query as user 1.
$result = $query->execute();
if (isset($result['node'])) {
$news_items_nids = array_keys($result['node']);
$news_items = entity_load('node', $news_items_nids);
}
Classe fornecida pelo módulo Entity
Visa facilitar a manipulação de Entidades e Fields, através de getters e setters
Facilita a manipulação de fields com tradução e/ou valores referenciados
$node_wrapper->field_number->value();
/**
* Implements hook_entity_info().
*/
function yourmodule_entity_info() {
return array(
'name_of_entity' => array(
'label' => t('Name of entity'),
'base table' => 'your_table',
'entity keys' => array(
'id' => 'your_tables_primary_key',
),
),
);
Base Entity Class
http://tinyurl.com/lgrav8b
Entity Controller
http://tinyurl.com/l283nw3
Conceito de bundles
Fieldable
Introdução a View modes
View modes customizados
Método view()
Nova forma de fazer ajax no drupal
Baseado no ctoolsCreate = PUT with a new URI POST to a base URI returning a newly created URI Read = GET Update = PUT with an existing URI
POST with existing endpoint, existing URI
Delete = DELETE
Interface Polymórfica, onde os métodos se aplicam à qualquer resource.
'operations' => array( 'update' => array( 'help' => 'Creates/updates a Technical support.', 'callback' => '_technical_support_update', 'access arguments' => array('update technical support through services'), 'args' => array( array( 'name' => 'partner_crm_id', 'type' => 'int', 'description' => 'The unique identifier for this partner in the CRM of Intelbras.', 'source' => array('path' => 0), 'default value' => NULL, 'optional' => FALSE, ), array( 'name' => 'data', 'type' => 'struct', 'description' => 'The data object', 'source' => 'data', 'optional' => FALSE, ), ), ),
hook_rest_server_response_formatters_alter
http://tinyurl.com/nbzz9tg
functioncustom_services_resource_rest_server_response_formatters_alter(&$formatters) { //This will change the formatter for xml, to use our custom one so it renders correctly $formatters['xml']['view'] = 'ExampleRESTServerView'; } class ExampleRESTServerView extends RESTServerView { public function render() { $doc = new DOMDocument('1.0', 'utf-8'); $root = $doc->createElement('Fruit_Basket'); $doc->appendChild($root); $this->xml_recurse($doc, $root, $this->model); return $doc->saveXML(); }
Services e contrib modules fornecem 3 tipos de autenticação
https://drupal.org/project/services_basic_auth
Permite a utilização de uma chave que representará um usuário no endpoint.
https://drupal.org/project/services_api_key_auth
https://drupal.org/project/services_views
Implementação de alguns hooks e callbacks:
www.drupalgap.org/node/187