Hello, I've essentially rebuilt the functionality of this module for Drupal 10. It includes a checkbox in the "advanced" column of the node edit form, a Drush command, and bulk Actions plugin. I would be happy to share it but I am not familiar with how to (or whether it is possible) to add a new release branch for this module.
It is worth noting for anyone that may be unaware, the Statistics module is moving from core to contrib with Drupal 11. There has been an effort for several years to get a global reset counter button ( https://www.drupal.org/project/statistics/issues/3123772#comment-15631423 β¨ Reset the Content viewing counter statistics via Drush Active ), so given that it seems unlikely that the functionality provided in the reset_node_counter module would make it into the Statistics module anytime soon, so I do feel this module is still needed.
Hi, this functionality would be useful to a site I am currently building. I will work on this and see if I can contribute something usable.
It took me quite a while but I did get this working. There is an odd issue in that the State and Zip code fields now show on separate lines of the edit form. I'd prefer that didn't happen but now that this is functional I'm happy enough to move on.
Example of working code for .module file:
function mycustommodule_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id == 'your_form_id') {
$form['field_address']['widget'][0]['address']['#pre_render'][] = [
MyTrustedCallbackClass::class, 'myMethod',
];
}
}
And for the MyTrustedCallbackClass.php:
namespace Drupal\mycustommodule;
use Drupal\Core\Security\TrustedCallbackInterface;
class MyTrustedCallbackClass implements TrustedCallbackInterface {
public static function trustedCallbacks() {
return ['myMethod'];
}
public static function myMethod($element) {
$include_states = ['NY', 'CA'];
$options = array_intersect_key($element['administrative_area']['#options'], array_flip($include_states));
$element['administrative_area']['#options'] = $options;
return $element;
}
}
In retrospect it wasn't all that difficult but as someone who is still getting up to speed with most of my experience being a Drupal 7 site builder and not a programmer sometimes I get tripped up easily.
I am struggling to make this work. It seems the #options for administrative_area doesn't exist because I keep getting error "Warning: Undefined array key "#options" ". It seems like limiting the list (US states in my case) for an address field on a node should be simple but can't figure out what I am doing wrong.
Relevant snipped from node_form_alter function in my .module file:
$form['field_address'][0]['address']['administrative_area']['#pre_render'][] = '\Drupal\mycustommodule\MyTrustedCallbackClass::preRender';
And from MyTrustedCallbackClass.php:
<?php
namespace Drupal\mycustommodule;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Security\TrustedCallbackInterface;
class MyTrustedCallbackClass implements TrustedCallbackInterface {
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return ['preRender'];
}
/**
* Callback to limit options.
*/
public static function preRender($element) {
$include_states = ['NY', 'CA'];
$options = array_intersect_key($element['#options'], array_flip($include_states));
$element['#options'] = $options;
return $element;
}
}
?>