You are here

public static function FormHookHandler::hookFormNodeTypeFormAlter in Node expire 7.2

Implements hook_form_node_type_form_alter().

Enable/Disable expiration feature on node types.

1 call to FormHookHandler::hookFormNodeTypeFormAlter()
node_expire_form_node_type_form_alter in ./node_expire.module
Implements hook_form_node_type_form_alter().

File

src/Module/Hook/FormHookHandler.php, line 27
FormHookHandler class.

Class

FormHookHandler
FormHookHandler class.

Namespace

Drupal\node_expire\Module\Hook

Code

public static function hookFormNodeTypeFormAlter(&$form, &$form_state) {
  if (user_access('administer node expire')) {
    $ntypes = variable_get('node_expire_ntypes', array());
    $node_type = $form['#node_type']->type;
    $handle_content_expiry = ConfigHandler::getHandleContentExpiry();
    if ($handle_content_expiry != 0) {

      // TODO: make both branches via common function.
      $form['workflow']['node_expire_type_cfg_enabled'] = array(
        '#title' => t('Enable Node Expiry'),
        '#description' => t('Allow nodes to expire after a certain amount of time.'),
        '#type' => 'checkbox',
        '#default_value' => empty($ntypes[$node_type]['enabled']) ? '' : $ntypes[$node_type]['enabled'],
      );

      // Visibility.
      $states = array(
        'visible' => array(
          ':input[name="node_expire_type_cfg_enabled"]' => array(
            'checked' => TRUE,
          ),
        ),
      );
      $form['workflow']['node_expire_container'] = array(
        '#type' => 'fieldset',
        '#title' => t('Node Expire'),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
        '#states' => $states,
      );

      // Text fields.
      // $form['workflow']['node_expire_container']['node_expire'] = array(
      $form['workflow']['node_expire_container']['node_expire_type_cfg_default'] = array(
        '#title' => t('Default expiration date'),
        '#description' => t('Default date to consider the node expired.') . ' ' . t('Format: PHP <a href="http://www.php.net/strtotime" target="_blank">strtotime format</a>.'),
        '#type' => 'textfield',
        // TODO: Create special class method(s) for default values.
        '#default_value' => empty($ntypes[$node_type]['default']) ? '' : TimestampUtils::dateStrFromCfgDefault($ntypes[$node_type]['default']),
        '#states' => $states,
      );
      $form['workflow']['node_expire_container']['node_expire_type_cfg_max'] = array(
        '#title' => t('Expiration date limit'),
        '#description' => t('The max date to consider the node expired.') . ' ' . t('Format: PHP <a href="http://www.php.net/strtotime" target="_blank">strtotime format</a>.') . ' ' . t('Leave it blank if this there is no limit date.'),
        '#type' => 'textfield',
        // TODO: Create special class method(s) for default values.
        '#default_value' => empty($ntypes[$node_type]['max']) ? '' : TimestampUtils::dateStrFromCfgDefault($ntypes[$node_type]['max']),
        '#states' => $states,
      );
      $form['workflow']['node_expire_container']['node_expire_type_cfg_required'] = array(
        '#title' => t('Expiration date required'),
        '#type' => 'checkbox',
        '#default_value' => !empty($ntypes[$node_type]['required']),
        '#states' => $states,
      );
      $options = ActionsHelper::getActionOptions();
      $form['workflow']['node_expire_container']['node_expire_type_cfg_action_type'] = array(
        '#type' => 'select',
        '#title' => t('Action to do'),
        '#default_value' => self::getActionType($ntypes, $node_type),
        '#options' => $options,
        '#description' => t('Action to do.'),
        '#states' => $states,
      );
    }
    else {
      $form['workflow']['node_expire_type_cfg_default'] = array(
        '#title' => t('Default expiration date'),
        '#description' => t('Default date to consider the node expired.') . ' ' . t('Format: PHP <a href="http://www.php.net/strtotime" target="_blank">strtotime format</a>.') . ' ' . t('Leave it blank if this content type never expires.'),
        '#type' => 'textfield',
        '#default_value' => empty($ntypes[$node_type]['default']) ? '' : $ntypes[$node_type]['default'],
      );
      $form['workflow']['node_expire_type_cfg_max'] = array(
        '#title' => t('Expiration date limit'),
        '#description' => t('The max date to consider the node expired.') . ' ' . t('Format: PHP <a href="http://www.php.net/strtotime" target="_blank">strtotime format</a>.') . ' ' . t('Leave it blank if this there is no limit date.'),
        '#type' => 'textfield',
        '#default_value' => empty($ntypes[$node_type]['max']) ? '' : $ntypes[$node_type]['max'],
      );
      $form['workflow']['node_expire_type_cfg_required'] = array(
        '#title' => t('Expiration date required'),
        '#type' => 'checkbox',
        '#default_value' => !empty($ntypes[$node_type]['required']),
      );
    }

    // Add special validate/submit functions.
    // Referenced in the bottom of node_expire.module
    // module_load_include('ntype.inc', 'node_expire');
    $form['#validate'][] = '_node_expire_form_node_type_form_alter_validate';
    $form['#submit'][] = '_node_expire_form_node_type_form_alter_submit';
  }
}