本文整理汇总了PHP中Drupal\Component\Utility\Unicode::ucwords方法的典型用法代码示例。如果您正苦于以下问题:PHP Unicode::ucwords方法的具体用法?PHP Unicode::ucwords怎么用?PHP Unicode::ucwords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Component\Utility\Unicode
的用法示例。
在下文中一共展示了Unicode::ucwords方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL)
{
$form['#tree'] = TRUE;
$form['#attached']['library'][] = 'uc_fulfillment/uc_fulfillment.scripts';
$shipping_types_products = array();
foreach ($uc_order->products as $product) {
if (uc_order_product_is_shippable($product)) {
$product->shipping_type = uc_product_get_shipping_type($product);
$shipping_types_products[$product->shipping_type][] = $product;
}
}
$quote_config = \Drupal::config('uc_quote.settings');
$shipping_type_weights = $quote_config->get('type_weight');
$result = db_query('SELECT op.order_product_id, SUM(pp.qty) AS quantity FROM {uc_packaged_products} pp LEFT JOIN {uc_packages} p ON pp.package_id = p.package_id LEFT JOIN {uc_order_products} op ON op.order_product_id = pp.order_product_id WHERE p.order_id = :id GROUP BY op.order_product_id', [':id' => $uc_order->id()]);
$packaged_products = $result->fetchAllKeyed();
$form['shipping_types'] = array();
$header = array(array('data' => '', 'class' => array('select-all')), 'model' => $this->t('SKU'), 'name' => $this->t('Title'), 'qty' => $this->t('Quantity'), 'package' => $this->t('Package'));
$shipping_type_options = uc_quote_shipping_type_options();
foreach ($shipping_types_products as $shipping_type => $products) {
$form['shipping_types'][$shipping_type] = array('#type' => 'fieldset', '#title' => isset($shipping_type_options[$shipping_type]) ? $shipping_type_options[$shipping_type] : Unicode::ucwords(str_replace('_', ' ', $shipping_type)), '#weight' => isset($shipping_type_weights[$shipping_type]) ? $shipping_type_weights[$shipping_type] : 0);
$form['shipping_types'][$shipping_type]['table'] = array('#type' => 'table', '#header' => $header, '#empty' => $this->t('There are no products available for this type of package.'));
foreach ($products as $product) {
$unboxed_qty = $product->qty->value;
if (isset($packaged_products[$product->order_product_id->value])) {
$unboxed_qty -= $packaged_products[$product->order_product_id->value];
}
if ($unboxed_qty > 0) {
$row = array();
$row['checked'] = array('#type' => 'checkbox', '#default_value' => 0);
$row['model'] = array('#plain_text' => $product->model->value);
$row['name'] = array('#markup' => $product->title->value);
$range = range(1, $unboxed_qty);
$row['qty'] = array('#type' => 'select', '#title' => $this->t('Quantity'), '#title_display' => 'invisible', '#options' => array_combine($range, $range), '#default_value' => $unboxed_qty);
$range = range(0, count($uc_order->products));
$options = array_combine($range, $range);
$options[0] = $this->t('Sep.');
$row['package'] = array('#type' => 'select', '#title' => $this->t('Package'), '#title_display' => 'invisible', '#options' => $options, '#default_value' => 0);
$form['shipping_types'][$shipping_type]['table'][$product->order_product_id->value] = $row;
}
}
}
$form['order_id'] = array('#type' => 'hidden', '#value' => $uc_order->id());
$form['actions'] = array('#type' => 'actions');
$form['actions']['create'] = array('#type' => 'submit', '#value' => $this->t('Make packages'));
$form['actions']['combine'] = array('#type' => 'submit', '#value' => $this->t('Create one package'));
$form['actions']['cancel'] = array('#type' => 'submit', '#value' => $this->t('Cancel'));
return $form;
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL, $package_id = NULL)
{
$this->package = Package::load($package_id);
$form['#tree'] = TRUE;
$form['#attached']['library'][] = 'uc_fulfillment/uc_fulfillment.scripts';
$products = array();
$shipping_types_products = array();
foreach ($uc_order->products as $product) {
if (uc_order_product_is_shippable($product)) {
$product->shipping_type = uc_product_get_shipping_type($product);
$shipping_types_products[$product->shipping_type][$product->order_product_id->value] = $product;
$products[$product->order_product_id->value] = $product;
}
}
$header = array(array('data' => '', 'class' => array('select-all')), 'model' => $this->t('SKU'), 'name' => $this->t('Title'), 'qty' => $this->t('Quantity'));
$result = db_query('SELECT order_product_id, SUM(qty) AS quantity FROM {uc_packaged_products} pp LEFT JOIN {uc_packages} p ON pp.package_id = p.package_id WHERE p.order_id = :id GROUP BY order_product_id', [':id' => $uc_order->id()]);
foreach ($result as $packaged_product) {
// Make already packaged products unavailable, except those in this package.
$products[$packaged_product->order_product_id]->qty->value -= $packaged_product->quantity;
if (isset($this->package->products[$packaged_product->order_product_id])) {
$products[$packaged_product->order_product_id]->qty->value += $this->package->products[$packaged_product->order_product_id]->qty;
}
}
$form['products'] = array('#type' => 'table', '#header' => $header, '#empty' => $this->t('There are no products available for this type of package.'));
foreach ($products as $product) {
if ($product->qty->value > 0) {
$row = array();
$row['checked'] = array('#type' => 'checkbox', '#default_value' => isset($this->package->products[$product->order_product_id->value]));
$row['model'] = array('#markup' => $product->model->value);
$row['name'] = array('#markup' => $product->title->value);
$range = range(1, $product->qty->value);
$row['qty'] = array('#type' => 'select', '#options' => array_combine($range, $range), '#default_value' => isset($this->package->products[$product->order_product_id->value]) ? $this->package->products[$product->order_product_id->value]->qty : 1);
$form['products'][$product->order_product_id->value] = $row;
}
}
$options = array();
$shipping_type_options = uc_quote_shipping_type_options();
foreach (array_keys($shipping_types_products) as $type) {
$options[$type] = isset($shipping_type_options[$type]) ? $shipping_type_options[$type] : Unicode::ucwords(str_replace('_', ' ', $type));
}
$form['shipping_type'] = array('#type' => 'select', '#title' => $this->t('Shipping type'), '#options' => $options, '#default_value' => isset($this->package->shipping_type) ? $this->package->shipping_type : 'small_package');
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save'));
return $form;
}
示例3: caseTransform
/**
* Transform a string by a certain method.
*
* @param $string
* The input you want to transform.
* @param $option
* How do you want to transform it, possible values:
* - upper: Uppercase the string.
* - lower: lowercase the string.
* - ucfirst: Make the first char uppercase.
* - ucwords: Make each word in the string uppercase.
*
* @return string
* The transformed string.
*/
protected function caseTransform($string, $option)
{
switch ($option) {
default:
return $string;
case 'upper':
return Unicode::strtoupper($string);
case 'lower':
return Unicode::strtolower($string);
case 'ucfirst':
return Unicode::ucfirst($string);
case 'ucwords':
return Unicode::ucwords($string);
}
}
示例4: testUcwords
/**
* Tests multibyte ucwords.
*
* @dataProvider providerUcwords
* @covers ::ucwords
*/
public function testUcwords($text, $expected, $multibyte = FALSE)
{
$status = $multibyte ? Unicode::STATUS_MULTIBYTE : Unicode::STATUS_SINGLEBYTE;
Unicode::setStatus($status);
$this->assertEquals($expected, Unicode::ucwords($text));
}