diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index dd4c028..b147737 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -9,9 +9,13 @@ use Drupal\Component\Uuid\Uuid; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityControllerInterface; use Drupal\Core\Entity\EntityMalformedException; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Config\Config; +use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Config\StorageInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines the storage controller class for configuration entities. @@ -28,7 +32,7 @@ * after the config_prefix in a config name forms the entity ID. Additional or * custom suffixes are not possible. */ -class ConfigStorageController implements EntityStorageControllerInterface { +class ConfigStorageController implements EntityStorageControllerInterface, EntityControllerInterface { /** * Entity type for this controller instance. @@ -77,11 +81,21 @@ class ConfigStorageController implements EntityStorageControllerInterface { protected $statusKey = 'status'; /** + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** + * @var \Drupal\Core\Config\StorageInterface + */ + protected $configStorage; + + /** * Implements Drupal\Core\Entity\EntityStorageControllerInterface::__construct(). * * Sets basic variables. */ - public function __construct($entityType) { + public function __construct($entityType, ConfigFactory $config_factory, StorageInterface $config_storage) { $this->entityType = $entityType; $this->entityInfo = entity_get_info($entityType); $this->hookLoadArguments = array(); @@ -93,6 +107,20 @@ public function __construct($entityType) { else { $this->statusKey = FALSE; } + + $this->configFactory = $config_factory; + $this->configStorage = $config_storage; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type) { + return new static( + $entity_type, + $container->get('config.factory'), + $container->get('config.storage') + ); } /** @@ -225,10 +253,10 @@ protected function buildQuery($ids, $revision_id = FALSE) { // Load all of the configuration entities. if ($ids === NULL) { - $names = drupal_container()->get('config.storage')->listAll($prefix); + $names = $this->configStorage->listAll($prefix); $result = array(); foreach ($names as $name) { - $config = config($name); + $config = $this->configFactory->get($name); $result[$config->get($this->idKey)] = new $config_class($config->get(), $this->entityType); } return $result; @@ -237,7 +265,7 @@ protected function buildQuery($ids, $revision_id = FALSE) { $result = array(); foreach ($ids as $id) { // Add the prefix to the ID to serve as the configuration object name. - $config = config($prefix . $id); + $config = $this->configFactory->get($prefix . $id); if (!$config->isNew()) { $result[$id] = new $config_class($config->get(), $this->entityType); } @@ -322,13 +350,13 @@ public function delete(array $entities) { } foreach ($entities as $id => $entity) { - $config = config($this->getConfigPrefix() . $entity->id()); + $config = $this->configFactory->get($this->getConfigPrefix() . $entity->id()); $config->delete(); // Remove the entity from the manifest file. Entity IDs can contain a dot // so we can not use Config::clear() to remove the entity from the // manifest. - $manifest = config('manifest.' . $this->entityInfo['config_prefix']); + $manifest = $this->configFactory->get('manifest.' . $this->entityInfo['config_prefix']); $manifest_data = $manifest->get(); unset($manifest_data[$entity->id()]); $manifest->setData($manifest_data); @@ -361,7 +389,7 @@ public function save(EntityInterface $entity) { if ($entity->getOriginalID() !== NULL) { $id = $entity->getOriginalID(); } - $config = config($prefix . $id); + $config = $this->configFactory->get($prefix . $id); $is_new = $config->isNew(); if (!$is_new && !isset($entity->original)) { @@ -375,7 +403,7 @@ public function save(EntityInterface $entity) { // - Storage controller needs to access the original object. // - The object needs to be renamed/copied in ConfigFactory and reloaded. // - All instances of the object need to be renamed. - drupal_container()->get('config.factory')->rename($prefix . $id, $prefix . $entity->id()); + $this->configFactory->rename($prefix . $id, $prefix . $entity->id()); } $this->preSave($entity); @@ -404,7 +432,7 @@ public function save(EntityInterface $entity) { } $update_manifest = FALSE; - $config = config('manifest.' . $this->entityInfo['config_prefix']); + $config = $this->configFactory->get('manifest.' . $this->entityInfo['config_prefix']); $manifest = $config->get(); // If the save operation resulted in a rename remove the old entity id from // the manifest file. diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php index 4810841..c2cc695 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php @@ -12,7 +12,6 @@ use Drupal\Component\Uuid\Uuid; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Database\Connection; -use Drupal\Core\Entity\EntityHandlerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -24,7 +23,7 @@ * This class can be used as-is by most simple entity types. Entity types * requiring special handling can extend the class. */ -class DatabaseStorageController implements EntityStorageControllerInterface, EntityControllerInterface{ +class DatabaseStorageController implements EntityStorageControllerInterface, EntityControllerInterface { /** * Static cache of entities. @@ -123,9 +122,9 @@ class DatabaseStorageController implements EntityStorageControllerInterface, Ent protected $database; /** - * Implements \Drupal\Core\Entity\EntityHandlerInterface::createInstance(). + * Implements \Drupal\Core\Entity\EntityControllerInterface::createInstance(). */ - public static function createInstance(ContainerInterface $container, $entity_type, EntityStorageControllerInterface $storage = NULL, $operation = NULL) { + public static function createInstance(ContainerInterface $container, $entity_type) { return new static( $entity_type, $container->get('database') diff --git a/core/lib/Drupal/Core/Entity/EntityControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityControllerInterface.php index 46b2cbb..519dac9 100644 --- a/core/lib/Drupal/Core/Entity/EntityControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityControllerInterface.php @@ -33,11 +33,10 @@ * The service container this object should use. * @param string $entity_type * The entity type which the controller handles. - * @param Drupal\Core\Entity\EntityStorageControllerInterface $storage - * (optional) Storage controller for the given entity type. Required for - * list controllers. - * @param string $operation - * (optional) Form operation, required for form controllers. + * + * @return static + * A new instance of the entity controller. */ - public static function createInstance(ContainerInterface $container, $entity_type, EntityStorageControllerInterface $storage = NULL, $operation = NULL); + public static function createInstance(ContainerInterface $container, $entity_type); + } diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 3638e0d..6e704d0 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -323,7 +323,7 @@ public function getFormController($entity_type, $operation) { if (!isset($this->controllers['form'][$operation][$entity_type])) { $class = $this->getControllerClass($entity_type, 'form_controller_class', $operation); if (in_array('Drupal\Core\Entity\EntityControllerInterface', class_implements($class))) { - $this->controllers['form'][$operation][$entity_type] = $class::createInstance($this->container, $entity_type, NULL, $operation); + $this->controllers['form'][$operation][$entity_type] = $class::createInstance($this->container, $entity_type, $operation); } else { $this->controllers['form'][$operation][$entity_type] = new $class($operation); diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php index 9506602..a951bdd 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php @@ -9,11 +9,38 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Entity\EntityControllerInterface; +use Drupal\Core\CacheDecorator\AliasManagerCacheDecorator; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the node edit forms. */ -class MenuLinkFormController extends EntityFormController { +class MenuLinkFormController extends EntityFormController implements EntityControllerInterface { + + /** + * Constructs a new MenuLinkFormController object. + * + * @param string $operation + * The name of the current operation. + * @param \Drupal\user\TempStoreFactory $temp_store_factory + * The factory for the temp store object. + */ + public function __construct($operation, AliasManagerCacheDecorator $path_alias_manager) { + parent::__construct($operation); + + $this->pathAliasManager = $path_alias_manager; + } + + /** + * Implements \Drupal\Core\Entity\EntityControllerInterface::createInstance(). + */ + public static function createInstance(ContainerInterface $container, $entity_type, $operation = NULL) { + return new static( + $operation, + $container->get('path.alias_manager.cached') + ); + } /** * Overrides EntityFormController::form(). @@ -148,7 +175,7 @@ protected function actions(array $form, array &$form_state) { public function validate(array $form, array &$form_state) { $menu_link = $this->buildEntity($form, $form_state); - $normal_path = drupal_container()->get('path.alias_manager.cached')->getSystemPath($menu_link->link_path); + $normal_path = $this->pathAliasManager->getSystemPath($menu_link->link_path); if ($menu_link->link_path != $normal_path) { drupal_set_message(t('The menu system stores system paths only, but will use the URL alias for display. %link_path has been stored as %normal_path', array('%link_path' => $menu_link->link_path, '%normal_path' => $normal_path))); $menu_link->link_path = $normal_path; diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php index 2a1dbb3..22171d2 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php @@ -11,6 +11,8 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Database\Connection; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Cmf\Component\Routing\RouteProviderInterface; /** * Controller class for menu links. @@ -35,17 +37,35 @@ class MenuLinkStorageController extends DatabaseStorageController { protected static $routerItemFields = array(); /** + * @var \Symfony\Cmf\Component\Routing\RouteProviderInterface + */ + protected $routeProvider; + + /** * Overrides DatabaseStorageController::__construct(). */ - public function __construct($entityType, Connection $database) { + public function __construct($entityType, Connection $database, RouteProviderInterface $route_provider) { parent::__construct($entityType, $database); + $this->routeProvider = $route_provider; + if (empty(static::$routerItemFields)) { static::$routerItemFields = array_diff(drupal_schema_fields_sql('menu_router'), array('weight')); } } /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type) { + return new static( + $entity_type, + $container->get('database'), + $container->get('router.route_provider') + ); + } + + /** * Overrides DatabaseStorageController::buildQuery(). */ protected function buildQuery($ids, $revision_id = FALSE) { @@ -80,7 +100,7 @@ protected function attachLoad(&$menu_links, $load_revision = FALSE) { // Now mass-load any routes needed and associate them. if ($routes) { - $route_objects = drupal_container()->get('router.route_provider')->getRoutesByNames($routes); + $route_objects = $this->routeProvider->getRoutesByNames($routes); foreach ($routes as $entity_id => $route) { $menu_links[$entity_id]->setRouteObject($route_objects[$route]); } diff --git a/core/modules/user/lib/Drupal/user/UserStorageController.php b/core/modules/user/lib/Drupal/user/UserStorageController.php index 3d8e981..6a5da02 100644 --- a/core/modules/user/lib/Drupal/user/UserStorageController.php +++ b/core/modules/user/lib/Drupal/user/UserStorageController.php @@ -10,6 +10,10 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityMalformedException; use Drupal\Core\Entity\DatabaseStorageController; +use Drupal\Core\Password\PasswordInterface; +use Drupal\Core\Database\Connection; +use Drupal\user\UserDataInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Controller class for users. @@ -20,6 +24,42 @@ class UserStorageController extends DatabaseStorageController { /** + * Provides the password hashing service object. + * + * @var \Drupal\Core\Password\PasswordInterface + */ + protected $password; + + /** + * Provides the user data service object. + * + * @var \Drupal\user\UserDataInterface + */ + protected $userData; + + /** + * Constructs a new UserStorageController object. + */ + public function __construct($entity_type, Connection $database, PasswordInterface $password, UserDataInterface $user_data) { + parent::__construct($entity_type, $database); + + $this->password = $password; + $this->userData = $user_data; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type) { + return new static( + $entity_type, + $container->get('database'), + $container->get('password'), + $container->get('user.data') + ); + } + + /** * Overrides Drupal\Core\Entity\DatabaseStorageController::attachLoad(). */ function attachLoad(&$queried_users, $load_revision = FALSE) { @@ -62,7 +102,7 @@ public function create(array $values) { */ public function save(EntityInterface $entity) { if (empty($entity->uid)) { - $entity->uid = db_next_id(db_query('SELECT MAX(uid) FROM {users}')->fetchField()); + $entity->uid = $this->database->nextId(db_query('SELECT MAX(uid) FROM {users}')->fetchField()); $entity->enforceIsNew(); } parent::save($entity); @@ -75,7 +115,7 @@ protected function preSave(EntityInterface $entity) { // Update the user password if it has changed. if ($entity->isNew() || (!empty($entity->pass) && $entity->pass != $entity->original->pass)) { // Allow alternate password hashing schemes. - $entity->pass = drupal_container()->get('password')->hash(trim($entity->pass)); + $entity->pass = $this->password->hash(trim($entity->pass)); // Abort if the hashing failed and returned FALSE. if (!$entity->pass) { throw new EntityMalformedException('The entity does not have a password.'); @@ -98,7 +138,7 @@ protected function preSave(EntityInterface $entity) { // Store account cancellation information. foreach (array('user_cancel_method', 'user_cancel_notify') as $key) { if (isset($entity->{$key})) { - drupal_container()->get('user.data')->set('user', $entity->id(), substr($key, 5), $entity->{$key}); + $this->userData->set('user', $entity->id(), substr($key, 5), $entity->{$key}); } } } @@ -123,11 +163,11 @@ protected function postSave(EntityInterface $entity, $update) { // Reload user roles if provided. if ($entity->roles != $entity->original->roles) { - db_delete('users_roles') + $this->database->delete('users_roles') ->condition('uid', $entity->uid) ->execute(); - $query = db_insert('users_roles')->fields(array('uid', 'rid')); + $query = $this->database->insert('users_roles')->fields(array('uid', 'rid')); foreach (array_keys($entity->roles) as $rid) { if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) { $query->values(array( @@ -154,7 +194,7 @@ protected function postSave(EntityInterface $entity, $update) { else { // Save user roles. if (count($entity->roles) > 1) { - $query = db_insert('users_roles')->fields(array('uid', 'rid')); + $query = $this->database->insert('users_roles')->fields(array('uid', 'rid')); foreach (array_keys($entity->roles) as $rid) { if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) { $query->values(array( @@ -172,9 +212,9 @@ protected function postSave(EntityInterface $entity, $update) { * Overrides Drupal\Core\Entity\DatabaseStorageController::postDelete(). */ protected function postDelete($entities) { - db_delete('users_roles') + $this->database->delete('users_roles') ->condition('uid', array_keys($entities), 'IN') ->execute(); - drupal_container()->get('user.data')->delete(NULL, array_keys($entities)); + $this->userData->delete(NULL, array_keys($entities)); } } diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewAddFormController.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewAddFormController.php index 474c1e1..4b3dad9 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewAddFormController.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewAddFormController.php @@ -8,14 +8,45 @@ namespace Drupal\views_ui; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityControllerInterface; use Drupal\views\Plugin\views\wizard\WizardPluginBase; use Drupal\views\Plugin\views\wizard\WizardException; -use Drupal\views\Views; +use Drupal\views\Plugin\ViewsPluginManager; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the Views edit form. */ -class ViewAddFormController extends ViewFormControllerBase { +class ViewAddFormController extends ViewFormControllerBase implements EntityControllerInterface { + + /** + * @var \Drupal\views\Plugin\ViewsPluginManager + */ + protected $wizardManager; + + /** + * Constructs a new ViewEditFormController object. + * + * @param string $operation + * The name of the current operation. + * @param \Drupal\views\Plugin\ViewsPluginManager $wizard_manager + * The wizard plugin manager. + */ + public function __construct($operation, ViewsPluginManager $wizard_manager) { + parent::__construct($operation); + + $this->wizardManager = $wizard_manager; + } + + /** + * Implements \Drupal\Core\Entity\EntityControllerInterface::createInstance(). + */ + public static function createInstance(ContainerInterface $container, $entity_type, $operation = NULL) { + return new static( + $operation, + $container->get('plugin.manager.views.wizard') + ); + } /** * Overrides Drupal\Core\Entity\EntityFormController::prepareForm(). @@ -89,7 +120,7 @@ public function form(array $form, array &$form_state, EntityInterface $view) { // Create the "Show" dropdown, which allows the base table of the view to be // selected. - $wizard_plugins = Views::pluginManager('wizard')->getDefinitions(); + $wizard_plugins = $this->wizardManager->getDefinitions(); $options = array(); foreach ($wizard_plugins as $key => $wizard) { $options[$key] = $wizard['title']; @@ -108,7 +139,7 @@ public function form(array $form, array &$form_state, EntityInterface $view) { // Build the rest of the form based on the currently selected wizard plugin. $wizard_key = $show_form['wizard_key']['#default_value']; - $wizard_instance = Views::pluginManager('wizard')->createInstance($wizard_key); + $wizard_instance = $this->wizardManager->createInstance($wizard_key); $form = $wizard_instance->build_form($form, $form_state); return $form; @@ -136,7 +167,7 @@ protected function actions(array $form, array &$form_state) { */ public function validate(array $form, array &$form_state) { $wizard_type = $form_state['values']['show']['wizard_key']; - $wizard_instance = Views::pluginManager('wizard')->createInstance($wizard_type); + $wizard_instance = $this->wizardManager->createInstance($wizard_type); $form_state['wizard'] = $wizard_instance->getDefinition(); $form_state['wizard_instance'] = $wizard_instance; $errors = $form_state['wizard_instance']->validateView($form, $form_state); diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php index 48d195a..22f4a0b 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php @@ -13,11 +13,57 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Component\Utility\NestedArray; use Drupal\views\ViewExecutable; +use Drupal\Core\Entity\EntityControllerInterface; +use Drupal\user\TempStoreFactory; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the Views edit form. */ -class ViewEditFormController extends ViewFormControllerBase { +class ViewEditFormController extends ViewFormControllerBase implements EntityControllerInterface { + + /** + * The views temp store. + * + * @var \Drupal\user\TempStore + */ + protected $tempStore; + + /** + * The request object. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; + + /** + * Constructs a new ViewEditFormController object. + * + * @param string $operation + * The name of the current operation. + * @param \Drupal\user\TempStoreFactory $temp_store_factory + * The factory for the temp store object. + * @param \Symfony\Component\HttpFoundation\Request $request + * The request object. + */ + public function __construct($operation, TempStoreFactory $temp_store_factory, Request $request) { + parent::__construct($operation); + + $this->tempStore = $temp_store_factory->get('views'); + $this->request = $request; + } + + /** + * Implements \Drupal\Core\Entity\EntityControllerInterface::createInstance(). + */ + public static function createInstance(ContainerInterface $container, $entity_type, $operation = NULL) { + return new static( + $operation, + $container->get('user.tempstore'), + $container->get('request') + ); + } /** * Overrides Drupal\Core\Entity\EntityFormController::getEntity(). @@ -242,7 +288,7 @@ public function submit(array $form, array &$form_state) { $view->set('display', $displays); // Direct the user to the right url, if the path of the display has changed. - $query = drupal_container()->get('request')->query; + $query = $this->request->query; // @todo: Revisit this when http://drupal.org/node/1668866 is in. $destination = $query->get('destination'); if (!empty($destination)) { @@ -271,7 +317,7 @@ public function submit(array $form, array &$form_state) { drupal_set_message(t('The view %name has been saved.', array('%name' => $view->label()))); // Remove this view from cache so we can edit it properly. - drupal_container()->get('user.tempstore')->get('views')->delete($view->id()); + $this->tempStore->delete($view->id()); } /** @@ -285,7 +331,7 @@ public function submit(array $form, array &$form_state) { public function cancel(array $form, array &$form_state) { // Remove this view from cache so edits will be lost. $view = $this->getEntity($form_state); - drupal_container()->get('user.tempstore')->get('views')->delete($view->id()); + $this->tempStore->delete($view->id()); $form_state['redirect'] = 'admin/structure/views'; } @@ -725,7 +771,7 @@ public function renderDisplayTop(ViewUI $view) { * should not yet redirect to the destination. */ public function submitDelayDestination($form, &$form_state) { - $query = \Drupal::service('request')->query; + $query = $this->request->query; // @todo: Revisit this when http://drupal.org/node/1668866 is in. $destination = $query->get('destination'); if (isset($destination) && $form_state['redirect'] !== FALSE) { diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php index 6b6821b..b2476d3 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php @@ -8,11 +8,45 @@ namespace Drupal\views_ui; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityControllerInterface; +use Drupal\user\TempStoreFactory; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the Views preview form. */ -class ViewPreviewFormController extends ViewFormControllerBase { +class ViewPreviewFormController extends ViewFormControllerBase implements EntityControllerInterface { + + /** + * The views temp store. + * + * @var \Drupal\user\TempStore + */ + protected $tempStore; + + /** + * Constructs a new ViewPreviewFormController object. + * + * @param string $operation + * The name of the current operation. + * @param \Drupal\user\TempStoreFactory $temp_store_factory + * The factory for the temp store object. + */ + public function __construct($operation, TempStoreFactory $temp_store_factory) { + parent::__construct($operation); + + $this->tempStore = $temp_store_factory->get('views'); + } + + /** + * Implements \Drupal\Core\Entity\EntityControllerInterface::createInstance(). + */ + public static function createInstance(ContainerInterface $container, $entity_type, $operation = NULL) { + return new static( + $operation, + $container->get('user.tempstore') + ); + } /** * Overrides Drupal\Core\Entity\EntityFormController::form(). @@ -99,7 +133,7 @@ public function submitPreview($form, &$form_state) { // Rebuild the form with a pristine $view object. $view = $this->getEntity($form_state); // Attempt to load the view from temp store, otherwise create a new one. - if (!$new_view = drupal_container()->get('user.tempstore')->get('views')->get($view->id())) { + if (!$new_view = $this->tempStore->get($view->id())) { $new_view = new ViewUI($view); } $form_state['build_info']['args'][0] = $new_view;