예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Build the file_product object from the form values.
     $file = uc_file_get_by_name($form_state->getValue('uc_file_filename'));
     $file_product = array('fid' => $file->fid, 'filename' => $file->filename, 'pfid' => $form_state->getValue('pfid'), 'model' => $form_state->getValue('uc_file_model'), 'description' => $form_state->getValue('uc_file_description'), 'shippable' => $form_state->getValue('uc_file_shippable'), 'download_limit' => $form_state->getValue('download_limit_number') ?: UC_FILE_LIMIT_SENTINEL, 'address_limit' => $form_state->getValue('download_limit_addresses') ?: UC_FILE_LIMIT_SENTINEL, 'time_granularity' => $form_state->getValue('download_limit_duration_granularity') ?: UC_FILE_LIMIT_SENTINEL, 'time_quantity' => $form_state->getValue('download_limit_duration_qty') ?: UC_FILE_LIMIT_SENTINEL);
     // Build product feature descriptions.
     $file_config = $this->config('uc_file.settings');
     $description = $this->t('<strong>SKU:</strong> @sku<br />', ['@sku' => empty($file_product['model']) ? 'Any' : $file_product['model']]);
     if (is_dir($file_config->get('base_dir') . "/" . $file_product['filename'])) {
         $description .= $this->t('<strong>Directory:</strong> @dir<br />', ['@dir' => $file_product['filename']]);
     } else {
         $description .= $this->t('<strong>File:</strong> @file<br />', ['@file' => \Drupal::service('file_system')->basename($file_product['filename'])]);
     }
     $description .= $file_product['shippable'] ? $this->t('<strong>Shippable:</strong> Yes') : $this->t('<strong>Shippable:</strong> No');
     $data = array('pfid' => $file_product['pfid'], 'nid' => $form_state->getValue('nid'), 'fid' => 'file', 'description' => $description);
     uc_product_feature_save($data);
     $file_product['pfid'] = $data['pfid'];
     unset($file_product['filename']);
     $key = NULL;
     if ($fpid = _uc_file_get_fpid($file_product['pfid'])) {
         $key = $fpid;
     }
     // Insert or update (if $key is already in table) uc_file_products table.
     db_merge('uc_file_products')->key(['fpid' => $key])->fields($file_product)->execute();
     $form_state->setRedirect('uc_product.features', ['node' => $data['nid']]);
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $product_role = array('pfid' => $form_state->getValue('pfid'), 'rpid' => $form_state->getValue('rpid'), 'nid' => $form_state->getValue('nid'), 'model' => $form_state->getValue('uc_role_model'), 'rid' => $form_state->getValue('uc_role_role'), 'duration' => $form_state->getValue('uc_role_expire_relative_granularity') != 'never' ? $form_state->getValue('uc_role_expire_relative_duration') : NULL, 'granularity' => $form_state->getValue('uc_role_expire_relative_granularity'), 'by_quantity' => $form_state->getValue('uc_role_by_quantity'), 'shippable' => $form_state->getValue('uc_role_shippable'), 'end_override' => $form_state->getValue('end_override'), 'end_time' => $form_state->getValue('expiration') === 'abs' ? $form_state->getValue('uc_role_expire_absolute') : NULL);
     $description = empty($product_role['model']) ? $this->t('<strong>SKU:</strong> Any<br />') : $this->t('<strong>SKU:</strong> @sku<br />', ['@sku' => $product_role['model']]);
     $description .= $this->t('<strong>Role:</strong> @role_name<br />', ['@role_name' => _uc_role_get_name($product_role['rid'])]);
     if ($product_role['end_override']) {
         if ($product_role['end_time']) {
             $description .= $this->t('<strong>Expiration:</strong> @date<br />', ['@date' => \Drupal::service('date.formatter')->format($product_role['end_time'])]);
         } else {
             switch ($product_role['granularity']) {
                 case 'never':
                     $description .= $this->t('<strong>Expiration:</strong> never<br />');
                     break;
                 case 'day':
                     $description .= $this->t('<strong>Expiration:</strong> @qty day(s)<br />', ['@qty' => $product_role['duration']]);
                     break;
                 case 'week':
                     $description .= $this->t('<strong>Expiration:</strong> @qty week(s)<br />', ['@qty' => $product_role['duration']]);
                     break;
                 case 'month':
                     $description .= $this->t('<strong>Expiration:</strong> @qty month(s)<br />', ['@qty' => $product_role['duration']]);
                     break;
                 case 'year':
                     $description .= $this->t('<strong>Expiration:</strong> @qty year(s)<br />', ['@qty' => $product_role['duration']]);
                     break;
                 default:
                     break;
             }
         }
     } else {
         $description .= $this->t('<strong>Expiration:</strong> @link (not overridden)<br />', ['@link' => $this->l(t('Global expiration'), Url::fromRoute('uc_product.settings'))]);
     }
     $description .= $product_role['shippable'] ? $this->t('<strong>Shippable:</strong> Yes<br />') : $this->t('<strong>Shippable:</strong> No<br />');
     $description .= $product_role['by_quantity'] ? $this->t('<strong>Multiply by quantity:</strong> Yes') : $this->t('<strong>Multiply by quantity:</strong> No');
     $data = array('pfid' => $product_role['pfid'], 'nid' => $product_role['nid'], 'fid' => 'role', 'description' => $description);
     uc_product_feature_save($data);
     $product_role['pfid'] = $data['pfid'];
     // Insert or update uc_file_product table.
     foreach (['duration', 'granularity', 'end_time'] as $property) {
         $product_role[$property] = $product_role[$property] === NULL ? 0 : $product_role[$property];
     }
     if (!isset($product_role['rpid'])) {
         $product_role['rpid'] = db_insert('uc_roles_products')->fields($product_role)->execute();
     } else {
         db_merge('uc_roles_products')->key('rpid', $product_role['rpid'])->fields($product_role)->execute();
     }
     $form_state->setRedirect('uc_product.features', ['node' => $data['nid']]);
 }