Commit 78e5e9bf authored by alexpott's avatar alexpott

Issue #2045927 by herom, martin107, ianthomas_uk, Xano, michaellander,...

Issue #2045927 by herom, martin107, ianthomas_uk, Xano, michaellander, Sutharsan: Replace all drupal_alter() deprecated function calls.
parent 966c3302
......@@ -251,7 +251,7 @@ function ajax_render($commands = array()) {
else {
$function = '_drupal_add_' . $type;
$items[$type] = $function();
drupal_alter($type, $items[$type]);
\Drupal::moduleHandler()->alter($type, $items[$type]);
// @todo Inline CSS and JS items are indexed numerically. These can't be
// reliably diffed with array_diff_key(), since the number can change
// due to factors unrelated to the inline content, so for now, we strip
......@@ -301,7 +301,7 @@ function ajax_render($commands = array()) {
}
// Allow modules to alter any Ajax response.
drupal_alter('ajax_render', $commands);
\Drupal::moduleHandler()->alter('ajax_render', $commands);
return Json::encode($commands);
}
......
......@@ -1896,13 +1896,13 @@ function module_invoke($module, $hook) {
/**
* Invokes a hook in all enabled modules that implement it.
*
* All arguments are passed by value. Use drupal_alter() if you need to pass
* arguments by reference.
* All arguments are passed by value. Use \Drupal::moduleHandler()->alter() if
* you need to pass arguments by reference.
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal::moduleHandler()->invokeAll($hook).
*
* @see drupal_alter()
* @see \Drupal\Core\Extension\ModuleHandler::alter()
* @see \Drupal\Core\Extension\ModuleHandler::invokeAll()
*/
function module_invoke_all($hook) {
......
......@@ -358,7 +358,7 @@ function _drupal_default_html_head() {
*/
function drupal_get_html_head() {
$elements = drupal_add_html_head();
drupal_alter('html_head', $elements);
\Drupal::moduleHandler()->alter('html_head', $elements);
return drupal_render($elements);
}
......@@ -1621,9 +1621,9 @@ function _drupal_add_css($data = NULL, $options = NULL) {
* (optional) An array of CSS files. If no array is provided, the default
* stylesheets array is used instead.
* @param $skip_alter
* (optional) If set to TRUE, this function skips calling drupal_alter() on
* $css, useful when the calling function passes a $css array that has already
* been altered.
* (optional) If set to TRUE, this function skips calling
* \Drupal::moduleHandler->alter() on $css, useful when the calling function
* passes a $css array that has already been altered.
*
* @return
* A string of XHTML CSS tags.
......@@ -1639,7 +1639,7 @@ function drupal_get_css($css = NULL, $skip_alter = FALSE) {
// Allow modules and themes to alter the CSS items.
if (!$skip_alter) {
drupal_alter('css', $css);
\Drupal::moduleHandler()->alter('css', $css);
}
// Sort CSS items, so that they appear in the correct order.
......@@ -2252,9 +2252,9 @@ function drupal_js_defaults($data = NULL) {
* (optional) An array with all JavaScript code. Defaults to the default
* JavaScript array for the given scope.
* @param bool $skip_alter
* (optional) If set to TRUE, this function skips calling drupal_alter() on
* $javascript, useful when the calling function passes a $javascript array
* that has already been altered.
* (optional) If set to TRUE, this function skips calling
* \Drupal::moduleHandler->alter() on $javascript, useful when the calling
* function passes a $javascript array that has already been altered.
* @param bool $is_ajax
* (optional) If set to TRUE, this function is called from an Ajax request and
* adds javascript settings to update ajaxPageState values.
......@@ -2276,7 +2276,7 @@ function drupal_get_js($scope = 'header', $javascript = NULL, $skip_alter = FALS
// Allow modules to alter the JavaScript.
if (!$skip_alter) {
drupal_alter('js', $javascript);
\Drupal::moduleHandler()->alter('js', $javascript);
}
// Filter out elements of the given scope.
......@@ -2722,7 +2722,7 @@ function drupal_add_library($module, $name, $every_page = NULL) {
if ($library = drupal_get_library($module, $name)) {
// Allow modules and themes to dynamically attach request and context
// specific data for this library; e.g., localization.
drupal_alter('library', $library, $module, $name);
\Drupal::moduleHandler()->alter('library', $library, $module, $name);
// Add all components within the library.
$elements['#attached'] = array(
......@@ -2816,7 +2816,7 @@ function drupal_get_library($extension, $name = NULL) {
throw new \RuntimeException(sprintf('Invalid library definition in %s: %s', $library_file, $e->getMessage()), 0, $e);
}
// Allow modules to alter the module's registered libraries.
drupal_alter('library_info', $libraries[$extension], $extension);
\Drupal::moduleHandler()->alter('library_info', $libraries[$extension], $extension);
}
foreach ($libraries[$extension] as $id => &$library) {
......@@ -3705,7 +3705,7 @@ function drupal_prepare_page($page) {
}
// Modules alter the $page as needed. Blocks are populated into regions like
// 'sidebar_first', 'footer', etc.
drupal_alter('page', $page);
\Drupal::moduleHandler()->alter('page', $page);
// The "main" and "secondary" menus are never part of the page-level render
// array and therefore their cache tags will never bubble up into the page
......@@ -4713,7 +4713,7 @@ function element_info($type) {
$cache[$element_type]['#type'] = $element_type;
}
// Allow modules to alter the element type defaults.
drupal_alter('element_info', $cache);
\Drupal::moduleHandler()->alter('element_info', $cache);
}
return isset($cache[$type]) ? $cache[$type] : array();
......@@ -5154,7 +5154,7 @@ function drupal_get_updaters() {
$updaters = &drupal_static(__FUNCTION__);
if (!isset($updaters)) {
$updaters = \Drupal::moduleHandler()->invokeAll('updater_info');
drupal_alter('updater_info', $updaters);
\Drupal::moduleHandler()->alter('updater_info', $updaters);
uasort($updaters, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
}
return $updaters;
......@@ -5174,7 +5174,7 @@ function drupal_get_filetransfer_info() {
$info = &drupal_static(__FUNCTION__);
if (!isset($info)) {
$info = \Drupal::moduleHandler()->invokeAll('filetransfer_info');
drupal_alter('filetransfer_info', $info);
\Drupal::moduleHandler()->alter('filetransfer_info', $info);
uasort($info, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
}
return $info;
......
......@@ -103,7 +103,7 @@ function entity_get_form_modes($entity_type = NULL) {
list($form_mode_entity_type, $form_mode_name) = explode('.', $form_mode->id(), 2);
$form_modes[$form_mode_entity_type][$form_mode_name] = (array) $form_mode;
}
drupal_alter('entity_form_mode_info', $form_modes);
\Drupal::moduleHandler()->alter('entity_form_mode_info', $form_modes);
\Drupal::cache()->set("entity_form_mode_info:$langcode", $form_modes, Cache::PERMANENT, array('entity_types' => TRUE));
}
}
......@@ -141,7 +141,7 @@ function entity_get_view_modes($entity_type = NULL) {
list($view_mode_entity_type, $view_mode_name) = explode('.', $view_mode->id(), 2);
$view_modes[$view_mode_entity_type][$view_mode_name] = (array) $view_mode;
}
drupal_alter('entity_view_mode_info', $view_modes);
\Drupal::moduleHandler()->alter('entity_view_mode_info', $view_modes);
\Drupal::cache()->set("entity_view_mode_info:$langcode", $view_modes, Cache::PERMANENT, array('entity_types' => TRUE));
}
}
......
......@@ -448,7 +448,7 @@ function file_stream_wrapper_get_instance_by_scheme($scheme) {
function file_create_url($uri) {
// Allow the URI to be altered, e.g. to serve a file from a CDN or static
// file server.
drupal_alter('file_url', $uri);
\Drupal::moduleHandler()->alter('file_url', $uri);
$scheme = file_uri_scheme($uri);
......
......@@ -20,7 +20,7 @@ function file_mimetype_mapping() {
if (!isset($mapping)) {
$mapping = file_default_mimetype_mapping();
// Allow modules to alter the default mapping.
drupal_alter('file_mimetype_mapping', $mapping);
\Drupal::moduleHandler()->alter('file_mimetype_mapping', $mapping);
}
return $mapping;
}
......
......@@ -3257,7 +3257,7 @@ function batch_process($redirect = NULL, $url = 'batch', $redirect_callback = NU
// The batch is now completely built. Allow other modules to make changes
// to the batch so that it is easier to reuse batch processes in other
// environments.
drupal_alter('batch', $batch);
\Drupal::moduleHandler()->alter('batch', $batch);
// Assign an arbitrary id: don't rely on a serial column in the 'batch'
// table, since non-progressive batches skip database storage completely.
......
......@@ -162,7 +162,7 @@ function drupal_mail($module, $key, $to, $langcode, $params = array(), $reply =
}
// Invoke hook_mail_alter() to allow all modules to alter the resulting e-mail.
drupal_alter('mail', $message);
\Drupal::moduleHandler()->alter('mail', $message);
// Retrieve the responsible implementation for this message.
$system = drupal_mail_system($module, $key);
......
......@@ -485,7 +485,7 @@ function menu_get_item($path = NULL, $router_item = NULL) {
if ($router_item) {
// Allow modules to alter the router item before it is translated and
// checked for access.
drupal_alter('menu_get_item', $router_item, $path, $original_map);
\Drupal::moduleHandler()->alter('menu_get_item', $router_item, $path, $original_map);
$map = _menu_translate($router_item, $original_map);
$router_item['original_map'] = $original_map;
......@@ -903,7 +903,7 @@ function _menu_link_translate(&$item) {
// options array. For performance reasons we only invoke this hook if the link
// has the 'alter' flag set in the options array.
if (!empty($item['options']['alter'])) {
drupal_alter('translated_menu_link', $item, $map);
\Drupal::moduleHandler()->alter('translated_menu_link', $item, $map);
}
}
......@@ -2451,7 +2451,7 @@ function menu_router_build($save = FALSE) {
}
}
// Alter the menu as defined in modules, keys are like user/%user.
drupal_alter('menu', $callbacks);
\Drupal::moduleHandler()->alter('menu', $callbacks);
\Drupal::configFactory()->setOverrideState($old_state);
foreach ($callbacks as $path => $router_item) {
// If the menu item is a default local task and incorrectly references a
......
......@@ -116,8 +116,9 @@ function system_list_reset() {
// Clear the library info cache.
// Libraries may be provided by all extension types, and may be altered by any
// other extensions (types) due to the nature of drupal_alter() and the fact
// that profiles are recorded and handled as modules.
// other extensions (types) due to the nature of
// \Drupal\Core\Extension\ModuleHandler::alter() and the fact that profiles
// are recorded and handled as modules.
Cache::invalidateTags(array('extension' => TRUE));
// Remove last known theme data state.
......
......@@ -160,7 +160,7 @@ function path_get_admin_paths() {
$patterns = &drupal_static(__FUNCTION__);
if (!isset($patterns)) {
$paths = \Drupal::moduleHandler()->invokeAll('admin_paths');
drupal_alter('admin_paths', $paths);
\Drupal::moduleHandler()->alter('admin_paths', $paths);
// Combine all admin paths into one array, and likewise for non-admin paths,
// for easier handling.
$patterns = array();
......
......@@ -86,7 +86,7 @@ function drupal_get_complete_schema($rebuild = FALSE) {
_drupal_schema_initialize($current, $module);
$schema = array_merge($schema, $current);
}
drupal_alter('schema', $schema);
\Drupal::moduleHandler()->alter('schema', $schema);
if ($rebuild) {
Cache::deleteTags(array('schema' => TRUE));
......
......@@ -2031,7 +2031,7 @@ function _template_preprocess_default_variables() {
}
// Give modules a chance to alter the default template variables.
drupal_alter('template_preprocess_default_variables', $variables);
\Drupal::moduleHandler()->alter('template_preprocess_default_variables', $variables);
return $variables;
}
......
......@@ -75,9 +75,10 @@ function _drupal_maintenance_theme() {
$themes = list_themes();
// list_themes() triggers a drupal_alter() in maintenance mode, but we can't
// let themes alter the .info.yml data until we know a theme's base themes. So
// don't set global $theme until after list_themes() builds its cache.
// list_themes() triggers a \Drupal\Core\Extension\ModuleHandler::alter() in
// maintenance mode, but we can't let themes alter the .info.yml data until
// we know a theme's base themes. So don't set global $theme until after
// list_themes() builds its cache.
$theme = $custom_theme;
// Store the identifier for retrieving theme settings with.
......
......@@ -106,7 +106,7 @@ protected function ajaxRender(Request $request) {
else {
$function = '_drupal_add_' . $type;
$items[$type] = $function();
drupal_alter($type, $items[$type]);
\Drupal::moduleHandler()->alter($type, $items[$type]);
// @todo Inline CSS and JS items are indexed numerically. These can't be
// reliably diffed with array_diff_key(), since the number can change
// due to factors unrelated to the inline content, so for now, we
......@@ -166,7 +166,7 @@ protected function ajaxRender(Request $request) {
}
$commands = $this->commands;
drupal_alter('ajax_render', $commands);
\Drupal::moduleHandler()->alter('ajax_render', $commands);
return $commands;
}
......
......@@ -391,7 +391,7 @@ public function preExecute(SelectInterface $query = NULL) {
foreach ($this->alterTags as $tag => $value) {
$hooks[] = 'query_' . $tag;
}
drupal_alter($hooks, $query);
\Drupal::moduleHandler()->alter($hooks, $query);
}
$this->prepared = TRUE;
......
......@@ -209,7 +209,7 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
// Allow modules to change the view mode.
$entity_view_mode = $view_mode;
drupal_alter('entity_view_mode', $entity_view_mode, $entity, $context);
$this->moduleHandler->alter('entity_view_mode', $entity_view_mode, $entity, $context);
// Store entities for rendering by view_mode.
$view_modes[$entity_view_mode][$entity->id()] = $entity;
}
......@@ -248,7 +248,7 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
$build[$key]['#weight'] = $weight++;
// Allow modules to modify the render array.
drupal_alter(array($view_hook, 'entity_view'), $build[$key], $entity, $display);
$this->moduleHandler->alter(array($view_hook, 'entity_view'), $build[$key], $entity, $display);
}
return $build;
......
......@@ -261,7 +261,7 @@ protected function formSingleElement(FieldItemListInterface $items, $delta, arra
'delta' => $delta,
'default' => !empty($entity->field_ui_default_value),
);
drupal_alter(array('field_widget_form', 'field_widget_' . $this->getPluginId() . '_form'), $element, $form_state, $context);
\Drupal::moduleHandler()->alter(array('field_widget_form', 'field_widget_' . $this->getPluginId() . '_form'), $element, $form_state, $context);
}
return $element;
......
......@@ -27,7 +27,7 @@ protected function readLanguageOverrides($langcode) {
parent::readLanguageOverrides($langcode);
// Let modules alter the language-specific overrides.
drupal_alter('transliteration_overrides', $this->languageOverrides[$langcode], $langcode);
\Drupal::moduleHandler()->alter('transliteration_overrides', $this->languageOverrides[$langcode], $langcode);
}
}
......@@ -405,7 +405,7 @@ public function buildContentsCssJSSetting(EditorEntity $editor) {
drupal_get_path('module', 'ckeditor') . '/css/ckeditor-iframe.css',
drupal_get_path('module', 'system') . '/css/system.module.css',
);
drupal_alter('ckeditor_css', $css, $editor);
$this->moduleHandler->alter('ckeditor_css', $css, $editor);
$css = array_merge($css, _ckeditor_theme_css());
$css = array_map('file_create_url', $css);
......
......@@ -222,7 +222,7 @@ function contextual_pre_render_links($element) {
$element['#links'] = $links;
// Allow modules to alter the renderable contextual links element.
drupal_alter('contextual_links_view', $element, $items);
\Drupal::moduleHandler()->alter('contextual_links_view', $element, $items);
// If there are no links, tell drupal_render() to abort rendering.
if (empty($element['#links'])) {
......
......@@ -73,7 +73,7 @@ public function __construct(array $values, $entity_type) {
// Initialize settings, merging module-provided defaults.
$default_settings = $plugin->getDefaultSettings();
$default_settings += \Drupal::moduleHandler()->invokeAll('editor_default_settings', array($this->editor));
drupal_alter('editor_default_settings', $default_settings, $this->editor);
\Drupal::moduleHandler()->alter('editor_default_settings', $default_settings, $this->editor);
$this->settings += $default_settings;
}
......
......@@ -88,7 +88,7 @@ public function getAttachments(array $format_ids) {
}
// Allow other modules to alter all JavaScript settings.
drupal_alter('editor_js_settings', $settings);
$this->moduleHandler->alter('editor_js_settings', $settings);
if (empty($attachments['library']) && empty($settings)) {
return array();
......
......@@ -309,7 +309,7 @@ protected function reAlterQuery(AlterableInterface $query, $tag, $base_table) {
$query->alterTags = array($tag => TRUE);
$query->alterMetaData['base_table'] = $base_table;
drupal_alter(array('query', 'query_' . $tag), $query);
\Drupal::moduleHandler()->alter(array('query', 'query_' . $tag), $query);
// Restore the tags and metadata.
$query->alterTags = $old_tags;
......
......@@ -42,8 +42,8 @@ function field_views_data() {
*
* Field modules can implement hook_field_views_data_views_data_alter() to
* alter the views data on a per field basis. This is weirdly named so as
* not to conflict with the drupal_alter('field_views_data') in
* field_views_data.
* not to conflict with the \Drupal::moduleHandler()->alter('field_views_data')
* in field_views_data.
*/
function field_views_data_alter(&$data) {
foreach (field_info_fields() as $field) {
......
......@@ -537,7 +537,7 @@ public function getBundleExtraFields($entity_type, $bundle) {
// shape of the hook, we have no other way than collecting extra fields on
// all bundles.
$extra = $this->moduleHandler->invokeAll('field_extra_fields');
drupal_alter('field_extra_fields', $extra);
$this->moduleHandler->alter('field_extra_fields', $extra);
$info = isset($extra[$entity_type][$bundle]) ? $extra[$entity_type][$bundle] : array();
$info += array('form' => array(), 'display' => array());
......
......@@ -7,8 +7,12 @@
namespace Drupal\field_ui;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\FieldTypePluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -21,6 +25,30 @@ class DisplayOverview extends DisplayOverviewBase {
*/
protected $displayContext = 'view';
/**
* Stores the module manager.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a new class instance.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Field\FieldTypePluginManager $field_type_manager
* The field type manager.
* @param \Drupal\Component\Plugin\PluginManagerBase $plugin_manager
* The widget or formatter plugin manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler class to use for invoking hooks.
*/
public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManager $field_type_manager, PluginManagerBase $plugin_manager, ModuleHandlerInterface $module_handler) {
parent::__construct($entity_manager, $field_type_manager, $plugin_manager);
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
......@@ -28,7 +56,8 @@ public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('plugin.manager.field.field_type'),
$container->get('plugin.manager.field.formatter')
$container->get('plugin.manager.field.formatter'),
$container->get('module_handler')
);
}
......@@ -204,7 +233,7 @@ protected function alterSettingsForm(array &$settings_form, $plugin, FieldDefini
'view_mode' => $this->mode,
'form' => $form,
);
drupal_alter('field_formatter_settings_form', $settings_form, $form_state, $context);
$this->moduleHandler->alter('field_formatter_settings_form', $settings_form, $form_state, $context);
}
/**
......@@ -216,7 +245,7 @@ protected function alterSettingsSummary(array &$summary, $plugin, FieldDefinitio
'field_definition' => $field_definition,
'view_mode' => $this->mode,
);
drupal_alter('field_formatter_settings_summary', $summary, $context);
$this->moduleHandler->alter('field_formatter_settings_summary', $summary, $context);
}
}
......@@ -7,8 +7,12 @@
namespace Drupal\field_ui;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldTypePluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -21,6 +25,30 @@ class FormDisplayOverview extends DisplayOverviewBase {
*/
protected $displayContext = 'form';
/**
* Stores the module manager.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a new class instance.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Field\FieldTypePluginManager $field_type_manager
* The field type manager.
* @param \Drupal\Component\Plugin\PluginManagerBase $plugin_manager
* The widget or formatter plugin manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to use for invoking hooks.
*/
public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManager $field_type_manager, PluginManagerBase $plugin_manager, ModuleHandlerInterface $module_handler) {
parent::__construct($entity_manager, $field_type_manager, $plugin_manager);
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
......@@ -28,7 +56,8 @@ public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('plugin.manager.field.field_type'),
$container->get('plugin.manager.field.widget')
$container->get('plugin.manager.field.widget'),
$container->get('module_handler')
);
}
......@@ -156,7 +185,7 @@ protected function alterSettingsForm(array &$settings_form, $plugin, FieldDefini
'form_mode' => $this->mode,
'form' => $form,
);
drupal_alter('field_widget_settings_form', $settings_form, $form_state, $context);
$this->moduleHandler->alter('field_widget_settings_form', $settings_form, $form_state, $context);
}
/**
......@@ -168,7 +197,7 @@ protected function alterSettingsSummary(array &$summary, $plugin, FieldDefinitio
'field_definition' => $field_definition,
'form_mode' => $this->mode,
);
drupal_alter('field_widget_settings_summary', $summary, $context);
$this->moduleHandler->alter('field_widget_settings_summary', $summary, $context);
}
}
......@@ -660,7 +660,7 @@ function file_file_download($uri, $field_type = 'file') {
'field' => $field,
'file' => $file,
);
drupal_alter('file_download_access', $grants, $context);
\Drupal::moduleHandler()->alter('file_download_access', $grants, $context);
if (in_array(TRUE, $grants)) {
// If TRUE is returned, access is granted and no further checks are
......
......@@ -144,7 +144,7 @@ function locale_translation_project_list() {
$project_info->processInfoList($projects, $theme_data, 'theme', TRUE, $additional_whitelist);
// Allow other modules to alter projects before fetching and comparing.
drupal_alter('locale_translation_projects', $projects);
\Drupal::moduleHandler()->alter('locale_translation_projects', $projects);
}
return $projects;
}
......
......@@ -79,7 +79,7 @@ function testNodeAccessRecords() {
foreach ($operations as $op) {
$grants = node_test_node_grants($op, $web_user);
$altered_grants = $grants;
drupal_alter('node_grants', $altered_grants, $web_user, $op);
\Drupal::moduleHandler()->alter('node_grants', $altered_grants, $web_user, $op);
$this->assertNotEqual($grants, $altered_grants, format_string('Altered the %op grant for a user.', array('%op' => $op)));
}
......
......@@ -1547,7 +1547,7 @@ function node_access_grants($op, $account = NULL) {
// Fetch node access grants from other modules.
$grants = \Drupal::moduleHandler()->invokeAll('node_grants', array($account, $op));
// Allow modules to alter the assigned grants.
drupal_alter('node_grants', $grants, $account, $op);
\Drupal::moduleHandler()->alter('node_grants', $grants, $account, $op);
return array_merge(array('all' => array(0)), $grants);
}
......
......@@ -531,7 +531,7 @@ function simpletest_test_get_all($module = NULL) {
}
// Allow modules extending core tests to disable originals.
drupal_alter('simpletest', $groups);
\Drupal::moduleHandler()->alter('simpletest', $groups);
\Drupal::cache()->set($cid, $groups);
}
}
......
......@@ -10,7 +10,7 @@
use Drupal\simpletest\WebTestBase;
/**
* Tests alteration of arguments passed to drupal_alter().
* Tests alteration of arguments passed to \Drupal::moduleHandler->alter().
*/
class AlterTest extends WebTestBase {
......@@ -24,7 +24,7 @@ class AlterTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'Alter hook functionality',
'description' => 'Tests alteration of arguments passed to drupal_alter().',
'description' => 'Tests alteration of arguments passed to \Drupal::moduleHandler->alter().',
'group' => 'Common',
);
}
......@@ -46,13 +46,13 @@ function testDrupalAlter() {
// Verify alteration of a single argument.
$array_copy = $array;
$array_expected = array('foo' => 'Drupal theme');
drupal_alter('drupal_alter', $array_copy);
\Drupal::moduleHandler()->alter('drupal_alter', $array_copy);
$this->assertEqual($array_copy, $array_expected, 'Single array was altered.');
$entity_copy = clone $entity;
$entity_expected = clone $entity;
$entity_expected->foo = 'Drupal theme';
drupal_alter('drupal_alter', $entity_copy);
\Drupal::moduleHandler()->alter('drupal_alter', $entity_copy);
$this->assertEqual($entity_copy, $entity_expected, 'Single object was altered.');
// Verify alteration of multiple arguments.
......@@ -63,17 +63,17 @@ function testDrupalAlter() {
$entity_expected->foo = 'Drupal theme';
$array2_copy = $array;
$array2_expected = array('foo' => 'Drupal theme');
drupal_alter('drupal_alter', $array_copy, $entity_copy, $array2_copy);
$this->assertEqual($array_copy, $array_expected, 'First argument to drupal_alter() was altered.');
$this->assertEqual($entity_copy, $entity_expected, 'Second argument to drupal_alter() was altered.');
$this->assertEqual($array2_copy, $array2_expected, 'Third argument to drupal_alter() was altered.');
\Drupal::moduleHandler()->alter('drupal_alter', $array_copy, $entity_copy, $array2_copy);
$this->assertEqual($array_copy, $array_expected, 'First argument to \Drupal::moduleHandler->alter() was altered.');
$this->assertEqual($entity_copy, $entity_expected, 'Second argument to \Drupal::moduleHandler->alter() was altered.');
$this->assertEqual($array2_copy, $array2_expected, 'Third argument to \Drupal::moduleHandler->alter() was altered.');
// Verify alteration order when passing an array of types to drupal_alter().
// Verify alteration order when passing an array of types to \Drupal::moduleHandler->alter().
// common_test_module_implements_alter() places 'block' implementation after
// other modules.
$array_copy = $array;
$array_expected = array('foo' => 'Drupal block theme');
drupal_alter(array('drupal_alter', 'drupal_alter_foo'), $array_copy);
\Drupal::moduleHandler()->alter(array('drupal_alter', 'drupal_alter_foo'), $array_copy);
$this->assertEqual($array_copy, $array_expected, 'hook_TYPE_alter() implementations ran in correct order.');
}
}
......@@ -1032,13 +1032,13 @@ function hook_mail_alter(&$message) {
* A module may implement this hook in order to reorder the implementing
* modules, which are otherwise ordered by the module's system weight.
*
* Note that hooks invoked using drupal_alter() can have multiple variations
* (such as hook_form_alter() and hook_form_FORM_ID_alter()). drupal_alter()
* will call all such variants defined by a single module in turn. For the
* purposes of hook_module_implements_alter(), these variants are treated as
* a single hook. Thus, to ensure that your implementation of
* hook_form_FORM_ID_alter() is called at the right time, you will have to
* change the order of hook_form_alter() implementation in
* Note that hooks invoked using \Drupal::moduleHandler->alter() can have
* multiple variations(such as hook_form_alter() and hook_form_FORM_ID_alter()).
* \Drupal::moduleHandler->alter() will call all such variants defined by a
* single module in turn. For the purposes of hook_module_implements_alter(),
* these variants are treated as a single hook. Thus, to ensure that your
* implementation of hook_form_FORM_ID_alter() is called at the right time,
* you will have to change the order of hook_form_alter() implementation in
* hook_module_implements_alter().
*
* @param $implementations
......
......@@ -1576,7 +1576,7 @@ function _system_rebuild_module_data() {
// Invoke hook_system_info_alter() to give installed modules a chance to
// modify the data in the .info.yml files if necessary.
$type = 'module';
drupal_alter('system_info', $modules[$key]->info, $modules[$key], $type);
\Drupal::moduleHandler()->alter('system_info', $modules[$key]->info, $modules[$key], $type);
}
// It is possible that a module was marked as required by
......
......@@ -81,7 +81,8 @@ function bartik_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
/**
* Implements hook_TYPE_alter() on behalf of block module.
*
* This is for verifying that drupal_alter(array(TYPE1, TYPE2), ...) allows