Enables a auto activity status that changes during "save" procedure to done or pending depending on the current date/time and acitvity date/time.
A custom farmOS/Drupal module that introduces an auto status option for logs.
When set to auto, the status is automatically determined at save time based on the log’s date:
- Future (> 10 minutes) →
pending - Now or past (≤ 10 minutes) →
done - Explicit user choice (
pendingordone) → respected, not overridden
-
Create the module folder
mkdir -p web/modules/custom/activity_status_enforcer
Inside your custom module folder, create the following files:
activity_status_enforcer.info.ymlactivity_status_enforcer.module- (optional)
config/install/*.ymlfor default settings - (optional)
activity_status_enforcer.libraries.yml - (optional)
js/status-preview.jsfor live form feedback
If your status field or log bundle has a different name, update it either:
- in the YAML config, or
- directly in the PHP code.
Run the following command:
drush cr
Enable the module with Drush: drush en activity_status_enforcer -y
If you want live feedback in the form (status auto-switching before save):
Attach the JavaScript library in your form_alter hook.
Register the library in activity_status_enforcer.libraries.yml.
Place your JS logic in js/status-preview.js.
Add the following code to your activity_status_enforcer.module file:
<?php
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_FORM_ID_alter().
*/
function activity_status_enforcer_form_log_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
// Filter for specific bundles, e.g. 'activity'.
if (!empty($form['#bundle']) && $form['#bundle'] === 'activity') {
$form['#attached']['library'][] = 'activity_status_enforcer/status_preview';
}
}