Con la versione 7 di Drupal è stato introdotto il concetto di Entity, poi evoluto con la versione 8, utilizzato come base di buona parte degli elementi core (nodi, tassonomie, utenti, ...), ma - soprattutto - è stata data la possibilità di costruire entity custom. L'utilizzo di queste apre le possibilità di personalizzazione dello strumento ad un livello superiore velocizzando notevolmente lo sviluppo.
Verranno mostrate le potenzialità nell'uso delle Entity custom e le integrazioni possibili.
6. • D6 & 5 $node = new stdClass();
// Sad L
• D7 $node = new stdClass();
// DrupalEntityControllerInterface
// EntityFieldQuery, …
• D8 $node = new DrupalnodeEntityNode();
// Yah yahhhh!!! J
A bit of history
10. D7 - Entity
Bla bla…
class CustomEntity extends Entity {
public function __construct(array $values = [], $entity_type = NULL) {}
public function identifier() {}
public function bundle() {}
public function uri() {}
public function hasStatus($status) {}
public function save() {}
public function delete() {}
public function view($view_mode = 'full', $lang = NULL, $page = NULL) {}
public function buildContent($view_mode = 'full', $langcode = NULL) {}
// ...
}
12. D7 - EntityAPIController
class CustomEntityController extends EntityAPIController {
public function __construct($entityType) {}
public function query($ids, $conditions, $revision_id = FALSE) {}
public function load($ids = array(), $conditions = array()) {}
public function invoke($hook, $entity) {}
public function delete($ids, DatabaseTransaction $trans = NULL) {}
public function save($entity, DatabaseTransaction $trans = NULL) {}
public function create(array $values = array()) {}
public function buildContent($entity, $view_mode = 'full’,
$lang = NULL, $content = []) {}
public function view($entities, $view_mode = 'full’,
$langcode = NULL, $page = NULL) {}
// ...
}
13. D7 - EntityDefaultUIController
Bla bla…class CustomEntityUIController extends EntityDefaultUIController {
public function __construct($entity_type, $entity_info) {}
public function hook_menu() {}
public function hook_forms() {}
public function overviewTable($conditions = array()) {}
public function overviewForm($form, &$form_state) {}
public function operationForm($form, &$form_state, $entity, $op) {}
// and also [overview|operation]Form[Submit|Validate] methods.
public function applyOperation($op, $entity) {}
// ...
}
26. D8 - Entity Type
Module namespaced
Drupalmy_moduleEntityMyCustomeEntity()
Defined folder in module
src/Entity/MyCustomEntity.php
INFORMATION MANAGED BY
ANNOTATION
/**
* @XyzEntityType( … )
*/
Can be “code only”
config/install/my_custom_entity.sample_1.yml
Unit testable
class MyCustomEntityTest extends DrupalTestsUnitTestCase {}
27. D8 - ContentEntityType
Require database definition
hook_schema()
Can be fildable/REVISIONABLE
baseFieldDefinition()
CAN HAVE CUSTOM BEHAVIOR
redefine [pre|post][Save|Load|Delete] methods
CAN PROVIDE CUSTOM ACCESS RULES
checkAccess() and checkCreateAccess()
CAN PROVIDE CUSTOM HANDLERS
strorage, view_builder, route_provider, form, translation, config_export...