From 12b09da4bf0d40262f3f5af243a4723b569b7a91 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Fri, 5 Apr 2013 13:32:19 +0100 Subject: [PATCH] Issue #1895266 by damiankloip, dawehner: Convert views to use the ModuleHandler. --- core/modules/field/field.views.inc | 2 +- .../Drupal/views/Plugin/views/HandlerBase.php | 3 +- .../views/display/DisplayPluginBase.php | 2 +- .../views/Plugin/views/display/Page.php | 4 +- .../Drupal/views/Plugin/views/query/Sql.php | 9 +-- .../Plugin/views/wizard/WizardPluginBase.php | 6 +- .../lib/Drupal/views/Tests/UI/TagTest.php | 2 +- .../lib/Drupal/views/Tests/ViewTestData.php | 4 +- .../lib/Drupal/views/Tests/ViewsDataTest.php | 3 +- .../Tests/Wizard/WizardPluginBaseUnitTest.php | 2 + .../views/lib/Drupal/views/ViewExecutable.php | 62 ++++++------------- .../Drupal/views/ViewStorageController.php | 2 +- .../views/lib/Drupal/views/ViewsBundle.php | 1 + .../views/lib/Drupal/views/ViewsDataCache.php | 25 +++++++- core/modules/views/views.module | 25 ++++---- core/modules/views/views.theme.inc | 2 +- .../views_ui/Form/Ajax/ViewsFormBase.php | 4 +- .../Drupal/views_ui/ViewAddFormController.php | 2 +- .../views_ui/ViewEditFormController.php | 6 +- .../views_ui/ViewFormControllerBase.php | 2 +- .../views_ui/lib/Drupal/views_ui/ViewUI.php | 2 +- core/modules/views/views_ui/views_ui.module | 2 +- 22 files changed, 83 insertions(+), 89 deletions(-) diff --git a/core/modules/field/field.views.inc b/core/modules/field/field.views.inc index 6c769cd2526d..d0458896b54b 100644 --- a/core/modules/field/field.views.inc +++ b/core/modules/field/field.views.inc @@ -28,7 +28,7 @@ function field_views_data() { if (empty($result)) { $result = field_views_field_default_views_data($field); } - drupal_alter('field_views_data', $result, $field, $module); + Drupal::moduleHandler()->alter('field_views_data', $result, $field, $module); if (is_array($result)) { $data = NestedArray::mergeDeep($result, $data); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php index a1d357a8437d..4383bd4d8cad 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php @@ -295,7 +295,8 @@ public function buildOptionsForm(&$form, &$form_state) { '#weight' => 150, ); // Allow to alter the default values brought into the form. - drupal_alter('views_handler_options', $this->options, $view); + // @todo Do we really want to keep this hook. + \Drupal::moduleHandler()->alter('views_handler_options', $this->options, $this->view); } /** diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index a252414235c3..5ae99018150d 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -1202,7 +1202,7 @@ public function optionsSummary(&$categories, &$options) { '***DEFAULT_LANGUAGE***' => t("Default site language"), LANGUAGE_NOT_SPECIFIED => t('Language neutral'), ); - if (module_exists('language')) { + if (\Drupal::moduleHandler()->moduleExists('language')) { $languages = array_merge($languages, language_list()); } $options['field_langcode'] = array( diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/Page.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/Page.php index 7f50a40a2220..daf4186daf90 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/Page.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/Page.php @@ -205,7 +205,7 @@ public function buildOptionsForm(&$form, &$form_state) { ); // Only display the menu selector if menu module is enabled. - if (module_exists('menu')) { + if (\Drupal::moduleHandler()->moduleExists('menu')) { $form['menu']['name'] = array( '#title' => t('Menu'), '#type' => 'select', @@ -322,7 +322,7 @@ public function buildOptionsForm(&$form, &$form_state) { ), ); // Only display the menu selector if menu module is enabled. - if (module_exists('menu')) { + if (\Drupal::moduleHandler()->moduleExists('menu')) { $form['tab_options']['name'] = array( '#title' => t('Menu'), '#type' => 'select', diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php b/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php index 6acac7e1cc14..c04bc993a2ba 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php @@ -1379,7 +1379,7 @@ public function query($get_count = FALSE) { } // Add all query substitutions as metadata. - $query->addMetaData('views_substitutions', module_invoke_all('views_query_substitutions', $this)); + $query->addMetaData('views_substitutions', \Drupal::moduleHandler()->invokeAll('views_query_substitutions', array($this->view))); return $query; } @@ -1402,10 +1402,7 @@ function get_where_args() { * Let modules modify the query just prior to finalizing it. */ function alter(ViewExecutable $view) { - foreach (module_implements('views_query_alter') as $module) { - $function = $module . '_views_query_alter'; - $function($view, $this); - } + \Drupal::moduleHandler()->invokeAll('views_query_alter', array($view, $this)); } /** @@ -1455,7 +1452,7 @@ function execute(ViewExecutable $view) { $items = array(); if ($query) { - $additional_arguments = module_invoke_all('views_query_substitutions', $view); + $additional_arguments = \Drupal::moduleHandler()->invokeAll('views_query_substitutions', array($view)); // Count queries must be run through the preExecute() method. // If not, then hook_query_node_access_alter() may munge the count by diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php index 4b2512c5029b..a8099a40636d 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php @@ -290,7 +290,7 @@ function build_form(array $form, array &$form_state) { '#prefix' => '<div id="edit-page-link-properties-wrapper">', '#suffix' => '</div>', ); - if (module_exists('menu')) { + if (\Drupal::moduleHandler()->moduleExists('menu')) { $menu_options = menu_get_menus(); } else { @@ -348,7 +348,7 @@ function build_form(array $form, array &$form_state) { ); } - if (!module_exists('block')) { + if (!\Drupal::moduleHandler()->moduleExists('block')) { return $form; } @@ -555,9 +555,7 @@ protected function row_style_options() { * available). */ protected function build_filters(&$form, &$form_state) { - // Find all the fields we are allowed to filter by. module_load_include('inc', 'views_ui', 'admin'); - $fields = views_fetch_fields($this->base_table, 'filter'); $bundles = entity_get_bundles($this->entity_type); // If the current base table support bundles and has more than one (like user). diff --git a/core/modules/views/lib/Drupal/views/Tests/UI/TagTest.php b/core/modules/views/lib/Drupal/views/Tests/UI/TagTest.php index 99fa8c42c7cf..06138e62e01a 100644 --- a/core/modules/views/lib/Drupal/views/Tests/UI/TagTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/UI/TagTest.php @@ -34,7 +34,7 @@ public static function getInfo() { * Tests the views_ui_autocomplete_tag function. */ public function testViewsUiAutocompleteTag() { - module_load_include('inc', 'views_ui', 'admin'); + \Drupal::moduleHandler()->loadInclude('views_ui', 'inc', 'admin'); // Save 15 views with a tag. $tags = array(); diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewTestData.php b/core/modules/views/lib/Drupal/views/Tests/ViewTestData.php index 232a847153d5..cf2c0d8df3ee 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewTestData.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewTestData.php @@ -45,9 +45,11 @@ public static function importTestViews($class, $modules = array()) { 'create' => array(), 'change' => array(), ); + + $module_handler = \Drupal::moduleHandler(); foreach ($modules as $module) { $config_dir = drupal_get_path('module', $module) . '/test_views'; - if (!is_dir($config_dir) || !module_exists($module)) { + if (!is_dir($config_dir) || !$module_handler->moduleExists($module)) { continue; } diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewsDataTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewsDataTest.php index 3357008b7888..af9859892150 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewsDataTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewsDataTest.php @@ -170,7 +170,8 @@ protected function viewsData() { * Tests the views_fetch_fields function(). */ public function testViewsFetchFields() { - module_load_include('inc', 'views_ui', 'admin'); + $this->enableModules(array('views_ui')); + $this->container->get('module_handler')->loadInclude('views_ui', 'inc', 'admin'); $expected = array( 'field' => array( diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/WizardPluginBaseUnitTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/WizardPluginBaseUnitTest.php index 7cac36bbe57d..529d4f13d18f 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/WizardPluginBaseUnitTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/WizardPluginBaseUnitTest.php @@ -46,6 +46,8 @@ protected function setUp() { $this->installSchema('language', 'language'); $this->installSchema('system', 'variable'); + $this->enableModules(array('views_ui')); + $this->wizard = $this->container->get('plugin.manager.views.wizard')->createInstance('standard:views_test_data', array()); } diff --git a/core/modules/views/lib/Drupal/views/ViewExecutable.php b/core/modules/views/lib/Drupal/views/ViewExecutable.php index aa39dae1bc6b..faa7493411bf 100644 --- a/core/modules/views/lib/Drupal/views/ViewExecutable.php +++ b/core/modules/views/lib/Drupal/views/ViewExecutable.php @@ -987,10 +987,8 @@ public function build($display_id = NULL) { } // Let modules modify the view just prior to building it. - foreach (module_implements('views_pre_build') as $module) { - $function = $module . '_views_pre_build'; - $function($this); - } + $module_handler = \Drupal::moduleHandler(); + $module_handler->invokeAll('views_pre_build', array($this)); // Attempt to load from cache. // @todo Load a build_info from cache. @@ -1111,10 +1109,7 @@ public function build($display_id = NULL) { $this->attachDisplays(); // Let modules modify the view just after building it. - foreach (module_implements('views_post_build') as $module) { - $function = $module . '_views_post_build'; - $function($this); - } + $module_handler->invokeAll('views_post_build', array($this)); return TRUE; } @@ -1189,10 +1184,8 @@ public function execute($display_id = NULL) { } // Let modules modify the view just prior to executing it. - foreach (module_implements('views_pre_execute') as $module) { - $function = $module . '_views_pre_execute'; - $function($this); - } + $module_handler = \Drupal::moduleHandler(); + $module_handler->invokeAll('views_pre_execute', array($this)); // Check for already-cached results. if (!empty($this->live_preview)) { @@ -1217,10 +1210,7 @@ public function execute($display_id = NULL) { } // Let modules modify the view just after executing it. - foreach (module_implements('views_post_execute') as $module) { - $function = $module . '_views_post_execute'; - $function($this); - } + $module_handler->invokeAll('views_post_execute', array($this)); $this->executed = TRUE; } @@ -1254,6 +1244,8 @@ public function render($display_id = NULL) { $exposed_form = $this->display_handler->getPlugin('exposed_form'); $exposed_form->pre_render($this->result); + $module_handler = \Drupal::moduleHandler(); + // Check for already-cached output. if (!empty($this->live_preview)) { $cache = FALSE; @@ -1261,6 +1253,7 @@ public function render($display_id = NULL) { else { $cache = $this->display_handler->getPlugin('cache'); } + if ($cache && $cache->cache_get('output')) { } else { @@ -1301,23 +1294,15 @@ public function render($display_id = NULL) { } // Let modules modify the view just prior to rendering it. - foreach (module_implements('views_pre_render') as $module) { - $function = $module . '_views_pre_render'; - $function($this); - } + $module_handler->invokeAll('views_pre_render', array($this)); // Let the themes play too, because pre render is a very themey thing. foreach ($GLOBALS['base_theme_info'] as $base) { - $function = $base->name . '_views_pre_render'; - if (function_exists($function)) { - $function($this); - } - } - $function = $GLOBALS['theme'] . '_views_pre_render'; - if (function_exists($function)) { - $function($this); + $module_handler->invoke($base, 'views_pre_render', array($this)); } + $module_handler->invoke($GLOBALS['theme'], 'views_pre_render', array($this)); + $this->display_handler->output = $this->display_handler->render(); if ($cache) { $cache->cache_set('output'); @@ -1331,23 +1316,15 @@ public function render($display_id = NULL) { } // Let modules modify the view output after it is rendered. - foreach (module_implements('views_post_render') as $module) { - $function = $module . '_views_post_render'; - $function($this, $this->display_handler->output, $cache); - } + $module_handler->invokeAll('views_post_render', array($this, $this->display_handler->output, $cache)); // Let the themes play too, because post render is a very themey thing. foreach ($GLOBALS['base_theme_info'] as $base) { - $function = $base->name . '_views_post_render'; - if (function_exists($function)) { - $function($this); - } - } - $function = $GLOBALS['theme'] . '_views_post_render'; - if (function_exists($function)) { - $function($this, $this->display_handler->output, $cache); + $module_handler->invoke($base, 'views_post_render', array($this)); } + $module_handler->invoke($GLOBALS['theme'], 'views_post_render', array($this)); + return $this->display_handler->output; } @@ -1423,10 +1400,7 @@ public function preExecute($args = array()) { } // Let modules modify the view just prior to executing it. - foreach (module_implements('views_pre_view') as $module) { - $function = $module . '_views_pre_view'; - $function($this, $display_id, $this->args); - } + \Drupal::moduleHandler()->invokeAll('views_pre_view', array($this, $display_id, $this->args)); // Allow hook_views_pre_view() to set the dom_id, then ensure it is set. $this->dom_id = !empty($this->dom_id) ? $this->dom_id : hash('sha256', $this->storage->id() . REQUEST_TIME . mt_rand()); diff --git a/core/modules/views/lib/Drupal/views/ViewStorageController.php b/core/modules/views/lib/Drupal/views/ViewStorageController.php index f53b5f40315f..3ac6731a7c96 100644 --- a/core/modules/views/lib/Drupal/views/ViewStorageController.php +++ b/core/modules/views/lib/Drupal/views/ViewStorageController.php @@ -23,7 +23,7 @@ public function load(array $ids = NULL) { // Only return views for enabled modules. return array_filter($entities, function ($entity) { - if (module_exists($entity->get('module'))) { + if (\Drupal::moduleHandler()->moduleExists($entity->get('module'))) { return TRUE; } return FALSE; diff --git a/core/modules/views/lib/Drupal/views/ViewsBundle.php b/core/modules/views/lib/Drupal/views/ViewsBundle.php index 649fd7dbac22..c33e4b05029a 100644 --- a/core/modules/views/lib/Drupal/views/ViewsBundle.php +++ b/core/modules/views/lib/Drupal/views/ViewsBundle.php @@ -31,6 +31,7 @@ public function build(ContainerBuilder $container) { $container->register('views.views_data', 'Drupal\views\ViewsDataCache') ->addArgument(new Reference('cache.views_info')) ->addArgument(new Reference('config.factory')) + ->addArgument(new Reference('module_handler')) ->addTag('needs_destruction'); $container->register('views.executable', 'Drupal\views\ViewExecutableFactory'); diff --git a/core/modules/views/lib/Drupal/views/ViewsDataCache.php b/core/modules/views/lib/Drupal/views/ViewsDataCache.php index 861d28768b46..bc5bd0257be3 100644 --- a/core/modules/views/lib/Drupal/views/ViewsDataCache.php +++ b/core/modules/views/lib/Drupal/views/ViewsDataCache.php @@ -9,6 +9,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\DestructableInterface; /** @@ -73,8 +74,26 @@ class ViewsDataCache implements DestructableInterface { */ protected $langcode; - public function __construct(CacheBackendInterface $cache_backend, ConfigFactory $config) { + /** + * Stores a module manager to invoke hooks. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** + * Constructs this ViewsDataCache object. + * + * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend + * The cache backend to use. + * @param \Drupal\Core\Config\ConfigFactory $config + * The configuration factory object to use. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler class to use for invoking hooks. + */ + public function __construct(CacheBackendInterface $cache_backend, ConfigFactory $config, ModuleHandlerInterface $module_handler) { $this->cacheBackend = $cache_backend; + $this->moduleHandler = $module_handler; $this->langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode; $this->skipCache = $config->get('views.settings')->get('skip_cache'); @@ -176,8 +195,8 @@ protected function getData() { return $data->data; } else { - $data = module_invoke_all('views_data'); - drupal_alter('views_data', $data); + $data = $this->moduleHandler->invokeAll('views_data'); + $this->moduleHandler->alter('views_data', $data); $this->processEntityTypes($data); diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 99e000c957b0..cd313c6c80ef 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -79,7 +79,7 @@ function views_pre_render_view_element($element) { * Implement hook_theme(). Register views theming functions. */ function views_theme($existing, $type, $theme, $path) { - module_load_include('inc', 'views', 'views.theme'); + Drupal::moduleHandler()->loadInclude('views', 'inc', 'views.theme'); // Some quasi clever array merging here. $base = array( @@ -687,13 +687,15 @@ function views_invalidate_cache() { // Set the menu as needed to be rebuilt. state()->set('menu_rebuild_needed', TRUE); + $module_handler = Drupal::moduleHandler(); + // Invalidate the block cache to update views block derivatives. - if (module_exists('block')) { - drupal_container()->get('plugin.manager.block')->clearCachedDefinitions(); + if ($module_handler->moduleExists('block')) { + Drupal::service('plugin.manager.block')->clearCachedDefinitions(); } // Allow modules to respond to the Views cache being cleared. - module_invoke_all('views_invalidate_cache'); + $module_handler->invokeAll('views_invalidate_cache'); } /** @@ -955,7 +957,7 @@ function views_fetch_plugin_names($type, $key = NULL, $base = array()) { } // @todo While Views is providing on behalf of core modules, check to see // if they are enabled or not. - if (isset($plugin['module']) && !module_exists($plugin['module'])) { + if (isset($plugin['module']) && !\Drupal::moduleHandler()->moduleExists($plugin['module'])) { continue; } @@ -980,10 +982,9 @@ function views_fetch_plugin_names($type, $key = NULL, $base = array()) { * An array of plugin definitions for all types. */ function views_get_plugin_definitions() { - $container = drupal_container(); $plugins = array(); foreach (ViewExecutable::getPluginTypes() as $plugin_type) { - $plugins[$plugin_type] = $container->get("plugin.manager.views.$plugin_type")->getDefinitions(); + $plugins[$plugin_type] = Views::pluginManager($plugin_type)->getDefinitions(); } return $plugins; @@ -1015,10 +1016,8 @@ function views_get_enabled_display_extenders() { * @endcode */ function views_get_applicable_views($type) { - $container = drupal_container(); - // Get all display plugins which provides the type. - $display_plugins = $container->get('plugin.manager.views.display')->getDefinitions(); + $display_plugins = Views::pluginManager('display')->getDefinitions(); $ids = array(); foreach ($display_plugins as $id => $definition) { if (!empty($definition[$type])) { @@ -1026,13 +1025,13 @@ function views_get_applicable_views($type) { } } - $entity_ids = $container->get('entity.query')->get('view') + $entity_ids = Drupal::service('entity.query')->get('view') ->condition('status', TRUE) ->condition("display.*.display_plugin", $ids, 'IN') ->execute(); $result = array(); - foreach ($container->get('plugin.manager.entity')->getStorageController('view')->load($entity_ids) as $view) { + foreach (Drupal::service('plugin.manager.entity')->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(); @@ -1560,7 +1559,7 @@ function views_exposed_form_cache($views_name, $display_name, $form_output = NUL * Build a list of theme function names for use most everywhere. */ function views_theme_functions($hook, ViewExecutable $view, $display = NULL) { - module_load_include('inc', 'views', 'views.theme'); + Drupal::moduleHandler()->loadInclude('views', 'inc', 'views.theme'); return _views_theme_functions($hook, $view, $display); } diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 44f48f6eb1fa..0bae0fc39ca5 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -1023,7 +1023,7 @@ function theme_views_form_views_form($variables) { $replace[] = isset($form[$field_name][$row_id]) ? drupal_render($form[$field_name][$row_id]) : ''; } // Add in substitutions from hook_views_form_substitutions(). - $substitutions = module_invoke_all('views_form_substitutions'); + $substitutions = Drupal::moduleHandler()->invokeAll('views_form_substitutions'); foreach ($substitutions as $placeholder => $substitution) { $search[] = $placeholder; $replace[] = $substitution; diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/Ajax/ViewsFormBase.php b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/Ajax/ViewsFormBase.php index b5ce81c378fa..aa4fe25d8d1d 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/Ajax/ViewsFormBase.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/Ajax/ViewsFormBase.php @@ -87,8 +87,8 @@ public function getForm(ViewStorageInterface $view, $display_id, $js) { $key = $form_state['form_key']; // @todo Remove the need for this. - module_load_include('inc', 'views_ui', 'admin'); - module_load_include('inc', 'views', 'includes/ajax'); + \Drupal::moduleHandler()->loadInclude('views_ui', 'inc', 'admin'); + \Drupal::moduleHandler()->loadInclude('views', 'inc', 'includes/ajax'); // Reset the cache of IDs. Drupal rather aggressively prevents ID // duplication but this causes it to remember IDs that are no longer even 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 5813b2348f09..474c1e1427aa 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 @@ -100,7 +100,7 @@ public function form(array $form, array &$form_state, EntityInterface $view) { '#options' => $options, ); $show_form = &$form['displays']['show']; - $default_value = module_exists('node') ? 'node' : 'users'; + $default_value = \Drupal::moduleHandler()->moduleExists('node') ? 'node' : 'users'; $show_form['wizard_key']['#default_value'] = WizardPluginBase::getSelected($form_state, array('show', 'wizard_key'), $default_value, $show_form['wizard_key']); // Changing this dropdown updates the entire content of $form['displays'] via // AJAX. 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 6808184d37e5..a660b0d2b223 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 @@ -326,7 +326,7 @@ public function getDisplayTab($view) { } // In AJAX context, ViewUI::rebuildCurrentTab() returns this outside of form // context, so hook_form_views_ui_edit_form_alter() is insufficient. - drupal_alter('views_ui_display_tab', $build, $view, $display_id); + \Drupal::moduleHandler()->alter('views_ui_display_tab', $build, $view, $display_id); return $build; } @@ -667,7 +667,7 @@ public function renderDisplayTop(ViewUI $view) { ); // Let other modules add additional links here. - drupal_alter('views_ui_display_top_links', $element['extra_actions']['#links'], $view, $display_id); + \Drupal::moduleHandler()->alter('views_ui_display_top_links', $element['extra_actions']['#links'], $view, $display_id); if (isset($view->type) && $view->type != t('Default')) { if ($view->type == t('Overridden')) { @@ -724,7 +724,7 @@ public function renderDisplayTop(ViewUI $view) { * should not yet redirect to the destination. */ public function submitDelayDestination($form, &$form_state) { - $query = drupal_container()->get('request')->query; + $query = \Drupal::service('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/ViewFormControllerBase.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php index 17db2ecf27da..3269124085bb 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php @@ -82,7 +82,7 @@ public static function getAdminCSS() { $list[$module_path . '/css/views-admin.css'] = array(); $list[$module_path . '/css/views-admin.theme.css'] = array(); - if (module_exists('contextual')) { + if (\Drupal::moduleHandler()->moduleExists('contextual')) { $list[$module_path . '/css/views-admin.contextual.css'] = array(); } diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php index e0b56a886bb9..fe49e411c593 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -651,7 +651,7 @@ public function renderPreview($display_id, $args = array()) { $rows['statistics'][] = array('<strong>' . t('View render time') . '</strong>', t('@time ms', array('@time' => intval($this->executable->render_time * 100000) / 100))); } - drupal_alter('views_preview_info', $rows, $this); + \Drupal::moduleHandler()->alter('views_preview_info', $rows, $this); } else { // No query was run. Display that information in place of either the diff --git a/core/modules/views/views_ui/views_ui.module b/core/modules/views/views_ui/views_ui.module index fca8a80987dc..8434656a9bf4 100644 --- a/core/modules/views/views_ui/views_ui.module +++ b/core/modules/views/views_ui/views_ui.module @@ -246,7 +246,7 @@ function views_ui_cache_set(ViewUI $view) { */ function views_ui_preprocess_views_view(&$vars) { $view = $vars['view']; - if (!empty($view->live_preview) && module_exists('contextual')) { + if (!empty($view->live_preview) && Drupal::moduleHandler()->moduleExists('contextual')) { $view->hide_admin_links = TRUE; foreach (array('title', 'header', 'exposed', 'rows', 'pager', 'more', 'footer', 'empty', 'attachment_after', 'attachment_before') as $section) { if (!empty($vars[$section])) { -- GitLab