You are here

public function RedhenContactTypeUIController::operationForm in RedHen CRM 7

Override parent::operationForm to set a more meaningful message on delete.

Overrides EntityDefaultUIController::operationForm

File

modules/redhen_contact/lib/redhen_contact_type.ui_controller.inc, line 24
Defines the EntityDefaultUIController for RedHen contacts.

Class

RedhenContactTypeUIController
Redhen Contact Type UI controller.

Code

public function operationForm($form, &$form_state, $entity, $op) {
  switch ($op) {
    case 'delete':
      $query = new EntityFieldQuery();
      $count = $query
        ->entityCondition('entity_type', 'redhen_contact')
        ->entityCondition('bundle', $entity->name)
        ->count()
        ->execute();
      $label = entity_label($this->entityType, $entity);
      $confirm_question = t('Are you sure you want to delete the %entity %label?', array(
        '%entity' => $this->entityInfo['label'],
        '%label' => $label,
      ));
      $form['delete_entities'] = array(
        '#type' => 'checkbox',
        '#title' => t('If checked, all %count contacts of type %type will also be deleted.', array(
          '%type' => $label,
          '%count' => $count,
        )),
        '#description' => t('If you have a large number of contacts of type %type, this may cause a timeout. Use with caution.', array(
          '%type' => $label,
        )),
        '#access' => $count > 0,
        '#default_value' => FALSE,
      );
      $desc = t('Click confirm to delete the contact type %label. This operation cannot be undone.', array(
        '%label' => $label,
      ));
      return confirm_form($form, $confirm_question, $this->path, $desc);
    default:
      return parent::operationForm($form, $form_state, $entity, $op);
  }
}