diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index c701dce..4215119 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -372,7 +372,7 @@ function hook_node_grants_alter(&$grants, $account, $op) { // array for roles specified in our variable setting. // Get our list of banned roles. - $restricted = variable_get('example_restricted_roles', array()); + $restricted = \Drupal::config('example.settings')->get('restricted_roles'); if ($op != 'view' && !empty($restricted)) { // Now check the roles for this account against the restrictions. diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index abda14e..8cc3c52 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -113,7 +113,7 @@ function hook_admin_paths_alter(&$paths) { function hook_cron() { // Short-running operation example, not using a queue: // Delete all expired records since the last cron run. - $expires = \Drupal::state()->get('mymodule.cron_last_run') ?: REQUEST_TIME; + $expires = \Drupal::state()->get('mymodule.cron_last_run', REQUEST_TIME); db_delete('mymodule_table') ->condition('expires', $expires, '>=') ->execute(); @@ -940,7 +940,7 @@ function hook_form_alter(&$form, &$form_state, $form_id) { $form['workflow']['upload_' . $form['type']['#value']] = array( '#type' => 'radios', '#title' => t('Attachments'), - '#default_value' => variable_get('upload_' . $form['type']['#value'], 1), + '#default_value' => \Drupal::config('mymodule.settings')->get('upload.' . $form['type']['#value']), '#options' => array(t('Disabled'), t('Enabled')), ); } @@ -1787,7 +1787,7 @@ function hook_module_preinstall($module) { */ function hook_modules_installed($modules) { if (in_array('lousy_module', $modules)) { - variable_set('lousy_module_conflicting_variable', FALSE); + \Drupal::state()->set('mymodule.lousy_module_compatibility', TRUE); } } @@ -1818,10 +1818,8 @@ function hook_module_preuninstall($module) { * @see hook_modules_disabled() */ function hook_modules_uninstalled($modules) { - foreach ($modules as $module) { - db_delete('mymodule_table') - ->condition('module', $module) - ->execute(); + if (in_array('lousy_module', $modules)) { + \Drupal::state()->delete('mymodule.lousy_module_compatibility'); } mymodule_cache_rebuild(); } @@ -2308,17 +2306,10 @@ function hook_query_TAG_alter(Drupal\Core\Database\Query\AlterableInterface $que * @see hook_modules_installed() */ function hook_install() { - // Populate the default {node_access} record. - db_insert('node_access') - ->fields(array( - 'nid' => 0, - 'gid' => 0, - 'realm' => 'all', - 'grant_view' => 1, - 'grant_update' => 0, - 'grant_delete' => 0, - )) - ->execute(); + // Create the styles directory and ensure it's writable. + $directory = file_default_scheme() . '://styles'; + $mode = isset($GLOBALS['install_state']['mode']) ? $GLOBALS['install_state']['mode'] : NULL; + file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, $mode); } /** @@ -2520,7 +2511,7 @@ function hook_update_last_removed() { * Remove any information that the module sets. * * The information that the module should remove includes: - * - variables that the module has set using variable_set() + * - state that the module has set using \Drupal::state() * - modifications to existing tables * * The module should not remove its entry from the module configuration. @@ -2545,7 +2536,8 @@ function hook_update_last_removed() { * @see hook_modules_uninstalled() */ function hook_uninstall() { - variable_del('upload_file_types'); + // Remove the styles directory and generated images. + file_unmanaged_delete_recursive(file_default_scheme() . '://styles'); } /** @@ -2589,11 +2581,10 @@ function hook_uninstall() { * access to this information. * * Remember that a user installing Drupal interactively will be able to reload - * an installation page multiple times, so you should use variable_set() and - * variable_get() if you are collecting any data that you need to store and - * inspect later. It is important to remove any temporary variables using - * variable_del() before your last task has completed and control is handed - * back to the installer. + * an installation page multiple times, so you should use \Drupal::state() to + * store any data that you may need later in the installation process. Any + * temporary state must be removed using \Drupal::state()->delete() before + * your last task has completed and control is handed back to the installer. * * @param array $install_state * An array of information about the current installation state. @@ -2652,7 +2643,7 @@ function hook_install_tasks(&$install_state) { // Here, we define a variable to allow tasks to indicate that a particular, // processor-intensive batch process needs to be triggered later on in the // installation. - $myprofile_needs_batch_processing = variable_get('myprofile_needs_batch_processing', FALSE); + $myprofile_needs_batch_processing = \Drupal::state()->get('myprofile.needs_batch_processing', FALSE); $tasks = array( // This is an example of a task that defines a form which the user who is // installing the site will be asked to fill out. To implement this task, @@ -2660,9 +2651,9 @@ function hook_install_tasks(&$install_state) { // as a normal form API callback function, with associated validation and // submit handlers. In the submit handler, in addition to saving whatever // other data you have collected from the user, you might also call - // variable_set('myprofile_needs_batch_processing', TRUE) if the user has - // entered data which requires that batch processing will need to occur - // later on. + // \Drupal::state()->set('myprofile.needs_batch_processing', TRUE) if the + // user has entered data which requires that batch processing will need to + // occur later on. 'myprofile_data_import_form' => array( 'display_name' => t('Data import options'), 'type' => 'form', @@ -2682,7 +2673,7 @@ function hook_install_tasks(&$install_state) { // implement this task, your profile would define a function named // myprofile_batch_processing() which returns a batch API array definition // that the installer will use to execute your batch operations. Due to the - // 'myprofile_needs_batch_processing' variable used here, this task will be + // 'myprofile.needs_batch_processing' variable used here, this task will be // hidden and skipped unless your profile set it to TRUE in one of the // previous tasks. 'myprofile_batch_processing' => array( @@ -2696,13 +2687,14 @@ function hook_install_tasks(&$install_state) { // function named myprofile_final_site_setup(), in which additional, // automated site setup operations would be performed. Since this is the // last task defined by your profile, you should also use this function to - // call variable_del('myprofile_needs_batch_processing') and clean up the - // variable that was used above. If you want the user to pass to the final - // Drupal installation tasks uninterrupted, return no output from this - // function. Otherwise, return themed output that the user will see (for - // example, a confirmation page explaining that your profile's tasks are - // complete, with a link to reload the current page and therefore pass on - // to the final Drupal installation tasks when the user is ready to do so). + // call \Drupal::state()->delete('myprofile.needs_batch_processing') and + // clean up the state that was used above. If you want the user to pass + // to the final Drupal installation tasks uninterrupted, return no output + // from this function. Otherwise, return themed output that the user will + // see (for example, a confirmation page explaining that your profile's + // tasks are complete, with a link to reload the current page and therefore + // pass on to the final Drupal installation tasks when the user is ready to + // do so). 'myprofile_final_site_setup' => array( ), ); @@ -3235,12 +3227,10 @@ function hook_filetransfer_info() { * @see hook_filetransfer_info() */ function hook_filetransfer_info_alter(&$filetransfer_info) { - if (variable_get('paranoia', FALSE)) { - // Remove the FTP option entirely. - unset($filetransfer_info['ftp']); - // Make sure the SSH option is listed first. - $filetransfer_info['ssh']['weight'] = -10; - } + // Remove the FTP option entirely. + unset($filetransfer_info['ftp']); + // Make sure the SSH option is listed first. + $filetransfer_info['ssh']['weight'] = -10; } /**