You are here

class EntityformTypeController in Entityform 7.2

Same name and namespace in other branches
  1. 7 entityform.module \EntityformTypeController

The Controller for Entityform entities

Hierarchy

Expanded class hierarchy of EntityformTypeController

1 string reference to 'EntityformTypeController'
entityform_entity_info in ./entityform.module
Implements hook_entity_info().

File

./entityform.module, line 1327
Module for the Entityform Entity - a starting point to create your own Entity and associated administration interface

View source
class EntityformTypeController extends EntityAPIControllerExportable {
  public function __construct($entityType) {
    parent::__construct($entityType);
  }

  /**
   * Create a entityform type - we first set up the values that are specific
   * to our entityform type schema but then also go through the EntityAPIController
   * function.
   *
   * @param $type
   *   The machine-readable type of the entityform.
   *
   * @return
   *   A entityform type object with all default fields initialized.
   */
  public function create(array $values = array(), $load_defaults = FALSE) {

    // Add values that are specific to our Entityform
    $default_values = variable_get('entityform_type_defaults', array());
    if (empty($default_values)) {
      $default_values = array();
    }
    $values += $default_values;
    $values += array(
      'id' => '',
      'is_new' => TRUE,
    );
    if (!isset($values['data'])) {
      $values['data'] = array();
    }
    if ($load_defaults) {
      $values['data'] += array(
        'submissions_view' => 'entityforms',
        'user_submissions_view' => 'user_entityforms',
        'preview_page' => 0,
      );
      $values['data'] += $this
        ->get_default_text_values();
    }
    else {
      if ($values['is_new']) {

        // Don't override values even if is_new. Features will send values in for checking status.
        $values['data'] += array(
          'submissions_view' => 'default',
          'user_submissions_view' => 'default',
        );
      }
    }
    $entityform_type = parent::create($values);
    return $entityform_type;
  }

  /**
   * Returns default text values
   */
  public function get_default_text_values() {
    return array(
      'label' => '',
      'instruction_pre' => '',
      'submit_confirm_msg' => t('Your submission has been saved.'),
      'submission_page_title' => t('Thank You.'),
      'draft_button_text' => t('Save Draft'),
      'submit_button_text' => t('Submit'),
      'your_submissions' => t('Your Submissions: @label', array(
        '@label' => '[entityform_type:label]',
      )),
      'disallow_resubmit_msg' => t('You already submitted this form'),
      'delete_confirm_msg' => t('Are you sure you want to delete this Submission for @label', array(
        '@label' => '[entityform_type:label]?',
      )),
      'draft_save_text' => '',
      'page_title_view' => t('Form Submission: @label', array(
        '@label' => '[entityform_type:label]',
      )),
    );
  }

  /**
   * Returns text labels.
   */
  public function get_text_labels() {
    return array(
      'label' => t('Label'),
      'draft_redirect_path' => t('Draft Redirect path'),
      'draft_button_text' => t('Override draft button text'),
      'draft_save_text' => t('Draft save text'),
      'submit_button_text' => t('Submit Button Text'),
      'submit_confirm_msg' => t('Submission Confirmation Text'),
      'your_submissions' => t('Your Submissions Text'),
      'disallow_resubmit_msg' => t('Form Disallow Resubmit Text'),
      'delete_confirm_msg' => t('Submission Delete Text'),
      'submission_page_title' => t('Thank You.'),
      'page_title_view' => t('Submission View Title'),
      'submission_text' => t('Submission reply'),
      'redirect_path' => t('Redirect path'),
      'instruction_pre' => t('Intro form instructions'),
    );
  }

  /*
   * Overridden to Load file
   */
  public function view($entities, $view_mode = 'full', $langcode = NULL, $page = NULL) {
    $view = parent::view($entities, $view_mode, $langcode, $page);
    foreach ($entities as $entity_id => $entity) {
      module_load_include('inc', 'entityform', 'entityform.admin');
      $view[$this->entityType][$entity->type]['form'] = entityform_form_wrapper(entityform_empty_load($entity->type), 'submit', $page ? 'page' : 'embedded');
    }
    return $view;
  }

  /**
   * Overridden to load paths also
   */
  public function load($ids = array(), $conditions = array()) {
    $entityform_types = parent::load($ids, $conditions);
    foreach ($entityform_types as $entityform_type) {
      if (module_exists('path')) {
        $entityform_type->paths = array();
        $path_types = _entityform_type_get_path_types($entityform_type->type);
        foreach ($path_types as $key => $path_type) {

          //check for existing alias
          $conditions = array(
            'source' => $path_type['default_path'],
          );
          $path = path_load($conditions);
          if ($path !== FALSE) {
            $entityform_type->paths[$key] = $path;
          }
        }
      }
    }
    return $entityform_types;
  }

  /**
   * Overridden to clear cache.
   */
  public function save($entity, DatabaseTransaction $transaction = NULL) {
    $return = parent::save($entity, $transaction);

    // Reset the entityform type cache. We need to do this first so
    // menu changes pick up our new type.
    entityform_type_cache_reset();

    // Clear field info caches such that any changes to extra fields get
    // reflected.
    field_info_cache_clear();
    return $return;
  }

  /**
   * Overridden to delete aliases and clear cache.
   */
  public function delete($ids, DatabaseTransaction $transaction = NULL) {
    $entities = $ids ? $this
      ->load($ids) : FALSE;
    if ($entities) {
      if (module_exists('path')) {
        foreach ($entities as $id => $entity) {
          try {
            $path_types = _entityform_type_get_path_types($entity->type);
            foreach ($path_types as $path_type) {
              path_delete(array(
                'source' => $path_type['default_path'],
              ));
            }
          } catch (Exception $e) {
          }
        }
      }

      // Delete all menu module links that point to this entityform type.
      $submit_paths = array();
      foreach ($entities as $id => $entity) {
        $submit_paths[] = _entityform_type_get_submit_url($entity->type);
      }
      $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path IN (:path) AND module = 'entityform'", array(
        ':path' => $submit_paths,
      ), array(
        'fetch' => PDO::FETCH_ASSOC,
      ));
      foreach ($result as $m) {
        menu_link_delete($m['mlid']);
      }
      parent::delete($ids, $transaction);

      // Clear field info caches such that any changes to extra fields get
      // reflected.
      field_info_cache_clear();

      // Reset the entityform type cache.
      entityform_type_cache_reset();
    }
  }

  /*
   * Overridden to exclude pid in alias Export
   */
  public function export($entity, $prefix = '') {
    if (module_exists('path')) {
      foreach ($entity->paths as &$path) {
        unset($path['pid']);
      }
    }
    return parent::export($entity, $prefix);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalDefaultEntityController::$cache protected property Whether this entity type should use the static cache.
DrupalDefaultEntityController::$entityCache protected property Static cache of entities, keyed by entity ID.
DrupalDefaultEntityController::$entityInfo protected property Array of information about the entity.
DrupalDefaultEntityController::$entityType protected property Entity type for this controller instance.
DrupalDefaultEntityController::$hookLoadArguments protected property Additional arguments to pass to hook_TYPE_load().
DrupalDefaultEntityController::$idKey protected property Name of the entity's ID field in the entity database table.
DrupalDefaultEntityController::$revisionKey protected property Name of entity's revision database table field, if it supports revisions.
DrupalDefaultEntityController::$revisionTable protected property The table that stores revisions, if the entity supports revisions.
DrupalDefaultEntityController::cleanIds protected function Ensures integer entity IDs are valid.
DrupalDefaultEntityController::filterId protected function Callback for array_filter that removes non-integer IDs.
EntityAPIController::$bundleKey protected property
EntityAPIController::$cacheComplete protected property
EntityAPIController::$defaultRevisionKey protected property
EntityAPIController::buildContent public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::buildContent
EntityAPIController::deleteRevision public function Implements EntityAPIControllerRevisionableInterface::deleteRevision(). Overrides EntityAPIControllerRevisionableInterface::deleteRevision
EntityAPIController::import public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::import
EntityAPIController::query public function Builds and executes the query for loading.
EntityAPIController::renderEntityProperty protected function Renders a single entity property.
EntityAPIController::saveRevision protected function Saves an entity revision.
EntityAPIControllerExportable::$entityCacheByName protected property
EntityAPIControllerExportable::$nameKey protected property
EntityAPIControllerExportable::applyConditions protected function
EntityAPIControllerExportable::attachLoad protected function Overridden. Overrides DrupalDefaultEntityController::attachLoad
EntityAPIControllerExportable::buildQuery protected function Support loading by name key. Overrides EntityAPIController::buildQuery
EntityAPIControllerExportable::cacheGet protected function Overridden. Overrides DrupalDefaultEntityController::cacheGet
EntityAPIControllerExportable::cacheGetByName protected function Like cacheGet() but keyed by name.
EntityAPIControllerExportable::cacheSet protected function Overridden. Overrides DrupalDefaultEntityController::cacheSet
EntityAPIControllerExportable::invoke public function Overridden to care about reverted bundle entities and to skip Rules. Overrides EntityAPIController::invoke
EntityAPIControllerExportable::resetCache public function Overrides DrupalDefaultEntityController::resetCache(). Overrides EntityAPIController::resetCache
EntityformTypeController::create public function Create a entityform type - we first set up the values that are specific to our entityform type schema but then also go through the EntityAPIController function. Overrides EntityAPIController::create
EntityformTypeController::delete public function Overridden to delete aliases and clear cache. Overrides EntityAPIControllerExportable::delete
EntityformTypeController::export public function Overridden. Overrides EntityAPIControllerExportable::export
EntityformTypeController::get_default_text_values public function Returns default text values
EntityformTypeController::get_text_labels public function Returns text labels.
EntityformTypeController::load public function Overridden to load paths also Overrides EntityAPIControllerExportable::load
EntityformTypeController::save public function Overridden to clear cache. Overrides EntityAPIControllerExportable::save
EntityformTypeController::view public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerExportable::view
EntityformTypeController::__construct public function Overridden. Overrides EntityAPIControllerExportable::__construct