Drupal 8 Entity常用

获取EntityManager
$entity_manager = \Drupal::entityTypeManager();

根据Property属性查询
$properties = array(
   'deleted' => TRUE,
   'include_deleted' => TRUE,
);
$fields = $entity_manager->getStorage('field_config')->loadByProperties($properties);

获取所有已定义的EntityType
$info = $entity_manager->getDefinitions();


获取一个Entity:

$entity = \Drupal::entityTypeManager()->getStorage('MyEntityType')->load(9);
dpm($entity);

查询其它条件

$entityQuery = \Drupal::entityQuery('project_list')
      ->condition('field_short_name', $short_name)->execute();

创建Entity

$EntityStorage = \Drupal::entityTypeManager()->getStorage('project_list');
$Entity = $EntityStorage->create(array('type' => 'project_list'));
$Entity->title = $title;
$Entity->field_short_name = $short_name;
$Entity->field_project_link = $link;

修改Entity 数据

$entity = \Drupal::entityTypeManager()->getStorage('MyEntityType')->load(9);
$entity->myfield = 1;
$entity->save();