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

Setting up xdebug and debugging from drush and cli in PHPSTROM

Submitted by barnettech on Tue, 04/20/2021 - 10:22

These directions worked with some modifications: https://javorszky.co.uk/2018/05/03/getting-xdebug-working-on-php-7-2-an…

I was using PHP on the command line with homebrew, so installed xdebug with pecl install xdebug
then I was able to put the following in the php.ini file, find the php.ini file for the command line by running php --ini and look for Loaded Configuration File in the output.

The below is for XDEUG 3.0

Sending an email from Drupal

Submitted by barnettech on Wed, 03/17/2021 - 14:10
/**
 * Implements hook_mail().
 */
function app_voucher_mail($key, &$message, $params) {
  $function = 'app_voucher_mail__' . $key;
  if (function_exists($function)) {
    return $function($key, $message, $params);
  }

  /*
   * @I Convert the enrollment email to use the new mail handler
   *    type     : improvement
   *    priority : normal
   *    labels   : refactoring
   */
  if (!empty($params['from'])) {
    $message['from'] = $params['from'];
  }
  $message['subject'] = $params['subject'];
  $message['body'][] = $params['body'];
}

/**

To Drupal config import a single file or a handful of files

Submitted by barnettech on Tue, 03/16/2021 - 10:01

Copy the config file(s) to a temp directory called only-few-configs (or whatver you like) and run drush cim --partial --source=/full/pathTo/only-few-configs/

This should have worked supposedly: drupal config:import:single --directory="/Users/jamesbarnett/sites/IPC/ipcedtr/config/default" --file="views.view.confirm_message_product_display.yml". (might need drupal console?)

It's working 10/3/2023 like this:

drush cim --partial --source="sites/default/files/config_2qxS84OiSm1EoIIcX3HFTV8-JsS8c-pks87NrsHJkFA0U2X6cg8C66i5u7klv3Iu2w76K2QSFw/sync" 

Two different ways to query entities / nodes: entityQuery and entityTypeManager

Submitted by barnettech on Tue, 03/09/2021 - 15:32
 $results = \Drupal::entityQuery('app_voucher')
      ->range(0, 20000)
      ->execute();
foreach ($results as $result) {
      $messenger = \Drupal::messenger();
      $voucher_entity = \Drupal::entityTypeManager()->getStorage("app_voucher")->load($result);
      $voucher_id = $voucher_entity->voucher_id->getValue();
      $product_id = $voucher_entity->product_id->getValue();

}

Here are 2 different ways to get the same sort of data: