Commit 73b4dd34 authored by Alex Shipilov's avatar Alex Shipilov Committed by dabblela
Browse files

Issue #1868540 by AndrewsizZ, andrewbelcher, alexshipilov, rerooting: Switch...

Issue #1868540 by AndrewsizZ, andrewbelcher, alexshipilov, rerooting: Switch to using exportable entities for entity types
parent 0879b45a
Loading
Loading
Loading
Loading
+83
Changes for commerce_order_types.admin.inc: 83 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Provides basic order types management functionality.
 */

/**
 * Creation/editing commerce order type form.
 */
function commerce_order_type_form($form, &$form_state, $commerce_order_type, $op = 'edit') {

  if ($op == 'clone') {
    $commerce_order_type->name .= ' (cloned)';
    $commerce_order_type->type = '';
  }

  $form['name'] = array(
    '#title' => t('Label'),
    '#type' => 'textfield',
    '#default_value' => isset($commerce_order_type->name) ? $commerce_order_type->name : '',
    '#description' => t('The human-readable name of this commerce order type.'),
    '#required' => TRUE,
    '#size' => 30,
  );
  // Machine-readable type name.
  $form['type'] = array(
    '#type' => 'machine_name',
    '#default_value' => isset($commerce_order_type->type) ? $commerce_order_type->type : '',
    '#maxlength' => 32,
    '#disabled' => $commerce_order_type->isLocked() && $op != 'clone',
    '#machine_name' => array(
      'exists' => 'commerce_order_types_order_types',
      'source' => array('name'),
    ),
    '#description' => t('A unique machine-readable name for this commerce order type. It must only contain lowercase letters, numbers, and underscores.'),
  );

  $form['help'] = array(
    '#type' => 'textarea',
    '#default_value' => isset($commerce_order_type->help) ? $commerce_order_type->help : '',
    '#description' => t('Description about the commerce order type.'),
  );

  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Order Type'),
    '#weight' => 40,
  );

  if (!$commerce_order_type->isLocked() && $op != 'add') {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete Order Type'),
      '#weight' => 45,
      '#limit_validation_errors' => array(),
      '#submit' => array('commerce_order_type_form_submit_delete'),
    );
  }

  return $form;
}

/**
 * Submit handler for creating/editing commerce_order_type.
 */
function commerce_order_type_form_submit(&$form, &$form_state) {
  $commerce_order_type = entity_ui_form_submit_build_entity($form, $form_state);
  // Save and go back.
  $commerce_order_type->save();
  commerce_order_configure_order_type($commerce_order_type->type);

  // Redirect user back to list of commerce order types.
  $form_state['redirect'] = 'admin/commerce/config/order-types';
}

/**
 * Submit handler for deletion button for commerce_order_type.
 */
function commerce_order_type_form_submit_delete(&$form, &$form_state) {
  $form_state['redirect'] = 'admin/commerce/config/order-types/manage/' . $form_state['commerce_order_type']->type . '/delete';
}
+27
Changes for commerce_order_types.entity.inc: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Extends EntityAPIControllerInterface with classes for commerce order types.
 */

/**
 * Provides a class for commerce order types.
 *
 * Use a separate class so we can specify some defaults modules may be alter.
 */
class CommerceOrderType extends Entity {
  public $type;
  public $id;
  public $help;
  public $data;

  public function __construct($values = array()) {
    parent::__construct($values, 'commerce_order_type');
  }

  function isLocked() {
    return !empty($this->id);
  }

}
+2
Changes for commerce_order_types.info: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,3 +4,5 @@ package = Commerce (contrib)
dependencies[] = commerce_order
core = 7.x
configure = admin/commerce/config/order-types
files[] = commerce_order_types.admin.inc
files[] = commerce_order_types.entity.inc
+60 −2
Changes for commerce_order_types.install: 60 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -8,9 +8,18 @@
 * Implements hook_schema().
 */
function commerce_order_types_schema() {
  $schema['commerce_order_types_order_types'] = array(
  $schema['commerce_order_types'] = array(
    'description' => 'Stores information about Commerce Order item types created via UI.',
    'primary key' => array('id'),
    'unique keys' => array(
      'type' => array('type'),
    ),
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique order type id.',
      ),
      'type' => array(
        'description' => 'The machine-readable name of this type.',
        'type' => 'varchar',
@@ -31,9 +40,58 @@ function commerce_order_types_schema() {
        'not null' => FALSE,
        'size' => 'medium',
      ),
      'data' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'A serialized array of additional data related to this order type.',
      ),
    'primary key' => array('type'),
    ) + entity_exportable_schema_fields(),
  );

  return $schema;
}

/**
 * Rename commerce_order_types_order_types_table
 */
function commerce_order_types_update_7001() {
  db_rename_table('commerce_order_types_order_types', 'commerce_order_types');
  // Add our primary key.
  db_drop_primary_key('commerce_order_types');
  $spec = array(
    'type' => 'serial',
    'not null' => TRUE,
    'description' => 'Primary Key: Unique order type id.',
  );
  $keys = array(
    'primary key' => array('id'),
  );
  db_add_field('commerce_order_types', 'id', $spec, $keys);
  // Add our unique keys.
  db_add_unique_key('commerce_order_types', 'type', array('type'));
  // Get an array of all the field definitions.
  $fields = array(
    'id' => array(
      'type' => 'serial',
      'not null' => TRUE,
      'description' => 'Primary Key: Unique order type id.',
    ),
    'data' => array(
      'type' => 'text',
      'not null' => FALSE,
      'size' => 'big',
      'serialize' => TRUE,
      'description' => 'A serialized array of additional data related to this order type.',
    ),
  ) + entity_exportable_schema_fields();
  // Add all our fields to the table.
  foreach ($fields as $field => $spec) {
    db_add_field('commerce_order_types', $field, $spec);
  }
  // We have changed the name of the table, so let's clear the schema cache.
  drupal_get_complete_schema(TRUE);
  // The exportable entity changes also need to clear the caches.
  drupal_flush_all_caches();
}
+92 −367

File changed.

Preview size limit exceeded, changes collapsed.