CommerceLicenseExample.class.php in Commerce License 7
File
modules/commerce_license_example/plugins/license_type/CommerceLicenseExample.class.php
View source
<?php
class CommerceLicenseExample extends CommerceLicenseBase {
static function fields() {
$fields = parent::fields();
$fields['cle_name']['field'] = array(
'type' => 'text',
'cardinality' => 1,
);
$fields['cle_name']['instance'] = array(
'label' => t('Name'),
'required' => 1,
'settings' => array(
'text_processing' => '0',
),
'widget' => array(
'module' => 'text',
'type' => 'text_textfield',
'settings' => array(
'size' => 20,
),
),
);
return $fields;
}
public function accessDetails() {
$output = field_view_field('commerce_license', $this, 'cle_name');
return drupal_render($output);
}
public function isConfigurable() {
return TRUE;
}
public function formValidate($form, &$form_state) {
parent::formValidate($form, $form_state);
$parents_path = implode('][', $form['#parents']);
$form_values = drupal_array_get_nested_value($form_state['values'], $form['#parents']);
if ($form_values['cle_name'][LANGUAGE_NONE][0]['value'] == 'John Smith') {
form_set_error($parents_path . '][cle_name][und][0][value', t('John Smith is not allowed to have licenses.'));
}
}
public function checkoutCompletionMessage() {
$text = 'Congratulations, ' . $this->wrapper->cle_name
->value() . '. <br />';
$text .= "You are now licensed.";
return $text;
}
}