diff --git a/core/core.services.yml b/core/core.services.yml index 9dca742..5f9d499 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -150,7 +150,7 @@ services: - { name: persist } plugin.manager.entity: class: Drupal\Core\Entity\EntityManager - arguments: ['@container.namespaces'] + arguments: ['@container.namespaces', '@service_container'] plugin.manager.archiver: class: Drupal\Core\Archiver\ArchiverManager arguments: ['@container.namespaces'] diff --git a/core/includes/menu.inc b/core/includes/menu.inc index ccf703e..3e6e810 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -2762,7 +2762,7 @@ function _menu_navigation_links_rebuild($menu) { else { // The Menu link module is not available at install time, so we need to // hardcode the default storage controller. - $menu_link_controller = new MenuLinkStorageController('menu_link'); + $menu_link_controller = new MenuLinkStorageController('menu_link', Drupal::service('database'), Drupal::service('router.route_provider')); } // Add normal and suggested items as links. diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index 5487e04..9dfc622 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,30 @@ class ConfigStorageController implements EntityStorageControllerInterface { protected $statusKey = 'status'; /** - * Implements Drupal\Core\Entity\EntityStorageControllerInterface::__construct(). + * The config factory service. * - * Sets basic variables. + * @var \Drupal\Core\Config\ConfigFactory */ - public function __construct($entityType) { + protected $configFactory; + + /** + * The config storage service. + * + * @var \Drupal\Core\Config\StorageInterface + */ + protected $configStorage; + + /** + * Constructs a ConfigStorageController object. + * + * @param string $entityType + * The entity type for which the instance is created. + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The config factory service. + * @param \Drupal\Core\Config\StorageInterface $config_storage + * The config storage service. + */ + public function __construct($entityType, ConfigFactory $config_factory, StorageInterface $config_storage) { $this->entityType = $entityType; $this->entityInfo = entity_get_info($entityType); $this->hookLoadArguments = array(); @@ -93,6 +116,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 +262,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 +274,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); } @@ -325,13 +362,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); @@ -364,7 +401,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)) { @@ -378,7 +415,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); @@ -407,7 +444,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 6bb91e1..4192f5a 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php @@ -12,7 +12,9 @@ use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Component\Uuid\Uuid; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Database\Connection; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines a base entity controller class. @@ -22,7 +24,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 { +class DatabaseStorageController implements EntityStorageControllerInterface, EntityControllerInterface { /** * Static cache of entities. @@ -113,14 +115,33 @@ class DatabaseStorageController implements EntityStorageControllerInterface { */ protected $cache; + /** + * Active database connection. + * + * @var \Drupal\Core\Database\Connection + */ + protected $database; + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type) { + return new static( + $entity_type, + $container->get('database') + ); + } /** * Constructs a DatabaseStorageController object. * * @param string $entityType * The entity type for which the instance is created. + * @param \Drupal\Core\Database\Connection $database + * The database connection to be used. */ - public function __construct($entityType) { + public function __construct($entityType, Connection $database) { + $this->database = $database; $this->entityType = $entityType; $this->entityInfo = entity_get_info($entityType); $this->entityCache = array(); @@ -279,7 +300,7 @@ public function deleteRevision($revision_id) { throw new EntityStorageException('Default revision can not be deleted'); } - db_delete($this->revisionTable) + $this->database->delete($this->revisionTable) ->condition($this->revisionKey, $revision->getRevisionId()) ->execute(); $this->invokeHook('revision_delete', $revision); @@ -333,7 +354,7 @@ protected function buildPropertyQuery(QueryInterface $entity_query, array $value * A SelectQuery object for loading the entity. */ protected function buildQuery($ids, $revision_id = FALSE) { - $query = db_select($this->entityInfo['base_table'], 'base'); + $query = $this->database->select($this->entityInfo['base_table'], 'base'); $query->addTag($this->entityType . '_load_multiple'); @@ -475,7 +496,7 @@ public function delete(array $entities) { // If no IDs or invalid IDs were passed, do nothing. return; } - $transaction = db_transaction(); + $transaction = $this->database->startTransaction(); try { $this->preDelete($entities); @@ -484,12 +505,12 @@ public function delete(array $entities) { } $ids = array_keys($entities); - db_delete($this->entityInfo['base_table']) + $this->database->delete($this->entityInfo['base_table']) ->condition($this->idKey, $ids, 'IN') ->execute(); if ($this->revisionKey) { - db_delete($this->revisionTable) + $this->database->delete($this->revisionTable) ->condition($this->idKey, $ids, 'IN') ->execute(); } @@ -515,7 +536,7 @@ public function delete(array $entities) { * Implements \Drupal\Core\Entity\EntityStorageControllerInterface::save(). */ public function save(EntityInterface $entity) { - $transaction = db_transaction(); + $transaction = $this->database->startTransaction(); try { // Load the stored entity, if any. if (!$entity->isNew() && !isset($entity->original)) { @@ -593,7 +614,7 @@ protected function saveRevision(EntityInterface $entity) { if ($entity->isNewRevision()) { drupal_write_record($this->revisionTable, $record); if ($entity->isDefaultRevision()) { - db_update($this->entityInfo['base_table']) + $this->database->update($this->entityInfo['base_table']) ->fields(array($this->revisionKey => $record[$this->revisionKey])) ->condition($this->idKey, $entity->id()) ->execute(); diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php index 9b7020a..d538d48 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php @@ -14,6 +14,7 @@ use Drupal\Core\Entity\DatabaseStorageController; use Drupal\Core\Entity\EntityStorageException; use Drupal\Component\Uuid\Uuid; +use Drupal\Core\Database\Connection; /** * Implements Field API specific enhancements to the DatabaseStorageController class. @@ -51,8 +52,8 @@ class DatabaseStorageControllerNG extends DatabaseStorageController { /** * Overrides DatabaseStorageController::__construct(). */ - public function __construct($entityType) { - parent::__construct($entityType); + public function __construct($entityType, Connection $database) { + parent::__construct($entityType, $database); $this->bundleKey = !empty($this->entityInfo['entity_keys']['bundle']) ? $this->entityInfo['entity_keys']['bundle'] : FALSE; $this->entityClass = $this->entityInfo['class']; @@ -222,7 +223,7 @@ protected function mapFromStorageRecords(array $records, $load_revision = FALSE) */ protected function attachPropertyData(array &$entities, $load_revision = FALSE) { if ($this->dataTable) { - $query = db_select($this->dataTable, 'data', array('fetch' => PDO::FETCH_ASSOC)) + $query = $this->database->select($this->dataTable, 'data', array('fetch' => PDO::FETCH_ASSOC)) ->fields('data') ->condition($this->idKey, array_keys($entities)) ->orderBy('data.' . $this->idKey); @@ -270,7 +271,7 @@ protected function attachPropertyData(array &$entities, $load_revision = FALSE) * Added mapping from entities to storage records before saving. */ public function save(EntityInterface $entity) { - $transaction = db_transaction(); + $transaction = $this->database->startTransaction(); try { // Ensure we are dealing with the actual entity. $entity = $entity->getNGEntity(); @@ -363,7 +364,7 @@ protected function saveRevision(EntityInterface $entity) { if ($entity->isNewRevision()) { drupal_write_record($this->revisionTable, $record); if ($entity->isDefaultRevision()) { - db_update($this->entityInfo['base_table']) + $this->database->update($this->entityInfo['base_table']) ->fields(array($this->revisionKey => $record->{$this->revisionKey})) ->condition($this->idKey, $record->{$this->idKey}) ->execute(); @@ -386,11 +387,11 @@ protected function saveRevision(EntityInterface $entity) { */ protected function savePropertyData(EntityInterface $entity) { // Delete and insert to handle removed values. - db_delete($this->dataTable) + $this->database->delete($this->dataTable) ->condition($this->idKey, $entity->id()) ->execute(); - $query = db_insert($this->dataTable); + $query = $this->database->insert($this->dataTable); foreach ($entity->getTranslationLanguages() as $langcode => $language) { $record = $this->mapToDataStorageRecord($entity, $langcode); @@ -497,7 +498,7 @@ public function delete(array $entities) { return; } - $transaction = db_transaction(); + $transaction = $this->database->startTransaction(); try { // Ensure we are dealing with the actual entities. foreach ($entities as $id => $entity) { @@ -510,18 +511,18 @@ public function delete(array $entities) { } $ids = array_keys($entities); - db_delete($this->entityInfo['base_table']) + $this->database->delete($this->entityInfo['base_table']) ->condition($this->idKey, $ids) ->execute(); if ($this->revisionKey) { - db_delete($this->revisionTable) + $this->database->delete($this->revisionTable) ->condition($this->idKey, $ids) ->execute(); } if ($this->dataTable) { - db_delete($this->dataTable) + $this->database->delete($this->dataTable) ->condition($this->idKey, $ids) ->execute(); } diff --git a/core/lib/Drupal/Core/Entity/EntityControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityControllerInterface.php new file mode 100644 index 0000000..f7ac1cd --- /dev/null +++ b/core/lib/Drupal/Core/Entity/EntityControllerInterface.php @@ -0,0 +1,41 @@ + DRUPAL_ROOT . '/core/lib', @@ -56,6 +66,7 @@ public function __construct(\Traversable $namespaces) { $this->discovery = new CacheDecorator($this->discovery, 'entity_info:' . language(LANGUAGE_TYPE_INTERFACE)->langcode, 'cache', CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE)); $this->factory = new DefaultFactory($this->discovery); + $this->container = $container; } /** @@ -125,7 +136,12 @@ public function getControllerClass($entity_type, $controller_type, $nested = NUL public function getStorageController($entity_type) { if (!isset($this->controllers['storage'][$entity_type])) { $class = $this->getControllerClass($entity_type, 'storage'); - $this->controllers['storage'][$entity_type] = new $class($entity_type); + if (in_array('Drupal\Core\Entity\EntityControllerInterface', class_implements($class))) { + $this->controllers['storage'][$entity_type] = $class::createInstance($this->container, $entity_type); + } + else { + $this->controllers['storage'][$entity_type] = new $class($entity_type); + } } return $this->controllers['storage'][$entity_type]; } @@ -142,7 +158,12 @@ public function getStorageController($entity_type) { public function getListController($entity_type) { if (!isset($this->controllers['listing'][$entity_type])) { $class = $this->getControllerClass($entity_type, 'list'); - $this->controllers['listing'][$entity_type] = new $class($entity_type, $this->getStorageController($entity_type)); + if (in_array('Drupal\Core\Entity\EntityControllerInterface', class_implements($class))) { + $this->controllers['listing'][$entity_type] = $class::createInstance($this->container, $entity_type, $this->getStorageController($entity_type)); + } + else { + $this->controllers['listing'][$entity_type] = new $class($entity_type, $this->getStorageController($entity_type)); + } } return $this->controllers['listing'][$entity_type]; } @@ -161,7 +182,12 @@ public function getListController($entity_type) { public function getFormController($entity_type, $operation) { if (!isset($this->controllers['form'][$operation][$entity_type])) { $class = $this->getControllerClass($entity_type, 'form', $operation); - $this->controllers['form'][$operation][$entity_type] = new $class($operation); + if (in_array('Drupal\Core\Entity\EntityControllerInterface', class_implements($class))) { + $this->controllers['form'][$operation][$entity_type] = $class::createInstance($this->container, $entity_type, $operation); + } + else { + $this->controllers['form'][$operation][$entity_type] = new $class($operation); + } } return $this->controllers['form'][$operation][$entity_type]; } @@ -178,7 +204,12 @@ public function getFormController($entity_type, $operation) { public function getRenderController($entity_type) { if (!isset($this->controllers['render'][$entity_type])) { $class = $this->getControllerClass($entity_type, 'render'); - $this->controllers['render'][$entity_type] = new $class($entity_type); + if (in_array('Drupal\Core\Entity\EntityControllerInterface', class_implements($class))) { + $this->controllers['render'][$entity_type] = $class::createInstance($this->container, $entity_type); + } + else { + $this->controllers['render'][$entity_type] = new $class($entity_type); + } } return $this->controllers['render'][$entity_type]; } @@ -195,7 +226,12 @@ public function getRenderController($entity_type) { public function getAccessController($entity_type) { if (!isset($this->controllers['access'][$entity_type])) { $class = $this->getControllerClass($entity_type, 'access'); - $this->controllers['access'][$entity_type] = new $class($entity_type); + if (in_array('Drupal\Core\Entity\EntityControllerInterface', class_implements($class))) { + $this->controllers['access'][$entity_type] = $class::createInstance($this->container, $entity_type); + } + else { + $this->controllers['access'][$entity_type] = new $class($entity_type); + } } return $this->controllers['access'][$entity_type]; } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php index cf4f6de..b965818 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php @@ -42,21 +42,21 @@ public function getFormID() { * Implements \Drupal\Core\Form\FormInterface::buildForm(). */ public function buildForm(array $form, array &$form_state, $entity_type = NULL, $bundle = NULL, $view_mode = NULL) { - parent::buildForm($form, $form_state, $entity_type, $bundle); + form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin'); $this->view_mode = (isset($view_mode) ? $view_mode : 'default'); // Gather type information. - $instances = field_info_instances($this->entity_type, $this->bundle); + $instances = field_info_instances($this->entityType, $this->bundle); $field_types = field_info_field_types(); - $extra_fields = field_info_extra_fields($this->entity_type, $this->bundle, 'display'); - $entity_display = entity_get_display($this->entity_type, $this->bundle, $this->view_mode); + $extra_fields = field_info_extra_fields($this->entityType, $this->bundle, 'display'); + $entity_display = entity_get_display($this->entityType, $this->bundle, $this->view_mode); $form_state += array( 'formatter_settings_edit' => NULL, ); $form += array( - '#entity_type' => $this->entity_type, + '#entity_type' => $this->entityType, '#bundle' => $this->bundle, '#view_mode' => $this->view_mode, '#fields' => array_keys($instances), @@ -346,7 +346,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, // Custom display settings. if ($this->view_mode == 'default') { - $view_modes = entity_get_view_modes($this->entity_type); + $view_modes = entity_get_view_modes($this->entityType); // Only show the settings if there is more than one view mode. if (count($view_modes) > 1) { $form['modes'] = array( @@ -358,7 +358,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, // checkboxes. $options = array(); $default = array(); - $view_mode_settings = field_view_mode_settings($this->entity_type, $this->bundle); + $view_mode_settings = field_view_mode_settings($this->entityType, $this->bundle); foreach ($view_modes as $view_mode_name => $view_mode_info) { $options[$view_mode_name] = $view_mode_info['label']; if (!empty($view_mode_settings[$view_mode_name]['custom_settings'])) { @@ -414,7 +414,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, */ public function submitForm(array &$form, array &$form_state) { $form_values = $form_state['values']; - $display = entity_get_display($this->entity_type, $this->bundle, $this->view_mode); + $display = entity_get_display($this->entityType, $this->bundle, $this->view_mode); // Collect data for 'regular' fields. foreach ($form['#fields'] as $field_name) { @@ -470,30 +470,30 @@ public function submitForm(array &$form, array &$form_state) { // Handle the 'view modes' checkboxes if present. if ($this->view_mode == 'default' && !empty($form_values['view_modes_custom'])) { - $entity_info = entity_get_info($this->entity_type); - $view_modes = entity_get_view_modes($this->entity_type); - $bundle_settings = field_bundle_settings($this->entity_type, $this->bundle); - $view_mode_settings = field_view_mode_settings($this->entity_type, $this->bundle); + $entity_info = entity_get_info($this->entityType); + $view_modes = entity_get_view_modes($this->entityType); + $bundle_settings = field_bundle_settings($this->entityType, $this->bundle); + $view_mode_settings = field_view_mode_settings($this->entityType, $this->bundle); foreach ($form_values['view_modes_custom'] as $view_mode => $value) { if (!empty($value) && empty($view_mode_settings[$view_mode]['custom_settings'])) { // If no display exists for the newly enabled view mode, initialize // it with those from the 'default' view mode, which were used so // far. - if (!entity_load('entity_display', $this->entity_type . '.' . $this->bundle . '.' . $view_mode)) { - $display = entity_get_display($this->entity_type, $this->bundle, 'default')->createCopy($view_mode); + if (!entity_load('entity_display', $this->entityType . '.' . $this->bundle . '.' . $view_mode)) { + $display = entity_get_display($this->entityType, $this->bundle, 'default')->createCopy($view_mode); $display->save(); } $view_mode_label = $view_modes[$view_mode]['label']; - $path = $this->entityManager->getAdminPath($this->entity_type, $this->bundle) . "/display/$view_mode"; + $path = $this->entityManager->getAdminPath($this->entityType, $this->bundle) . "/display/$view_mode"; drupal_set_message(t('The %view_mode mode now uses custom display settings. You might want to configure them.', array('%view_mode' => $view_mode_label, '@url' => url($path)))); } $bundle_settings['view_modes'][$view_mode]['custom_settings'] = !empty($value); } // Save updated bundle settings. - field_bundle_settings($this->entity_type, $this->bundle, $bundle_settings); + field_bundle_settings($this->entityType, $this->bundle, $bundle_settings); } drupal_set_message(t('Your settings have been saved.')); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php index f02e2eb..80f6834 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -7,6 +7,7 @@ namespace Drupal\field_ui; +use Drupal\Core\Entity\EntityManager; use Drupal\field_ui\OverviewBase; /** @@ -15,6 +16,31 @@ class FieldOverview extends OverviewBase { /** + * The entity storage controller for the field_entity entity type. + * + * @var \Drupal\Core\Entity\EntityStorageControllerInterface + */ + protected $fieldStorageController; + + /** + * The entity storage controller for the field_instance entity type. + * + * @var \Drupal\Core\Entity\EntityStorageControllerInterface + */ + protected $fieldInstanceStorageController; + + /** + * {@inheritdoc} + */ + public function __construct(EntityManager $entity_manager, $entity_type) { + parent::__construct($entity_manager, $entity_type); + + $this->fieldStorageController = $entity_manager->getStorageController('field_entity'); + $this->fieldInstanceStorageController = $entity_manager->getStorageController('field_instance'); + } + + + /** * Implements Drupal\field_ui\OverviewBase::getRegions(). */ public function getRegions() { @@ -42,8 +68,8 @@ public function getFormID() { /** * Implements \Drupal\Core\Form\FormInterface::buildForm(). */ - public function buildForm(array $form, array &$form_state, $entity_type = NULL, $bundle = NULL) { - parent::buildForm($form, $form_state, $entity_type, $bundle); + public function buildForm(array $form, array &$form_state) { + form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin'); $this->view_mode = 'form'; // When displaying the form, make sure the list of fields is up-to-date. @@ -52,13 +78,13 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, } // Gather bundle information. - $instances = field_info_instances($this->entity_type, $this->bundle); + $instances = field_info_instances($this->entityType, $this->bundle); $field_types = field_info_field_types(); $widget_types = field_info_widget_types(); - $extra_fields = field_info_extra_fields($this->entity_type, $this->bundle, 'form'); + $extra_fields = field_info_extra_fields($this->entityType, $this->bundle, 'form'); $form += array( - '#entity_type' => $this->entity_type, + '#entity_type' => $this->entityType, '#bundle' => $this->bundle, '#fields' => array_keys($instances), '#extra' => array_keys($extra_fields), @@ -205,7 +231,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, } // Additional row: add new field. - $max_weight = field_info_max_weight($this->entity_type, $this->bundle, 'form'); + $max_weight = field_info_max_weight($this->entityType, $this->bundle, 'form'); $field_type_options = field_ui_field_type_options(); $widget_type_options = field_ui_widget_type_options(NULL, TRUE); if ($field_type_options && $widget_type_options) { @@ -300,7 +326,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, } // Additional row: re-use existing field. - $existing_fields = field_ui_existing_field_options($this->entity_type, $this->bundle); + $existing_fields = field_ui_existing_field_options($this->entityType, $this->bundle); if ($existing_fields && $widget_type_options) { // Build list of options. $existing_field_options = array(); @@ -522,12 +548,12 @@ protected function validateAddExisting(array $form, array &$form_state) { public function submitForm(array &$form, array &$form_state) { $form_values = $form_state['values']['fields']; - $bundle_settings = field_bundle_settings($this->entity_type, $this->bundle); + $bundle_settings = field_bundle_settings($this->entityType, $this->bundle); // Update field weights. foreach ($form_values as $key => $values) { if (in_array($key, $form['#fields'])) { - $instance = field_read_instance($this->entity_type, $key, $this->bundle); + $instance = field_read_instance($this->entityType, $key, $this->bundle); $instance['widget']['weight'] = $values['weight']; field_update_instance($instance); } @@ -536,7 +562,7 @@ public function submitForm(array &$form, array &$form_state) { } } - field_bundle_settings($this->entity_type, $this->bundle, $bundle_settings); + field_bundle_settings($this->entityType, $this->bundle, $bundle_settings); $destinations = array(); @@ -552,7 +578,7 @@ public function submitForm(array &$form, array &$form_state) { ); $instance = array( 'field_name' => $field['field_name'], - 'entity_type' => $this->entity_type, + 'entity_type' => $this->entityType, 'bundle' => $this->bundle, 'label' => $values['label'], 'widget' => array( @@ -563,14 +589,14 @@ public function submitForm(array &$form, array &$form_state) { // Create the field and instance. try { - $this->entityManager->getStorageController('field_entity')->create($field)->save(); - $new_instance = $this->entityManager->getStorageController('field_instance')->create($instance); + $this->fieldStorageController->create($field)->save(); + $new_instance = $this->fieldInstanceStorageController->create($instance); $new_instance->save(); // Make sure the field is displayed in the 'default' view mode (using // default formatter and settings). It stays hidden for other view // modes until it is explicitly configured. - entity_get_display($this->entity_type, $this->bundle, 'default') + entity_get_display($this->entityType, $this->bundle, 'default') ->setComponent($field['field_name']) ->save(); @@ -597,7 +623,7 @@ public function submitForm(array &$form, array &$form_state) { else { $instance = array( 'field_name' => $field['field_name'], - 'entity_type' => $this->entity_type, + 'entity_type' => $this->entityType, 'bundle' => $this->bundle, 'label' => $values['label'], 'widget' => array( @@ -607,13 +633,13 @@ public function submitForm(array &$form, array &$form_state) { ); try { - $new_instance = $this->entityManager->getStorageController('field_instance')->create($instance); + $new_instance = $this->fieldInstanceStorageController->create($instance); $new_instance->save(); // Make sure the field is displayed in the 'default' view mode (using // default formatter and settings). It stays hidden for other view // modes until it is explicitly configured. - entity_get_display($this->entity_type, $this->bundle, 'default') + entity_get_display($this->entityType, $this->bundle, 'default') ->setComponent($field['field_name']) ->save(); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php b/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php index a8cd891..b92ddcc 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php @@ -22,7 +22,7 @@ * * @var string */ - protected $entity_type = ''; + protected $entityType = ''; /** * The entity bundle. @@ -46,20 +46,30 @@ protected $adminPath = NULL; /** - * The entity manager. + * The entity information for the entity type. * - * @var \Drupal\Core\Entity\EntityManager + * @var \array */ - protected $entityManager; + protected $entityInfo; /** * Constructs a new OverviewBase. * * @param \Drupal\Core\Entity\EntityManager $entity_manager * The entity manager. + * @param string $entity_type + * The entity type used for this overview form. + * @param string $bundle + * The entity bundle used for this overview form. */ - public function __construct(EntityManager $entity_manager) { - $this->entityManager = $entity_manager; + public function __construct(EntityManager $entity_manager, $entity_type, $bundle) { + $this->entityType = $entity_type; + $this->entityInfo = $entity_manager->getDefinition($this->entityType); + if (!empty($this->entityInfo['bundle_prefix'])) { + $bundle = $this->entityInfo['bundle_prefix'] . $bundle; + } + $this->bundle = $bundle; + $this->adminPath = $entity_manager->getAdminPath($this->entityType, $this->bundle); } /** @@ -67,38 +77,19 @@ public function __construct(EntityManager $entity_manager) { */ public static function create(ContainerInterface $container) { return new static( - $container->get('plugin.manager.entity') + $container->get('plugin.manager.entity'), + $container->get('request')->attributes->get('entity_type'), + $container->get('request')->attributes->get('bundle') ); } /** - * {@inheritdoc} - */ - public function buildForm(array $form, array &$form_state, $entity_type = NULL, $bundle = NULL) { - $entity_info = $this->entityManager->getDefinition($entity_type); - if (!empty($entity_info['bundle_prefix'])) { - $bundle = $entity_info['bundle_prefix'] . $bundle; - } - - form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin'); - $this->entity_type = $entity_type; - $this->bundle = $bundle; - $this->adminPath = $this->entityManager->getAdminPath($this->entity_type, $this->bundle); - } - - /** * Implements \Drupal\Core\Form\FormInterface::validateForm(). */ public function validateForm(array &$form, array &$form_state) { } /** - * Implements \Drupal\Core\Form\FormInterface::submitForm(). - */ - public function submitForm(array &$form, array &$form_state) { - } - - /** * Get the regions needed to create the overview form. * * @return array 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 79bd8de..521e1ac 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php @@ -8,11 +8,45 @@ namespace Drupal\menu_link; use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Entity\EntityControllerInterface; +use Drupal\Core\Path\AliasManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the node edit forms. */ -class MenuLinkFormController extends EntityFormController { +class MenuLinkFormController extends EntityFormController implements EntityControllerInterface { + + /** + * The path alias manager. + * + * @var \Drupal\Core\Path\AliasManagerInterface + */ + protected $pathAliasManager; + + /** + * Constructs a new MenuLinkFormController object. + * + * @param string $operation + * The name of the current operation. + * @param \Drupal\Core\Path\AliasManagerInterface $path_alias_manager + * The path alias manager. + */ + public function __construct($operation, AliasManagerInterface $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 +182,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 dd4ffcc..c1526cf 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php @@ -10,6 +10,9 @@ use Drupal\Core\Entity\DatabaseStorageController; 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. @@ -34,10 +37,26 @@ class MenuLinkStorageController extends DatabaseStorageController { protected static $routerItemFields = array(); /** + * The route provider service. + * + * @var \Symfony\Cmf\Component\Routing\RouteProviderInterface + */ + protected $routeProvider; + + /** * Overrides DatabaseStorageController::__construct(). + * + * @param string $entityType + * The entity type for which the instance is created. + * @param \Drupal\Core\Database\Connection $database + * The database connection to be used. + * @param \Symfony\Cmf\Component\Routing\RouteProviderInterface $route_provider + * The route provider service. */ - public function __construct($entityType) { - parent::__construct($entityType); + 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')); @@ -45,6 +64,17 @@ public function __construct($entityType) { } /** + * {@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) { @@ -79,7 +109,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) { // Not all stored routes will be valid on load. if (isset($route_objects[$route])) { @@ -100,7 +130,7 @@ public function save(EntityInterface $entity) { // would be confusing in that situation. $return = SAVED_UPDATED; - $transaction = db_transaction(); + $transaction = $this->database->startTransaction(); try { // Load the stored entity, if any. if (!$entity->isNew() && !isset($entity->original)) { @@ -108,7 +138,7 @@ public function save(EntityInterface $entity) { } if ($entity->isNew()) { - $entity->mlid = db_insert($this->entityInfo['base_table'])->fields(array('menu_name' => 'tools'))->execute(); + $entity->mlid = $this->database->insert($this->entityInfo['base_table'])->fields(array('menu_name' => 'tools'))->execute(); $entity->enforceIsNew(); } @@ -364,7 +394,7 @@ protected function updateParentalStatus(EntityInterface $entity, $exclude = FALS } $parent_has_children = ((bool) $query->execute()) ? 1 : 0; - db_update('menu_links') + $this->database->update('menu_links') ->fields(array('has_children' => $parent_has_children)) ->condition('mlid', $entity->plid) ->execute(); @@ -495,7 +525,7 @@ protected function setParents(EntityInterface $entity, EntityInterface $parent) public function findChildrenRelativeDepth(EntityInterface $entity) { // @todo Since all we need is a specific field from the base table, does it // make sense to convert to EFQ? - $query = db_select('menu_links'); + $query = $this->database->select('menu_links'); $query->addField('menu_links', 'depth'); $query->condition('menu_name', $entity->menu_name); $query->orderBy('depth', 'DESC'); @@ -523,7 +553,7 @@ public function findChildrenRelativeDepth(EntityInterface $entity) { * A menu link entity. */ protected function moveChildren(EntityInterface $entity) { - $query = db_update($this->entityInfo['base_table']); + $query = $this->database->update($this->entityInfo['base_table']); $query->fields(array('menu_name' => $entity->menu_name)); diff --git a/core/modules/user/lib/Drupal/user/UserStorageController.php b/core/modules/user/lib/Drupal/user/UserStorageController.php index 3d8e981..8ee10d9 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,51 @@ 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. + * + * @param string $entityType + * The entity type for which the instance is created. + * @param \Drupal\Core\Database\Connection $database + * The database connection to be used. + * @param \Drupal\Core\Password\PasswordInterface $password + * The password hashing service. + * @param \Drupal\user\UserDataInterface $user_data + * The user data service. + */ + 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 +111,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 +124,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 +147,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 +172,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 +203,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 +221,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_ui/lib/Drupal/views_ui/ViewAddFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewAddFormController.php index 40f0086..1c92682 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewAddFormController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewAddFormController.php @@ -7,14 +7,47 @@ namespace Drupal\views_ui; +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 { + + /** + * The wizard plugin manager. + * + * @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; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type, $operation = NULL) { + return new static( + $operation, + $container->get('plugin.manager.views.wizard') + ); + } /** * {@inheritdoc} @@ -97,7 +130,7 @@ public function form(array $form, array &$form_state) { // 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']; @@ -116,7 +149,7 @@ public function form(array $form, array &$form_state) { // 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; @@ -144,7 +177,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_ui/lib/Drupal/views_ui/ViewEditFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php index ff34a3d..944d301 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php @@ -12,11 +12,57 @@ use Drupal\Core\Ajax\ReplaceCommand; 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; + } + + /** + * {@inheritdoc} + */ + 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::form(). @@ -223,7 +269,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)) { @@ -252,7 +298,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()); } /** @@ -266,7 +312,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->entity; - drupal_container()->get('user.tempstore')->get('views')->delete($view->id()); + $this->tempStore->delete($view->id()); $form_state['redirect'] = 'admin/structure/views'; } @@ -707,7 +753,7 @@ public function renderDisplayTop(ViewUI $view) { * should not yet redirect to the destination. */ public function submitDelayDestination($form, &$form_state) { - $query = \Drupal::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_ui/lib/Drupal/views_ui/ViewPreviewFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php index 3a8adf6..88456b5 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php @@ -10,7 +10,38 @@ /** * 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 +130,7 @@ public function submitPreview($form, &$form_state) { // Rebuild the form with a pristine $view object. $view = $this->entity; // 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;