You are here

class CommerceLicenseInlineEntityFormController in Commerce License 7

@file Defines the IEF controller for the commerce_license entity type.

Hierarchy

Expanded class hierarchy of CommerceLicenseInlineEntityFormController

1 string reference to 'CommerceLicenseInlineEntityFormController'
commerce_license_entity_info in ./commerce_license.module
Implements hook_entity_info().

File

includes/commerce_license.inline_entity_form.inc, line 8
Defines the IEF controller for the commerce_license entity type.

View source
class CommerceLicenseInlineEntityFormController extends EntityInlineEntityFormController {

  /**
   * Overrides EntityInlineEntityFormController::settingsForm().
   */
  public function settingsForm($field, $instance) {
    $form = parent::settingsForm($field, $instance);

    // Adding existing entities is not supported for licenses.
    $form['allow_existing']['#access'] = FALSE;
    $form['match_operator']['#access'] = FALSE;
    return $form;
  }

  /**
   * Overrides EntityInlineEntityFormController::entityForm().
   */
  public function entityForm($entity_form, &$form_state) {
    $license = $entity_form['#entity'];

    // Only show the form if the license is configurable.
    if ($license
      ->isConfigurable()) {
      $license
        ->form($entity_form, $form_state);

      // Restore any form errors and show them above the form.
      if (!empty($form_state['errors'])) {
        $form_errors =& drupal_static('form_set_error', array());
        $form_errors = $form_state['errors'];
        $error_messages = array(
          'error' => array_values($form_errors),
        );
        $_SESSION['messages'] = array_merge_recursive($error_messages, drupal_get_messages());
        $entity_form['messages'] = array(
          '#markup' => theme('status_messages'),
          '#weight' => -99,
        );
      }
    }
    return $entity_form;
  }

  /**
   * Overrides EntityInlineEntityFormController::entityFormValidate().
   */
  public function entityFormValidate($entity_form, &$form_state) {
    $license = $entity_form['#entity'];

    // Only validate the form if the license is configurable.
    if ($license
      ->isConfigurable()) {
      $license
        ->formValidate($entity_form, $form_state);

      // If validation failed, save the errors, clear them, and rebuild the form.
      // This allows them to be displayed by entityForm() in a more appropriate
      // place than the top of the page.
      $form_errors =& drupal_static('form_set_error', array());
      if (!empty($form_errors)) {
        drupal_get_messages('error', TRUE);
        $form_state['errors'] = $form_errors;
        $form_errors = array();
        $form_state['rebuild'] = TRUE;
      }
      else {
        $form_state['errors'] = array();
      }
    }
  }

  /**
   * Overrides EntityInlineEntityFormController::entityFormSubmit().
   */
  public function entityFormSubmit(&$entity_form, &$form_state) {
    $license = $entity_form['#entity'];

    // If IEF is being shown on an order form, use it to get the uid.
    if (!empty($form_state['commerce_order'])) {
      $license->uid = $form_state['commerce_order']->uid;
    }
    else {
      $license->uid = $GLOBALS['user']->uid;
    }

    // $license->product_id is maintained by
    // commerce_license_commerce_line_item_presave().
    // Only submit the form if the license is configurable.
    if ($license
      ->isConfigurable()) {
      $license
        ->formSubmit($entity_form, $form_state);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommerceLicenseInlineEntityFormController::entityForm public function Overrides EntityInlineEntityFormController::entityForm(). Overrides EntityInlineEntityFormController::entityForm
CommerceLicenseInlineEntityFormController::entityFormSubmit public function Overrides EntityInlineEntityFormController::entityFormSubmit(). Overrides EntityInlineEntityFormController::entityFormSubmit
CommerceLicenseInlineEntityFormController::entityFormValidate public function Overrides EntityInlineEntityFormController::entityFormValidate(). Overrides EntityInlineEntityFormController::entityFormValidate
CommerceLicenseInlineEntityFormController::settingsForm public function Overrides EntityInlineEntityFormController::settingsForm(). Overrides EntityInlineEntityFormController::settingsForm
EntityInlineEntityFormController::$entityType protected property
EntityInlineEntityFormController::$settings public property
EntityInlineEntityFormController::createClone public function Creates a clone of the given entity. 2
EntityInlineEntityFormController::css public function Returns an array of css filepaths for the current entity type, keyed by theme name. 1
EntityInlineEntityFormController::defaultLabels public function Returns the default entity type labels. 2
EntityInlineEntityFormController::defaultSettings public function Returns an array of default settings in the form of key => value. 2
EntityInlineEntityFormController::delete public function Delete permanently saved entities. 1
EntityInlineEntityFormController::entityType public function Returns the entity type managed by this controller.
EntityInlineEntityFormController::getSetting public function Returns a setting value.
EntityInlineEntityFormController::labels public function Returns an array of entity type labels fit for display in the UI.
EntityInlineEntityFormController::removeForm public function Returns the remove form to be shown through the IEF widget. 1
EntityInlineEntityFormController::removeFormSubmit public function Handles the submission of a remove form. Decides what should happen to the entity after the removal confirmation.
EntityInlineEntityFormController::save public function Permanently saves the given entity. 2
EntityInlineEntityFormController::tableFields public function Returns an array of fields used to represent an entity in the IEF table. 4
EntityInlineEntityFormController::__construct public function 1