You are here

scheduler_extras.module in Scheduler 2.x

Same filename and directory in other branches
  1. 8 tests/modules/scheduler_extras/scheduler_extras.module

Hook implementations for the Scheduler Extras test module.

This module is used in SchedulerDefaultTimeTest to check that the default time is set correctly when the time element of the datetime input is hidden.

File

tests/modules/scheduler_extras/scheduler_extras.module
View source
<?php

/**
 * @file
 * Hook implementations for the Scheduler Extras test module.
 *
 * This module is used in SchedulerDefaultTimeTest to check that the default
 * time is set correctly when the time element of the datetime input is hidden.
 */
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_alter().
 */
function scheduler_extras_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Only continue if the form is form adding the standard test entity types.
  if (!in_array($form_id, [
    'node_testpage_form',
    'media_test_video_add_form',
    'commerce_product_test_product_add_form',
  ])) {
    return;
  }

  // Hide the time element when the scheduler field exists.
  if (isset($form['publish_on'])) {
    $form['publish_on']['widget'][0]['value']['#date_time_element'] = 'none';
  }
  if (isset($form['unpublish_on'])) {
    $form['unpublish_on']['widget'][0]['value']['#date_time_element'] = 'none';
  }
}

Functions