You are here

class RedhenContactTypeUIController in RedHen CRM 7

Redhen Contact Type UI controller.

Hierarchy

Expanded class hierarchy of RedhenContactTypeUIController

1 string reference to 'RedhenContactTypeUIController'
redhen_contact_entity_info in modules/redhen_contact/redhen_contact.module
Implements hook_entity_info().

File

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

View source
class RedhenContactTypeUIController extends EntityDefaultUIController {

  /**
   * Overrides hook_menu() defaults.
   */
  public function hook_menu() {
    $items = parent::hook_menu();
    $items[$this->path]['description'] = 'Manage contact entity types, including adding and removing fields and the display of fields.';
    return $items;
  }

  /**
   * Override parent::operationForm to set a more meaningful message on delete.
   */
  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);
    }
  }

  /**
   * Override parent to pass our delete entities flag in the delete op.
   */
  public function operationFormSubmit($form, &$form_state) {
    if ($form_state['op'] == 'delete') {
      $entity = $form_state[$this->entityType];
      $delete_entities = $form_state['values']['delete_entities'];
      $entity
        ->delete($delete_entities);
      $label = entity_label($this->entityType, $entity);
      $msg = t('Successfully deleted contact type %label.', array(
        '%label' => $label,
      ));
      if ($delete_entities) {
        $msg = t('Successfully deleted contact type %label and all %label contacts.', array(
          '%label' => $label,
        ));
      }
      drupal_set_message($msg);
      $form_state['redirect'] = $this->path;
    }
    else {
      parent::operationFormSubmit($form, $form_state);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityDefaultUIController::$entityInfo protected property
EntityDefaultUIController::$entityType protected property
EntityDefaultUIController::$id_count protected property
EntityDefaultUIController::$overviewPagerLimit public property Defines the number of entries to show per page in overview table.
EntityDefaultUIController::applyOperation public function Applies an operation to the given entity.
EntityDefaultUIController::entityFormSubmitBuildEntity public function Entity submit builder invoked via entity_ui_form_submit_build_entity().
EntityDefaultUIController::hook_forms public function Provides definitions for implementing hook_forms().
EntityDefaultUIController::operationCount protected function Returns the operation count for calculating colspans.
EntityDefaultUIController::operationFormValidate public function Operation form validation callback.
EntityDefaultUIController::overviewForm public function Builds the entity overview form.
EntityDefaultUIController::overviewFormSubmit public function Overview form submit callback.
EntityDefaultUIController::overviewFormValidate public function Overview form validation callback.
EntityDefaultUIController::overviewTable public function Generates the render array for a overview table for arbitrary entities matching the given conditions.
EntityDefaultUIController::overviewTableHeaders protected function Generates the table headers for the overview table.
EntityDefaultUIController::overviewTableRow protected function Generates the row for the passed entity and may be overridden in order to customize the rows.
EntityDefaultUIController::__construct public function
RedhenContactTypeUIController::hook_menu public function Overrides hook_menu() defaults. Overrides EntityDefaultUIController::hook_menu
RedhenContactTypeUIController::operationForm public function Override parent::operationForm to set a more meaningful message on delete. Overrides EntityDefaultUIController::operationForm
RedhenContactTypeUIController::operationFormSubmit public function Override parent to pass our delete entities flag in the delete op. Overrides EntityDefaultUIController::operationFormSubmit