本文整理汇总了PHP中Drupal\Component\Utility\Unicode::strtoupper方法的典型用法代码示例。如果您正苦于以下问题:PHP Unicode::strtoupper方法的具体用法?PHP Unicode::strtoupper怎么用?PHP Unicode::strtoupper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Component\Utility\Unicode
的用法示例。
在下文中一共展示了Unicode::strtoupper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBlockExampleBasic
/**
* Tests block_example functionality.
*/
public function testBlockExampleBasic()
{
// Login the admin user.
$this->drupalLogin($this->webUser);
$theme_name = \Drupal::config('system.theme')->get('default');
// Verify the blocks are listed to be added.
$this->drupalGet('admin/structure/block/list/' . $theme_name);
$this->assertRaw(t('Title of first block (example_configurable_text)'), 'Block configurable-string found.');
$this->assertRaw(t('Example: empty block'), 'Block empty-block found.');
$this->assertRaw(t('Example: uppercase this please'), 'Block uppercase found.');
// Define and place blocks.
$settings_configurable = array('label' => t('Title of first block (example_configurable_text)'), 'id' => 'block_example_example_configurable_text', 'theme' => $theme_name);
$this->drupalPlaceBlock('example_configurable_text', $settings_configurable);
$settings_uppercase = array('label' => t('Configurable block to be uppercased'), 'id' => 'block_example_example_uppercased', 'theme' => $theme_name);
$this->drupalPlaceBlock('example_uppercase', $settings_uppercase);
$settings_empty = array('label' => t('Example: empty block'), 'id' => 'block_example_example_empty', 'theme' => $theme_name);
$this->drupalPlaceBlock('example_empty', $settings_empty);
// Verify that blocks are there. Empty block will not be shown, because it
// is empty.
$this->drupalGet('/');
$this->assertRaw($settings_configurable['label'], 'Block configurable test not found.');
$this->assertNoRaw($settings_uppercase['label'], 'Block uppercase with normal label not found.');
$this->assertRaw(Unicode::strtoupper($settings_uppercase['label']), 'Block uppercase with uppercased label found.');
$this->assertNoRaw($settings_empty['label'], 'Block empty not found.');
// Change content of configurable text block.
$edit = array('settings[block_example_string_text]' => $this->randomMachineName());
$this->drupalPostForm('admin/structure/block/manage/' . $settings_configurable['id'], $edit, t('Save block'));
// Verify that new content is shown.
$this->drupalGet('/');
$this->assertRaw($edit['settings[block_example_string_text]'], 'Content of configurable text block successfully verified.');
}
示例2: valueCallback
/**
* {@inheritdoc}
*/
public static function valueCallback(&$element, $input, FormStateInterface $form_state)
{
if ($input !== FALSE && $input !== NULL) {
// Make sure element properties are set.
$element['#allow_null'] = isset($element['#allow_null']) ? $element['#allow_null'] : FALSE;
$element['#allow_opacity'] = isset($element['#allow_opacity']) ? $element['#allow_opacity'] : FALSE;
// Normalize returned element values to a RGBA hex value.
$val = '';
if ($element['#allow_null'] && !empty($input['container']['transparent'])) {
return '';
} elseif ($element['#allow_null'] || $element['#allow_opacity']) {
$val = Unicode::strtoupper($input['container']['hex']);
} else {
$val = Unicode::strtoupper($input['hex']);
}
if ($val[0] != '#') {
$val = '#' . $val;
}
if ($element['#allow_opacity']) {
$val .= ColorUtility::opacityToAlpha($input['container']['opacity']);
}
return $val;
}
return '';
}
示例3: opacityToAlpha
/**
* Convert percent opacity to hex alpha.
*
* @param int $value
* Opacity as percentage (0 = transparent, 100 = fully opaque).
*
* @return string|null
* Opacity as HEX (#00 = transparent, #FF = fully opaque).
*/
public static function opacityToAlpha($value)
{
if (!$value || $value < 0 || $value > 100) {
return NULL;
}
return Unicode::strtoupper(str_pad(dechex(ceil($value / 100 * 255)), 2, '0', STR_PAD_LEFT));
}
示例4: compile
/**
* {@inheritdoc}
*/
public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$options = $this->getNode('options');
list($singular, $tokens) = $this->compileString($this->getNode('body'));
$plural = NULL;
if (NULL !== $this->getNode('plural')) {
list($plural, $pluralTokens) = $this->compileString($this->getNode('plural'));
$tokens = array_merge($tokens, $pluralTokens);
}
// Start writing with the function to be called.
$compiler->write('echo ' . (empty($plural) ? 't' : '\\Drupal::translation()->formatPlural') . '(');
// Move the count to the beginning of the parameters list.
if (!empty($plural)) {
$compiler->raw('abs(')->subcompile($this->getNode('count'))->raw('), ');
}
// Write the singular text parameter.
$compiler->subcompile($singular);
// Write the plural text parameter, if necessary.
if (!empty($plural)) {
$compiler->raw(', ')->subcompile($plural);
}
// Write any tokens found as an associative array parameter, otherwise just
// leave as an empty array.
$compiler->raw(', array(');
foreach ($tokens as $token) {
$compiler->string($token->getAttribute('placeholder'))->raw(' => ')->subcompile($token)->raw(', ');
}
$compiler->raw(')');
// Write any options passed.
if (!empty($options)) {
$compiler->raw(', ')->subcompile($options);
}
// Write function closure.
$compiler->raw(')');
// Append translation debug markup, if necessary.
if ($compiler->getEnvironment()->isDebug()) {
$compiler->raw(" . '\n<!-- TRANSLATION: ");
$compiler->subcompile($singular);
if (!empty($plural)) {
$compiler->raw(', PLURAL: ')->subcompile($plural);
}
if (!empty($options)) {
foreach ($options->getKeyValuePairs() as $pair) {
$compiler->raw(', ' . Unicode::strtoupper($pair['key']->getAttribute('value')) . ': ')->subcompile($pair['value']);
}
}
$compiler->raw(" -->\n'");
}
// End writing.
$compiler->raw(";\n");
}
示例5: query
/**
* {@inheritdoc}
*/
public function query($group_by = FALSE)
{
$this->fillValue();
$condition_operator = empty($this->options['not']) ? '=' : '<>';
if (count($this->value) > 1) {
$conditions = $this->query->createConditionGroup(Unicode::strtoupper($this->operator));
// $conditions will be NULL if there were errors in the query.
if ($conditions) {
foreach ($this->value as $value) {
$conditions->addCondition($this->realField, $value, $condition_operator);
}
$this->query->addConditionGroup($conditions);
}
} else {
$this->query->addCondition($this->realField, reset($this->value), $condition_operator);
}
}
示例6: testGlossaryView
/**
* Tests the default glossary view.
*/
public function testGlossaryView()
{
// Create a content type and add some nodes, with a non-random title.
$type = $this->drupalCreateContentType();
$nodes_per_char = array('d' => 1, 'r' => 4, 'u' => 10, 'p' => 2, 'a' => 3, 'l' => 6);
$nodes_by_char = [];
foreach ($nodes_per_char as $char => $count) {
$setting = array('type' => $type->id());
for ($i = 0; $i < $count; $i++) {
$node = $setting;
$node['title'] = $char . $this->randomString(3);
$node = $this->drupalCreateNode($node);
$nodes_by_char[$char][] = $node;
}
}
// Execute glossary view
$view = Views::getView('glossary');
$view->setDisplay('attachment_1');
$view->executeDisplay('attachment_1');
// Check that the amount of nodes per char.
foreach ($view->result as $item) {
$this->assertEqual($nodes_per_char[$item->title_truncated], $item->num_records);
}
// Enable the glossary to be displayed.
$view->storage->enable()->save();
$this->container->get('router.builder')->rebuildIfNeeded();
$url = Url::fromRoute('view.glossary.page_1');
// Verify cache tags.
$this->assertPageCacheContextsAndTags($url, ['timezone', 'languages:' . LanguageInterface::TYPE_CONTENT, 'languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'url', 'user.node_grants:view', 'user.permissions', 'route'], ['config:views.view.glossary', 'node:' . $nodes_by_char['a'][0]->id(), 'node:' . $nodes_by_char['a'][1]->id(), 'node:' . $nodes_by_char['a'][2]->id(), 'node:1', 'node:16', 'node:2', 'node:21', 'node:6', 'node_list', 'user:0', 'user_list', 'rendered', 'config:user.role.anonymous']);
// Check the actual page response.
$this->drupalGet($url);
$this->assertResponse(200);
foreach ($nodes_per_char as $char => $count) {
$href = Url::fromRoute('view.glossary.page_1', ['arg_0' => $char])->toString();
$label = Unicode::strtoupper($char);
// Get the summary link for a certain character. Filter by label and href
// to ensure that both of them are correct.
$result = $this->xpath('//a[contains(@href, :href) and normalize-space(text())=:label]/..', array(':href' => $href, ':label' => $label));
$this->assertTrue(count($result));
// The rendered output looks like "| (count)" so let's figure out the int.
$result_count = trim(str_replace(array('|', '(', ')'), '', (string) $result[0]));
$this->assertEqual($result_count, $count, 'The expected number got rendered.');
}
}
示例7: testGlossaryView
/**
* Tests the default glossary view.
*/
public function testGlossaryView()
{
// create a contentype and add some nodes, with a non random title.
$type = $this->drupalCreateContentType();
$nodes_per_char = array('d' => 1, 'r' => 4, 'u' => 10, 'p' => 2, 'a' => 3, 'l' => 6);
foreach ($nodes_per_char as $char => $count) {
$setting = array('type' => $type->type);
for ($i = 0; $i < $count; $i++) {
$node = $setting;
$node['title'] = $char . $this->randomString(3);
$this->drupalCreateNode($node);
}
}
// Execute glossary view
$view = Views::getView('glossary');
$view->setDisplay('attachment_1');
$view->executeDisplay('attachment_1');
// Check that the amount of nodes per char.
foreach ($view->result as $item) {
$this->assertEqual($nodes_per_char[$item->title_truncated], $item->num_records);
}
// Enable the glossary to be displayed.
$view->storage->enable()->save();
// Check the actual page response.
$this->drupalGet('glossary');
$this->assertResponse(200);
foreach ($nodes_per_char as $char => $count) {
$href = url('glossary/' . $char);
$label = Unicode::strtoupper($char);
// Get the summary link for a certain character. Filter by label and href
// to ensure that both of them are correct.
$result = $this->xpath('//a[contains(@href, :href) and normalize-space(text())=:label]/..', array(':href' => $href, ':label' => $label));
$this->assertTrue(count($result));
// The rendered output looks like "| (count)" so let's figure out the int.
$result_count = trim(str_replace(array('|', '(', ')'), '', (string) $result[0]));
$this->assertEqual($result_count, $count, 'The expected number got rendered.');
}
}
示例8: 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);
}
}
示例9: isUnitTest
/**
* Determines if the provided classname is a unit test.
*
* @param $classname
* The test classname.
*
* @return bool
* TRUE if the class is a unit test. FALSE if not.
*/
public static function isUnitTest($classname)
{
if (strpos($classname, 'Drupal\\Tests\\') === 0) {
$namespace = explode('\\', $classname);
$first_letter = Unicode::substr($namespace[2], 0, 1);
if (Unicode::strtoupper($first_letter) === $first_letter) {
// A core unit test.
return TRUE;
} elseif ($namespace[3] == 'Unit') {
// A module unit test.
return TRUE;
}
}
return FALSE;
}
示例10: testStrtoupper
/**
* Tests multibyte strtoupper.
*
* @dataProvider providerStrtoupper
* @covers ::strtoupper
* @covers ::caseFlip
*/
public function testStrtoupper($text, $expected, $multibyte = FALSE)
{
$status = $multibyte ? Unicode::STATUS_MULTIBYTE : Unicode::STATUS_SINGLEBYTE;
Unicode::setStatus($status);
$this->assertEquals($expected, Unicode::strtoupper($text));
}
示例11: getSummary
/**
* {@inheritdoc}
*/
public function getSummary()
{
$summary = array('#markup' => Unicode::strtoupper($this->configuration['extension']));
$summary += parent::getSummary();
return $summary;
}
示例12: testCaseSensitivity
/**
* Test case sensitive and in-sensitive query conditions.
*/
public function testCaseSensitivity()
{
$bundle = $this->randomMachineName();
$field_storage = FieldStorageConfig::create(array('field_name' => 'field_ci', 'entity_type' => 'entity_test_mulrev', 'type' => 'string', 'cardinality' => 1, 'translatable' => FALSE, 'settings' => array('case_sensitive' => FALSE)));
$field_storage->save();
FieldConfig::create(array('field_storage' => $field_storage, 'bundle' => $bundle))->save();
$field_storage = FieldStorageConfig::create(array('field_name' => 'field_cs', 'entity_type' => 'entity_test_mulrev', 'type' => 'string', 'cardinality' => 1, 'translatable' => FALSE, 'settings' => array('case_sensitive' => TRUE)));
$field_storage->save();
FieldConfig::create(array('field_storage' => $field_storage, 'bundle' => $bundle))->save();
$fixtures = array();
for ($i = 0; $i < 2; $i++) {
// If the last 4 of the string are all numbers, then there is no
// difference between upper and lowercase and the case sensitive CONTAINS
// test will fail. Ensure that can not happen by appending a non-numeric
// character. See https://www.drupal.org/node/2397297.
$string = $this->randomMachineName(7) . 'a';
$fixtures[] = array('original' => $string, 'uppercase' => Unicode::strtoupper($string), 'lowercase' => Unicode::strtolower($string));
}
EntityTestMulRev::create(array('type' => $bundle, 'name' => $this->randomMachineName(), 'langcode' => 'en', 'field_ci' => $fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 'field_cs' => $fixtures[0]['uppercase'] . $fixtures[1]['lowercase']))->save();
// Check the case insensitive field, = operator.
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['lowercase'] . $fixtures[1]['lowercase'])->execute();
$this->assertIdentical(count($result), 1, 'Case insensitive, lowercase');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['uppercase'] . $fixtures[1]['uppercase'])->execute();
$this->assertIdentical(count($result), 1, 'Case insensitive, uppercase');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['uppercase'] . $fixtures[1]['lowercase'])->execute();
$this->assertIdentical(count($result), 1, 'Case insensitive, mixed.');
// Check the case sensitive field, = operator.
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['lowercase'] . $fixtures[1]['lowercase'])->execute();
$this->assertIdentical(count($result), 0, 'Case sensitive, lowercase.');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['uppercase'] . $fixtures[1]['uppercase'])->execute();
$this->assertIdentical(count($result), 0, 'Case sensitive, uppercase.');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['uppercase'] . $fixtures[1]['lowercase'])->execute();
$this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
// Check the case insensitive field, IN operator.
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', array($fixtures[0]['lowercase'] . $fixtures[1]['lowercase']), 'IN')->execute();
$this->assertIdentical(count($result), 1, 'Case insensitive, lowercase');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', array($fixtures[0]['uppercase'] . $fixtures[1]['uppercase']), 'IN')->execute();
$this->assertIdentical(count($result), 1, 'Case insensitive, uppercase');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', array($fixtures[0]['uppercase'] . $fixtures[1]['lowercase']), 'IN')->execute();
$this->assertIdentical(count($result), 1, 'Case insensitive, mixed');
// Check the case sensitive field, IN operator.
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', array($fixtures[0]['lowercase'] . $fixtures[1]['lowercase']), 'IN')->execute();
$this->assertIdentical(count($result), 0, 'Case sensitive, lowercase');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', array($fixtures[0]['uppercase'] . $fixtures[1]['uppercase']), 'IN')->execute();
$this->assertIdentical(count($result), 0, 'Case sensitive, uppercase');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', array($fixtures[0]['uppercase'] . $fixtures[1]['lowercase']), 'IN')->execute();
$this->assertIdentical(count($result), 1, 'Case sensitive, mixed');
// Check the case insensitive field, STARTS_WITH operator.
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['lowercase'], 'STARTS_WITH')->execute();
$this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['uppercase'], 'STARTS_WITH')->execute();
$this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
// Check the case sensitive field, STARTS_WITH operator.
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['lowercase'], 'STARTS_WITH')->execute();
$this->assertIdentical(count($result), 0, 'Case sensitive, lowercase.');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['uppercase'], 'STARTS_WITH')->execute();
$this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
// Check the case insensitive field, ENDS_WITH operator.
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[1]['lowercase'], 'ENDS_WITH')->execute();
$this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[1]['uppercase'], 'ENDS_WITH')->execute();
$this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
// Check the case sensitive field, ENDS_WITH operator.
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[1]['lowercase'], 'ENDS_WITH')->execute();
$this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[1]['uppercase'], 'ENDS_WITH')->execute();
$this->assertIdentical(count($result), 0, 'Case sensitive, exact match.');
// Check the case insensitive field, CONTAINS operator, use the inner 8
// characters of the uppercase and lowercase strings.
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', Unicode::substr($fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 4, 8), 'CONTAINS')->execute();
$this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', Unicode::strtolower(Unicode::substr($fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 4, 8)), 'CONTAINS')->execute();
$this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
// Check the case sensitive field, CONTAINS operator.
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', Unicode::substr($fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 4, 8), 'CONTAINS')->execute();
$this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
$result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', Unicode::strtolower(Unicode::substr($fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 4, 8)), 'CONTAINS')->execute();
$this->assertIdentical(count($result), 0, 'Case sensitive, exact match.');
}
示例13: applyModifiers
protected function applyModifiers($string, $modifiers)
{
if (!is_null($string) || strlen($string)) {
if ($modifiers) {
$original_string = $string;
$prefix = '';
$suffix = '';
if (preg_match('/^(<span[^>]*>)(.*)(<\\/span>)$/i', $string, $matches)) {
$prefix = $matches[1];
$string = $matches[2];
$suffix = $matches[3];
}
for ($j = 0; $j < strlen($modifiers); $j++) {
switch ($modifiers[$j]) {
case 'L':
$string = Unicode::strtolower($string);
break;
case 'U':
$string = Unicode::strtoupper($string);
break;
case 'F':
$string = Unicode::ucfirst($string);
break;
case 'G':
if (!empty($string)) {
$parts = explode(' ', $string);
$string = array();
foreach ($parts as $part) {
$string[] = Unicode::ucfirst($part);
}
$string = implode(' ', $string);
}
break;
case 'T':
$string = trim($string);
break;
case 'S':
$string = SafeMarkup::checkPlain($string);
break;
}
}
$string = $prefix . $string . $suffix;
}
}
return $string;
}
示例14: dec2hex
/**
* Convert a dec to a hex.
*
* @param int $dec
* an integer number
*
* @return string
* the number represented as hex
*/
protected function dec2hex($dec)
{
$hex = dechex($dec);
return str_repeat("0", 2 - Unicode::strlen($hex)) . Unicode::strtoupper($hex);
}
示例15: __toString
/**
* Formats the address for display based on the country's address format.
*
* @return string
* An HTML formatted string containing the address.
*/
public function __toString()
{
$variables = array('!company' => $this->company, '!first_name' => $this->first_name, '!last_name' => $this->last_name, '!street1' => $this->street1, '!street2' => $this->street2, '!city' => $this->city, '!postal_code' => $this->postal_code);
$country = $this->country ? \Drupal::service('country_manager')->getCountry($this->country) : NULL;
if ($country) {
$variables += array('!zone_code' => $this->zone ?: $this->t('N/A'), '!zone_name' => isset($country->getZones()[$this->zone]) ? $country->getZones()[$this->zone] : $this->t('Unknown'), '!country_name' => $this->t($country->getName()), '!country_code2' => $country->id(), '!country_code3' => $country->getAlpha3());
if ($this->country != $this->default_country) {
$variables['!country_name_if'] = $variables['!country_name'];
$variables['!country_code2_if'] = $variables['!country_code2'];
$variables['!country_code3_if'] = $variables['!country_code3'];
} else {
$variables['!country_name_if'] = '';
$variables['!country_code2_if'] = '';
$variables['!country_code3_if'] = '';
}
$format = implode("\n", $country->getAddressFormat());
} else {
$format = "!company\n!first_name !last_name\n!street1\n!street2\n!city\n!postal_code";
}
$address = Html::escape(strtr($format, $variables));
$address = trim(trim(preg_replace("/\n+/", "\n", $address), "\n"), ' ');
if (\Drupal::config('uc_store.settings')->get('capitalize_address')) {
$address = Unicode::strtoupper($address);
}
// <br> instead of <br />, because Twig will change it to <br> anyway and it's nice
// to be able to test the Raw output.
return nl2br($address, FALSE);
}