Account created on 20 April 2010, about 14 years ago
  • Software Developer at Atech 
#

Recent comments

🇦🇺Australia taggartj

Libs look like ..
 

dependencies:
  - core/drupal
  - core/jquery
  - core/once
(function ($, Drupal, once) {
 "use strict";
 Drupal.behaviors.something = {
   attach (context, settings) {
   var resButton = once('#my-button-id', 'body', context);
   $(resButton).on('click', function() {
       alert('click');
   });
   // more stuff here
  
   }
 };
})(jQuery, Drupal, once);
🇦🇺Australia taggartj

Just came across this in my case I was trying to add an extra field as I used to do in hook_search_api_solr_documents_alter()

See search_api_solr/src/Event/PostCreateIndexDocumentsEvent.php for doc
but here is the quick version

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents(): array {
    return [
      SearchApiSolrEvents::POST_CREATE_INDEX_DOCUMENTS => 'alterSolrFieldsAfterIndex',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function alterSolrFieldsAfterIndex(PostCreateIndexDocumentsEvent $event): void {
    $documents = $event->getSolariumDocuments();
    foreach ($documents as $document) {
      $documentFields = $document->getFields();
      .... 
      $document->setField('ss_test', 'hello');
    }
    $event->setSolariumDocuments($documents);
  }
🇦🇺Australia taggartj

lint php example

🇦🇺Australia taggartj

added an example of the twig service rendering a template form custom module

🇦🇺Australia taggartj

I had Same thing in Drupal 10 version 10 Jan 2024 Where No other admin page would work or load

redirected back to user/1/edit
just reset password

just putting here to help people

🇦🇺Australia taggartj

explain use of drush 

🇦🇺Australia taggartj

Thanks @thomaswalther good to see you debugged it as it wold be quite some time before i had a chance to

🇦🇺Australia taggartj

This is still an issue in Drupal 10 please see

/**
 * Adds a prime key id so I can finish early today. 
 */
function MYMODULE_update_8002() {
  // Add a prime key for views base.
  $spec = [
    'type' => 'serial',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ];
  $db = \Drupal::database();
  $schema = $db->schema();

  if ($schema->fieldExists('some_custom_table', 'id')) {
    $schema->dropField('some_custom_table', 'id');
  }
   
  // THESE HERE Don't work as they should 
  //$schema->addField('some_custom_table', 'id', $spec, ['id']);
  //$schema->addPrimaryKey('some_custom_table', ['id']);

  // Resulting to hackery. 
  $table = 'some_custom_table';
  $col = 'id';
  $db->query('ALTER TABLE {' . $table . '} ADD {'. $col .'} INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY ({'. $col .'})');
}
🇦🇺Australia taggartj

This is still an issue in drupal 10 please see

/**
 * Adds a prime key id so I can finish early today. 
 */
function MYMODULE_update_8002() {
  // Add a prime key for views base.
  $spec = [
    'type' => 'serial',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ];
  $db = \Drupal::database();
  $schema = $db->schema();

  if ($schema->fieldExists('some_custom_table', 'id')) {
    $schema->dropField('some_custom_table', 'id');
  }
   
  // THESE HERE Don't work as they should 
  //$schema->addField('some_custom_table', 'id', $spec, ['id']);
  //$schema->addPrimaryKey('some_custom_table', ['id']);

  // Resulting to hackery. 
  $table = 'some_custom_table';
  $col = 'id';
  $db->query('ALTER TABLE {' . $table . '} ADD {'. $col .'} INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY ({'. $col .'})');
}
🇦🇺Australia taggartj

For me in 10.1.3

I had to do something like this
in Drupal\Core\Extension\ExtensionList ....

was upgrading but drush cr was not working / throwing an error


public function getPathname($extension_name) {
........
// If we make it here were not doing so good.
    if ($this->type === "profile") {
      //dump($this->getPathnames());
      $module_list = \Drupal::moduleHandler()->getModuleList();
      if (!empty($module_list[$extension_name])) {
        $ext = $module_list[$extension_name];
        if (is_object($ext)) {
          return $ext->getExtensionPathname();
        }
      }
    }
    throw new UnknownExtensionException("The {$this->type} $extension_name does not exist.");

just incase you see "The profile X does not exist."

🇦🇺Australia taggartj

New release you shall have :) working with D10 now.

🇦🇺Australia taggartj

Now i have to make a patch for Drupal core with this some where in it.
as sure I can fix my own code but not everyones.

Again if its easy to leave it in, then leave it in.

// #Add this back in
function drupal_get_path($type, $name) {
/**
drupal_get_path('module', 'node') \Drupal::service('extension.list.module')->getPath('node')
drupal_get_path('theme', 'seven') \Drupal::service('extension.list.theme')->getPath('seven')
drupal_get_path('profile', 'standard') \Drupal::service('extension.list.profile')->getPath('standard')
*/
switch ($type) {
case 'module':
return \Drupal::service('extension.list.module')->getPath($name);
break;
case 'theme':
return \Drupal::service('extension.list.theme')->getPath($name);
break;
case 'profile':
return \Drupal::service('extension.list.profile')->getPath($name);
break;
return false;
}
}

🇦🇺Australia taggartj

Yep the account has been closed

🇦🇺Australia taggartj

Strangest thing using 8.x-1.10
2 environments same code base:

one php 8.0.28 (does error) vs other has 8.0.29 (does not error)


ArgumentCountError: Too few arguments to function Drupal\captcha\Service\CaptchaService::__construct(), 0 passed in /var/www/html/public/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 and exactly 1 expected in Drupal\captcha\Service\CaptchaService->__construct() (line 28 of /var/www/html/public/modules/contrib/captcha/src/Service/CaptchaService.php)
#0 /var/www/html/public/core/lib/Drupal/Component/DependencyInjection/Container.php(259): Drupal\captcha\Service\CaptchaService->__construct()
#1 /var/www/html/public/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'captcha.helper')
#2 /var/www/html/public/core/lib/Drupal.php(207): Drupal\Component\DependencyInjection\Container->get('captcha.helper')
#3 /var/www/html/public/modules/contrib/captcha/captcha.module(169): Drupal::service('captcha.helper')
#4 /var/www/html/public/core/lib/Drupal/Core/Extension/ModuleHandler.php(562): captcha_form_alter(Array, Object(Drupal\Core\Form\FormState), 'views_exposed_f...')

however it still works ?!? and no amount of cache clears help
and drush php-eval "dump(Drupal::getContainer()->has('captcha.helper'));" = true

🇦🇺Australia taggartj

thanks for this, however can you please have a look at this https://www.drupal.org/project/rest_password/issues/3036405 (for has_equals)

So you are unable to login after you have set a new password ?

Production build 0.69.0 2024