You are here

function event_calendar_form_taxonomy_form_term_alter in Event Calendar 7

Implements hook_form_FORM_ID_alter().

Set access FALSE for not to delete module defined terms. Make term name 'readonly'.

File

./event_calendar.module, line 246
The module file that allows events to be created and required admin approval.

Code

function event_calendar_form_taxonomy_form_term_alter(&$form, &$form_state, $form_id) {

  // Build query to fetch available terms.
  $vid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE machine_name = :machine_name", array(
    ':machine_name' => TAXONOMY_NAME,
  ))
    ->fetchField();

  // Disable access to delete and set readonly.
  // List of term added default.
  $terms = array(
    'approved' => 'approved',
    'pending' => 'pending',
    'denied' => 'denied',
  );
  if (isset($form['#vocabulary']->vid) && $form['#vocabulary']->vid == $vid) {
    if (@$form_state['values']['op'] != 'Delete') {
      if (in_array($form['#term']['name'], $terms)) {
        $form['name']['#attributes']['readonly'] = 'readonly';
        $form['actions']['delete']['#access'] = FALSE;
      }
    }
  }
}