Commit e775437e authored by webchick's avatar webchick

Issue #1982984 by larowlan: Create Drupal::entityManager for improved DX.

parent ec8deb00
......@@ -6090,7 +6090,7 @@ function drupal_flush_all_caches() {
// Clear all non-drupal_static() static caches.
// @todo Rebuild the kernel/container.
drupal_container()->get('plugin.manager.entity')->clearCachedDefinitions();
Drupal::entityManager()->clearCachedDefinitions();
// Rebuild module and theme data.
system_rebuild_module_data();
......
......@@ -342,7 +342,7 @@ function config_import_invoke_owner(array $config_changes, StorageInterface $sou
// higher-level configuration data.
// First pass deleted, then new, and lastly changed configuration, in order to
// handle dependencies correctly.
$manager = drupal_container()->get('plugin.manager.entity');
$manager = Drupal::entityManager();
foreach (array('delete', 'create', 'change') as $op) {
foreach ($config_changes[$op] as $key => $name) {
// Call to the configuration entity's storage controller to handle the
......@@ -366,7 +366,7 @@ function config_import_invoke_owner(array $config_changes, StorageInterface $sou
if (!empty($handled_by_module)) {
$factory->reset($name);
// Reset the manifest config object for the config entity.
$entity_info = drupal_container()->get('plugin.manager.entity')->getDefinition($entity_type);
$entity_info = Drupal::entityManager()->getDefinition($entity_type);
$factory->reset('manifest.' . $entity_info['config_prefix']);
unset($config_changes[$op][$key]);
}
......
......@@ -28,10 +28,10 @@
*/
function entity_get_info($entity_type = NULL) {
if (empty($entity_type)) {
return drupal_container()->get('plugin.manager.entity')->getDefinitions();
return Drupal::entityManager()->getDefinitions();
}
else {
return drupal_container()->get('plugin.manager.entity')->getDefinition($entity_type);
return Drupal::entityManager()->getDefinition($entity_type);
}
}
......@@ -42,7 +42,7 @@ function entity_info_cache_clear() {
drupal_static_reset('entity_get_view_modes');
drupal_static_reset('entity_get_bundles');
// Clear all languages.
drupal_container()->get('plugin.manager.entity')->clearCachedDefinitions();
Drupal::entityManager()->clearCachedDefinitions();
}
/**
......@@ -185,7 +185,7 @@ function entity_load($entity_type, $id, $reset = FALSE) {
* @see Drupal\Core\Entity\DatabaseStorageController
*/
function entity_revision_load($entity_type, $revision_id) {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getStorageController($entity_type)
->loadRevision($revision_id);
}
......@@ -199,7 +199,7 @@ function entity_revision_load($entity_type, $revision_id) {
* The revision ID to delete.
*/
function entity_revision_delete($entity_type, $revision_id) {
drupal_container()->get('plugin.manager.entity')
Drupal::entityManager()
->getStorageController($entity_type)
->deleteRevision($revision_id);
}
......@@ -231,7 +231,7 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
}
$uuid_key = $entity_info['entity_keys']['uuid'];
$controller = drupal_container()->get('plugin.manager.entity')->getStorageController($entity_type);
$controller = Drupal::entityManager()->getStorageController($entity_type);
if ($reset) {
$controller->resetCache();
}
......@@ -273,7 +273,7 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
* @see Drupal\Core\Entity\Query\QueryInterface
*/
function entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE) {
$controller = drupal_container()->get('plugin.manager.entity')->getStorageController($entity_type);
$controller = Drupal::entityManager()->getStorageController($entity_type);
if ($reset) {
$controller->resetCache();
}
......@@ -293,7 +293,7 @@ function entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE) {
* An array of entity objects indexed by their ids.
*/
function entity_load_multiple_by_properties($entity_type, array $values) {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getStorageController($entity_type)
->loadByProperties($values);
}
......@@ -315,7 +315,7 @@ function entity_load_multiple_by_properties($entity_type, array $values) {
* The unchanged entity, or FALSE if the entity cannot be loaded.
*/
function entity_load_unchanged($entity_type, $id) {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getStorageController($entity_type)
->loadUnchanged($id);
}
......@@ -329,7 +329,7 @@ function entity_load_unchanged($entity_type, $id) {
* An array of entity IDs of the entities to delete.
*/
function entity_delete_multiple($entity_type, array $ids) {
$controller = drupal_container()->get('plugin.manager.entity')->getStorageController($entity_type);
$controller = Drupal::entityManager()->getStorageController($entity_type);
$entities = $controller->load($ids);
$controller->delete($entities);
}
......@@ -347,7 +347,7 @@ function entity_delete_multiple($entity_type, array $ids) {
* A new entity object.
*/
function entity_create($entity_type, array $values) {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getStorageController($entity_type)
->create($values);
}
......@@ -360,7 +360,7 @@ function entity_create($entity_type, array $values) {
* @deprecated Use \Drupal\Core\Entity\EntityManager::getStorageController().
*/
function entity_get_controller($entity_type) {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getStorageController($entity_type);
}
......@@ -398,7 +398,7 @@ function entity_page_label(EntityInterface $entity, $langcode = NULL) {
* @deprecated Use \Drupal\Core\Entity\EntityManager::getRenderController().
*/
function entity_access_controller($entity_type) {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getAccessController($entity_type);
}
......@@ -426,7 +426,7 @@ function entity_access_controller($entity_type) {
* @deprecated Use \Drupal\Core\Entity\EntityManager::getFormController().
*/
function entity_form_controller($entity_type, $operation = 'default') {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getFormController($entity_type, $operation);
}
......@@ -443,7 +443,7 @@ function entity_form_controller($entity_type, $operation = 'default') {
*/
function entity_form_state_defaults(EntityInterface $entity, $operation = 'default') {
$form_state = array();
$controller = Drupal::service('plugin.manager.entity')->getFormController($entity->entityType(), $operation);
$controller = Drupal::entityManager()->getFormController($entity->entityType(), $operation);
$controller->setEntity($entity);
$form_state['build_info']['callback_object'] = $controller;
$form_state['build_info']['base_form_id'] = $controller->getBaseFormID();
......@@ -552,7 +552,7 @@ function entity_form_submit_build_entity($entity_type, $entity, $form, &$form_st
* @deprecated Use \Drupal\Core\Entity\EntityManager::getFormController().
*/
function entity_list_controller($entity_type) {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getListController($entity_type);
}
......@@ -568,7 +568,7 @@ function entity_list_controller($entity_type) {
* @deprecated Use \Drupal\Core\Entity\EntityManager::getFormController().
*/
function entity_render_controller($entity_type) {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getRenderController($entity_type);
}
......@@ -587,7 +587,7 @@ function entity_render_controller($entity_type) {
* A render array for the entity.
*/
function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL) {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getRenderController($entity->entityType())
->view($entity, $view_mode, $langcode);
}
......@@ -608,7 +608,7 @@ function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL) {
* entities array passed in $entities.
*/
function entity_view_multiple(array $entities, $view_mode, $langcode = NULL) {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getRenderController(reset($entities)->entityType())
->viewMultiple($entities, $view_mode, $langcode);
}
......@@ -740,14 +740,14 @@ function entity_page_access(EntityInterface $entity, $operation = 'view') {
* TRUE if the access is granted. FALSE if access is denied.
*/
function entity_page_create_access($entity_type, $bundle = NULL) {
$definition = Drupal::service('plugin.manager.entity')->getDefinition($entity_type);
$definition = Drupal::entityManager()->getDefinition($entity_type);
// Pass in the entity bundle if given and required.
$values = array();
if ($bundle && isset($definition['entity_keys']['bundle'])) {
$values[$definition['entity_keys']['bundle']] = $bundle;
}
$entity = drupal_container()->get('plugin.manager.entity')
$entity = Drupal::entityManager()
->getStorageController($entity_type)
->create($values);
return $entity->access('create');
......
......@@ -2602,7 +2602,7 @@ function menu_cache_clear_all() {
* Resets the menu system static cache.
*/
function menu_reset_static_cache() {
drupal_container()->get('plugin.manager.entity')
Drupal::entityManager()
->getStorageController('menu_link')->resetCache();
drupal_static_reset('_menu_build_tree');
drupal_static_reset('menu_tree');
......@@ -2749,7 +2749,7 @@ function menu_get_router() {
*/
function _menu_navigation_links_rebuild($menu) {
if (module_exists('menu_link')) {
$menu_link_controller = drupal_container()->get('plugin.manager.entity')
$menu_link_controller = Drupal::entityManager()
->getStorageController('menu_link');
}
else {
......
......@@ -147,6 +147,16 @@ public static function request() {
return static::$container->get('request');
}
/**
* Retrieves the entity manager service.
*
* @return \Drupal\Core\Entity\EntityManager
* The entity manager service.
*/
public static function entityManager() {
return static::$container->get('plugin.manager.entity');
}
/**
* Returns the current primary database.
*
......
......@@ -258,7 +258,7 @@ public function getIterator() {
* Implements \Drupal\Core\TypedData\AccessibleInterface::access().
*/
public function access($operation = 'view', \Drupal\user\Plugin\Core\Entity\User $account = NULL) {
return drupal_container()->get('plugin.manager.entity')
return \Drupal::entityManager()
->getAccessController($this->entityType)
->access($this, $operation, LANGUAGE_DEFAULT, $account);
}
......@@ -331,7 +331,7 @@ public function getTranslationLanguages($include_default = TRUE) {
* Implements \Drupal\Core\Entity\EntityInterface::save().
*/
public function save() {
return drupal_container()->get('plugin.manager.entity')->getStorageController($this->entityType)->save($this);
return \Drupal::entityManager()->getStorageController($this->entityType)->save($this);
}
/**
......@@ -339,7 +339,7 @@ public function save() {
*/
public function delete() {
if (!$this->isNew()) {
drupal_container()->get('plugin.manager.entity')->getStorageController($this->entityType)->delete(array($this->id() => $this));
\Drupal::entityManager()->getStorageController($this->entityType)->delete(array($this->id() => $this));
}
}
......
......@@ -223,7 +223,7 @@ public function getPropertyDefinition($name) {
*/
public function getPropertyDefinitions() {
if (!isset($this->fieldDefinitions)) {
$this->fieldDefinitions = drupal_container()->get('plugin.manager.entity')->getStorageController($this->entityType)->getFieldDefinitions(array(
$this->fieldDefinitions = \Drupal::entityManager()->getStorageController($this->entityType)->getFieldDefinitions(array(
'EntityType' => $this->entityType,
'Bundle' => $this->bundle,
));
......
......@@ -216,7 +216,7 @@ public function access($operation = 'view', \Drupal\user\Plugin\Core\Entity\User
// @todo Add a way to set and get the langcode so that's more obvious what
// we're doing here.
$langcode = substr($this->getName(), 1);
return drupal_container()->get('plugin.manager.entity')
return \Drupal::entityManager()
->getAccessController($this->parent->entityType())
->access($this->parent, $operation, $langcode, $account);
}
......
......@@ -178,7 +178,7 @@ public function getPropertyDefinition($name) {
*/
public function getPropertyDefinitions() {
// @todo: Support getting definitions if multiple bundles are specified.
return drupal_container()->get('plugin.manager.entity')->getStorageController($this->entityType)->getFieldDefinitions($this->definition['constraints']);
return \Drupal::entityManager()->getStorageController($this->entityType)->getFieldDefinitions($this->definition['constraints']);
}
/**
......
......@@ -29,7 +29,7 @@ function block_admin_demo($theme = NULL) {
* @see block_menu()
*/
function block_admin_display($theme) {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getListController('block')
->render($theme);
}
......
......@@ -16,7 +16,7 @@
* @see custom_block_menu()
*/
function custom_block_type_list() {
return drupal_container()->get('plugin.manager.entity')->getListController('custom_block_type')->render();
return Drupal::entityManager()->getListController('custom_block_type')->render();
}
/**
......
......@@ -83,7 +83,7 @@ function config_test_load($id) {
* Page callback; Lists available ConfigTest objects.
*/
function config_test_list_page() {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getListController('config_test')
->render();
}
......
......@@ -17,7 +17,7 @@
*/
function contact_category_list() {
drupal_set_title(t('Contact form categories'));
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getListController('contact_category')
->render();
}
......
......@@ -266,7 +266,7 @@ public function getExportProperties() {
*/
public function save() {
$module_handler = \Drupal::moduleHandler();
$storage_controller = \Drupal::service('plugin.manager.entity')->getStorageController($this->entityType);
$storage_controller = \Drupal::entityManager()->getStorageController($this->entityType);
// Clear the derived data about the field.
unset($this->schema, $this->storageDetails);
......@@ -295,7 +295,7 @@ public function save() {
// Disallow reserved field names. This can't prevent all field name
// collisions with existing entity properties, but some is better than
// none.
foreach (\Drupal::service('plugin.manager.entity')->getDefinitions() as $type => $info) {
foreach (\Drupal::entityManager()->getDefinitions() as $type => $info) {
if (in_array($this->id, $info['entity_keys'])) {
throw new FieldException(format_string('Attempt to create field %id which is reserved by entity type %type.', array('%id' => $this->id, '%type' => $type)));
}
......@@ -388,7 +388,7 @@ public function save() {
public function delete() {
if (!$this->deleted) {
$module_handler = \Drupal::moduleHandler();
$instance_controller = \Drupal::service('plugin.manager.entity')->getStorageController('field_instance');
$instance_controller = \Drupal::entityManager()->getStorageController('field_instance');
$state = \Drupal::state();
// Delete all non-deleted instances.
......
......@@ -321,7 +321,7 @@ public function getExportProperties() {
*/
public function save() {
$module_handler = \Drupal::moduleHandler();
$entity_manager = \Drupal::service('plugin.manager.entity');
$entity_manager = \Drupal::entityManager();
$instance_controller = $entity_manager->getStorageController($this->entityType);
if ($this->isNew()) {
......
......@@ -414,7 +414,7 @@ function file_validate_size(File $file, $file_limit = 0, $user_limit = 0) {
}
// Save a query by only calling spaceUsed() when a limit is provided.
if ($user_limit && (drupal_container()->get('plugin.manager.entity')->getStorageController('file')->spaceUsed($user->uid) + $file->filesize) > $user_limit) {
if ($user_limit && (Drupal::entityManager()->getStorageController('file')->spaceUsed($user->uid) + $file->filesize) > $user_limit) {
$errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_size($file->filesize), '%quota' => format_size($user_limit)));
}
......@@ -716,7 +716,7 @@ function file_file_download($uri, $field_type = 'file') {
* Implements file_cron()
*/
function file_cron() {
$result = drupal_container()->get('plugin.manager.entity')->getStorageController('file')->retrieveTemporaryFiles();
$result = Drupal::entityManager()->getStorageController('file')->retrieveTemporaryFiles();
foreach ($result as $row) {
if ($file = file_load($row->fid)) {
$references = file_usage()->listUsage($file);
......
......@@ -41,7 +41,7 @@ protected function getCancelPath() {
*/
protected function getDescription() {
$caption = '';
$num_links = drupal_container()->get('plugin.manager.entity')
$num_links = \Drupal::entityManager()
->getStorageController('menu_link')->countMenuLinks($this->menu->id());
if ($num_links) {
$caption .= '<p>' . format_plural($num_links, '<strong>Warning:</strong> There is currently 1 menu link in %title. It will be deleted (system-defined items will be reset).', '<strong>Warning:</strong> There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', array('%title' => $this->menu->label())) . '</p>';
......
......@@ -14,7 +14,7 @@
* Menu callback which shows an overview page of all the custom menus and their descriptions.
*/
function menu_overview_page() {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getListController('menu')
->render();
}
......
......@@ -110,7 +110,7 @@ public function form(array $form, array &$form_state) {
);
// Get number of items in menu so the weight selector is sized appropriately.
$delta = drupal_container()->get('plugin.manager.entity')
$delta = \Drupal::entityManager()
->getStorageController('menu_link')->countMenuLinks($menu_link->menu_name);
$form['weight'] = array(
'#type' => 'weight',
......
......@@ -323,7 +323,7 @@ public static function buildFromRouterItem(array $item) {
'link_path' => $item['path'],
'options' => empty($item['description']) ? array() : array('attributes' => array('title' => $item['description'])),
);
return drupal_container()->get('plugin.manager.entity')
return \Drupal::entityManager()
->getStorageController('menu_link')->create($item);
}
......
......@@ -86,7 +86,7 @@ function menu_link_delete_multiple(array $mlids, $force = FALSE, $prevent_repare
return;
}
$controller = drupal_container()->get('plugin.manager.entity')
$controller = Drupal::entityManager()
->getStorageController('menu_link');
if (!$force) {
$entity_query = Drupal::entityQuery('menu_link');
......@@ -141,7 +141,7 @@ function menu_link_save(MenuLink $menu_link) {
* The insert op returns the mlid of the new item. Others op return NULL.
*/
function menu_link_maintain($module, $op, $link_path, $link_title = NULL) {
$menu_link_controller = drupal_container()->get('plugin.manager.entity')
$menu_link_controller = Drupal::entityManager()
->getStorageController('menu_link');
switch ($op) {
case 'insert':
......
......@@ -16,7 +16,7 @@
* @see picture_menu()
*/
function picture_mapping_page() {
return drupal_container()->get('plugin.manager.entity')
return Drupal::entityManager()
->getListController('picture_mapping')
->render();
}
......
......@@ -178,7 +178,7 @@ function __construct($test_id = NULL) {
*/
function drupalGetNodeByTitle($title, $reset = FALSE) {
if ($reset) {
drupal_container()->get('plugin.manager.entity')->getStorageController('node')->resetCache();
\Drupal::entityManager()->getStorageController('node')->resetCache();
}
$nodes = entity_load_multiple_by_properties('node', array('title' => $title));
// Load the first node returned from the database.
......
......@@ -581,7 +581,7 @@ function taxonomy_term_is_page(Term $term) {
* Clear all static cache variables for terms.
*/
function taxonomy_terms_static_reset() {
drupal_container()->get('plugin.manager.entity')->getStorageController('taxonomy_term')->resetCache();
Drupal::entityManager()->getStorageController('taxonomy_term')->resetCache();
}
/**
......@@ -591,7 +591,7 @@ function taxonomy_terms_static_reset() {
* An array of ids to reset in entity controller cache.
*/
function taxonomy_vocabulary_static_reset(array $ids = NULL) {
drupal_container()->get('plugin.manager.entity')->getStorageController('taxonomy_vocabulary')->resetCache($ids);
Drupal::entityManager()->getStorageController('taxonomy_vocabulary')->resetCache($ids);
}
/**
......
......@@ -1040,7 +1040,7 @@ function views_get_applicable_views($type) {
->execute();
$result = array();
foreach (Drupal::service('plugin.manager.entity')->getStorageController('view')->load($entity_ids) as $view) {
foreach (Drupal::entityManager()->getStorageController('view')->load($entity_ids) as $view) {
// Check each display to see if it meets the criteria and is enabled.
$executable = $view->get('executable');
$executable->initDisplay();
......@@ -1058,7 +1058,7 @@ function views_get_applicable_views($type) {
* Returns an array of all views as fully loaded $view objects.
*/
function views_get_all_views() {
return drupal_container()->get('plugin.manager.entity')->getStorageController('view')->load();
return Drupal::entityManager()->getStorageController('view')->load();
}
/**
......
......@@ -167,7 +167,7 @@ public function getForm(ViewStorageInterface $view, $display_id, $js) {
// If this form was for view-wide changes, there's no need to regenerate
// the display section of the form.
if ($display_id !== '') {
drupal_container()->get('plugin.manager.entity')->getFormController('view', 'edit')->rebuildCurrentTab($view, $response, $display_id);
\Drupal::entityManager()->getFormController('view', 'edit')->rebuildCurrentTab($view, $response, $display_id);
}
return $response;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment