WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

Getting and setting a config value in Drupal 8

Submitted by barnettech on Thu, 09/23/2021 - 12:34

\Drupal::config('ipc_syncdb.settings')->get('transaction_api_log_level');

or

use Drupal\Core\Config\ConfigFactoryInterface;
$config = $this->configFactory->get('ipc_syncdb.settings');
 $requestParams->logLevel = $config->get('transaction_api_log_level');

https://www.drupal.org/docs/upgrading-and-converting-drupal-7-modules/s…

 \Drupal::state()->set('my_data', 'foo');
  $data = \Drupal::state()->get('my_data', 'bar');
  \Drupal::state()->delete('my_data');

real usage example:

  $run_time = date('Y-m-d\TH:i:s');
  $last_run_time = \Drupal::state()->get('ipc_order_cron_last_run_time', $run_time);
  $requestParams->modifiedOnAfter = $last_run_time;
  $result = Transaction::getEdgeTransactionList($requestParams);
   ... and then later on:
   $run_time = date('Y-m-d\TH:i:s');
  \Drupal::state()->set('ipc_order_cron_last_run_time', $run_time);